|
-
May 1st, 2007, 09:10 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] file exists
i'm trying to see if a user inserted the correct cd. i'm doing this by checking if a file exists on the cd drive. my question is, can i use wildcard characters to see if a file exists? example:
Code:
If fso.FileExists("D:\*.cde") = True Then MsgBox "yes"
this doesn't seem to work. if i enter the complete file name, it works.
-
May 1st, 2007, 09:18 AM
#2
Re: file exists
If Dir("D:\*.cde") > vbNull Then MsgBox "yes"
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
May 1st, 2007, 09:21 AM
#3
Thread Starter
Fanatic Member
-
May 1st, 2007, 09:21 AM
#4
Re: file exists
vbNullString would work a little better.
-
May 1st, 2007, 09:22 AM
#5
Thread Starter
Fanatic Member
-
May 1st, 2007, 09:31 AM
#6
Re: file exists
You are welcome.
If you consider this resolved, you could help us out by pulling down the Thread Tools menu and click the Mark Thread Resolved menu item. That will let everyone know that you have your answer.
Thank you.
-
May 1st, 2007, 09:33 AM
#7
Thread Starter
Fanatic Member
Re: file exists
if there is no cd in the drive at all i get an error message. how can i check if there is a cd in the drive?
-
May 1st, 2007, 09:35 AM
#8
Re: file exists
Why not just trap for the error?
What is the error number you get?
-
May 1st, 2007, 09:39 AM
#9
Thread Starter
Fanatic Member
Re: file exists
Run-time error '52'
Bad file name or number
-
May 1st, 2007, 09:40 AM
#10
Re: file exists
vb Code:
On Error GoTo ErrTrap
'your file exists code
Exit Sub
ErrTrap:
If Err.Number = 52 Then
Msgbox "Please insert a CD into the CD Drive.",vbOKOnly + vbInformation,"No CD"
Else
Msgbox Err.Number & " " & Err.Description
End If
End Sub
-
May 1st, 2007, 09:46 AM
#11
Thread Starter
Fanatic Member
Re: file exists
works great. one last question. is there a way to automatically eject the cd?
-
May 1st, 2007, 09:47 AM
#12
Re: file exists
Try
vb Code:
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Sub cmdOpenCD_Click()
Dim OpenCDDrive As Long
OpenCDDrive = mciSendString("set CDAudio door open", "", 127, 0)
End Sub
-
May 1st, 2007, 09:52 AM
#13
Thread Starter
Fanatic Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|