Click to See Complete Forum and Search --> : Whats wrong with this code? Msgbox
Moses420ca
October 10th, 2001, 12:41 PM
private Sub Drive1_Change()
on error GoTo nodisk
Dir1.Path = Drive1.Drive
Text3.Text = Drive1.Drive
nodisk: MsgBox "There is no disk in that Drive", vbRetryCancel, "a Phrozen error"
If nodisk = vbRetry then
Dir1.Path = Drive1.Drive
Text3.Text = Drive1.Drive
else
Drive1.Drive = "c:\"
Dir1.Path = "c:\"
Text3.Text = "c:\"
End If
End Sub
http://www.geocities.com/moses420ca/images/thumbnails/drewblue2.jpgThankz, Drew
Moses420ca@yahoo.ca?SUBJECT=I Love Your Stuff
Iouri
October 10th, 2001, 01:03 PM
Either you have an error or not you will get the message "There is no disk in that Drive".
Iouri Boutchkine
iouri@hotsheet.com
Moses420ca
October 10th, 2001, 01:05 PM
now VB is returning Errors all over the place in my project. whats wrong?
http://www.geocities.com/moses420ca/images/thumbnails/drewblue2.jpgThankz, Drew
Moses420ca@yahoo.ca?SUBJECT=I Love Your Stuff
d.paulson
October 10th, 2001, 01:17 PM
Put in Exit Sub after this line
Text3.Text = Drive1.Drive
David Paulson
John G Duffy
October 10th, 2001, 04:35 PM
Here is your routine revised somewhat.
You need to do an Option Explicit to ensure all variables are defined. YOu need to Exit the Sub if everything goes well or you will fall into the error routine and execute it. The MsgBox needs to be a function so it can return the users response so I altered it as you can see
option Explicit ' add this line
Dim strTemp as string
private Sub Drive1_Change()
Dim noDisk as Integer ' add this line
on error GoTo noDisk
Dir1.Path = Drive1.Drive
Text3.Text = Drive1.Drive
Exit Sub ' Add this line
noDisk:
' next line revised
noDisk = MsgBox("There is no disk in that Drive", vbRetryCancel, "a Phrozen error")
If noDisk = vbRetry then
Dir1.Path = Drive1.Drive
Text3.Text = Drive1.Drive
else
Drive1.Drive = "c:\"
Dir1.Path = "c:\"
Text3.Text = "c:\"
End If
End Sub
John G
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.