Using VB to Build Your Web Site
OK. Lets put down some code. Open up VB and make a new Standard EXE Project. Add three text boxes (txtHeader, txtTitle and txtReturn), a command button (cmdMake) and a combo box (cboDir). Make sure that txtHeader's and txtReturn's MultiLine property is set to True and that you paste in the header text talked about above into txtHeader with another line at the top (<!--Start Header-->). Also put a space and then press Ctrl+Enter in the text property of txtReturn as Chr(13) does not act as a very good carriage return character. Add a common dialog control to the form (comDlg). Copy and paste this code into the cmdMake_Click procedure:
Private Sub cmdMake_Click() Dim strBuffer As String Dim strPath As String Dim intFile As String '// Build the HTML file strBuffer = txtHeader & txtReturn strBuffer = strBuffer & "<title>" _ & txtTitle & "</title>" & txtReturn strBuffer = strBuffer & "</head>" & _ txtReturn strBuffer = strBuffer & _ "<!--End Header-->" _ & txtReturn strBuffer = strBuffer & "<!--Start Content-->" _ & txtReturn strBuffer = strBuffer & bgImage(cboDir.Text) strBuffer = strBuffer & "<!--End Content-->" _ & txtReturn strBuffer = strBuffer & "<!--Start Footer-->" _ & txtReturn strBuffer = strBuffer & "</body>" & txtReturn strBuffer = strBuffer & "</html>" & txtReturn strBuffer = strBuffer & "<!--End Footer-->" '// Set up the common dialog intFile = FreeFile comDlg.Action = 2 strPath = comDlg.filename If strPath = "" Then Exit Sub '// Open/Create the HTML file and write to it Open strPath For Append As #intFile Write #intFile, strBuffer Close #intFile End Sub
We now need to build the bgImage function found in the above code. This function takes one parameter, strDir, which is the directory (root sub etc) from which to create to file to. It looks like this:
Private Function bgImage(strDir As String) As String Select Case strDir Case "Root Dir" bgImage = "<body background=" & Chr(34) & _ "image/back.gif" & Chr(34) & ">" Case "Sub Dir" bgImage = "<body background=" & Chr(34) & _ "../images/back.gif" & Chr(34) & ">" Case Else bgImage = "" End Select End Function
That's basically all the code you need. Just add this little bit to the form's Load procedure:
Private Sub Form_Load() With cboDir .AddItem "Root Dir" .AddItem "Sub Dir" End With End Sub
That's it! You have now created your own version of PageGen. See the source code download below if you get stuck.
NOTE: Please don't remove the <!--Text--> tags from the program, they will be needed in a future part of this series.
Page 4 of 5