Creating an HTML File List with VB - Coding the Program (Page 3 of 5 )
Since the program will run by clicking the Run Catalog button, you will need to create a click event for this object. To do this, double click the Run Catalog button. The code window will open, and will create a sub routine called cmdCatalog_click().
The next few sections will describe the code logic.
Error Checking
To try and prevent the program from causing problems in case it crashed, some error checking should be added. With this error checking added, here is the sub routine so far:
Private Sub cmdCatalog_Click
()
On Error GoTo Err_cmdCatalog_Click
Exit_cmdCatalog_Click:
Exit Sub
Err_cmdCatalog_Click:
MsgBox Err.Description
Resume Exit_cmdCatalog_Click
End Sub
Creating the Picture Directory List
To create the directory listing, we would use the shell command to run a DOS command. Because Windows 2000 does not have the dir.com file, you would get file not found errors, so I used a batch file called dir.bat. Here is the sub routine so far
Private Sub cmdCatalog_Click
()
On Error GoTo Err_cmdCatalog_Click
'run directory listing
'put the path in the shell command where you put the dir.bat file
Dim RetVal
RetVal = Shell("d:picturesdir.bat", 1) ' Run dir.bat
Exit_cmdCatalog_Click:
Exit Sub
Err_cmdCatalog_Click:
MsgBox Err.Description
Resume Exit_cmdCatalog_Click
End Sub
You will need to create a batch file, and save it as dir.bat As the remarks note, put this file somewhere, and change the path in the shell command.
dir
*.jpg /b > dir.txt
dir *.gif /b >> dir.txt
Next: Opening the Dir.txt File and Creating the HTML File >>
More Visual Basic Articles
More By Tim Haight