Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS VB6 course ... check if file exists

Status
Not open for further replies.

BowlerBob

Programmer
Jan 16, 2003
21
GB
Hi

Lesson07 in the Microsoft VB6 course ...

I would like to enhance the Loop to skip over image files
that do not exist eg: C:\vb6sbs\less07\misc05.ico

This is some of the code I have done ...


For iImg = 0 To 3
iIcon = i
sIcon = iIcon
If i < 10 Then
sIcon = &quot;0&quot; & i
End If
Err.Clear
img2.Picture = LoadPicture(&quot;C:\vb6sbs\less07\misc&quot; & sIcon & &quot;.ico&quot;)
If Err.Number <> 0 Then
If iImg > 0 Then
iImg = iImg - 1
End If
Err.Clear
Else
img1(iImg).Picture = LoadPicture(&quot;C:\vb6sbs\less07\misc&quot; & sIcon & &quot;.ico&quot;)
End If

i = i + 1
Next


Program fills the 4 images the first time round,
but stops with Error when sIcon has the value &quot;05&quot;
How can I skip over these non-existant image files ?


 
Dim fso As New Scripting.FileSystemObject
If (fso.FileExists(sFile)) Then
...
Else
...
EndIf

-Rob
 

[tt]
If Dir(&quot;Path To File&quot;) = vbNullString Then
'File Does Not Exist
Else
'File Exists
End If
[/tt]

Good Luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top