|
-
Jan 10th, 2001, 05:48 AM
#1
Thread Starter
Hyperactive Member
Hi.
Put this code in a form1's form load event, and add a label1.
When you start the program it looks for a CD called stuff.exe in the root of the CD-ROM drive. If the CD is in there, the program loads as normal, by loading form2.
If there is no CD with stuff.exe, a message box comes up: 'Please insert the appropriate CD-ROM in the drive.'.
Then when 'OK' is clicked, the message box disappears. However, the program is still in memory when 'Ok' is clicked. (I just set the visible property of Form1 to false). I thought the 'Exit Sub' whould take care of this, but it doesn't.
Could someone please look at my code and tell me how to unload Form1 when the user clicks 'OK' on the message box?
Thanks for your help.
---------------
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Const DRIVE_REMOVABLE = 2
Private Const DRIVE_FIXED = 3
Private Const DRIVE_REMOTE = 4
Private Const DRIVE_CDROM = 5
Private Const DRIVE_RAMDISK = 6
'Set the form's visible property to false
Private Sub Form_Load()
Dim TheFile As String
Dim Results As String
'the program detects the CD drive. When it finds it, it looks
'for a file on the CD, in this case "stuff
'.exe". When it finds it, the program loads as normal. If it's
'not there, a message box pops up, asking them to install the CD
Dim r&, allDrives$, JustOneDrive$, pos%, DriveType&
Dim CDfound As Integer
allDrives$ = Space$(64)
r& = GetLogicalDriveStrings(Len(allDrives$), allDrives$)
allDrives$ = Left$(allDrives$, r&)
Do
pos% = InStr(allDrives$, Chr$(0))
If pos% Then
JustOneDrive$ = Left$(allDrives$, pos%)
allDrives$ = Mid$(allDrives$, pos% + 1, Len(allDrives$))
DriveType& = GetDriveType(JustOneDrive$)
If DriveType& = DRIVE_CDROM Then
CDfound% = True
Exit Do
End If
End If
Loop Until allDrives$ = "" Or DriveType& = DRIVE_CDROM
Label1 = UCase$(JustOneDrive$)
TheFile = Label1.Caption & "stuff.exe"
On Error GoTo errorhandler
Results = Dir$(TheFile)
If Results = "" Then
Message = "Please insert the appropriate CD-ROM."
buttonsandicons = vbOKOnly + vbExclamation
Title = "Stuff"
MsgBox Message, buttonsandicons, Title
Exit Sub
Else
Form1.Show
End If
Exit Sub
errorhandler:
Message = "Please insert the Maths-Master CD-ROM."
buttonsandicons = vbOKOnly + vbExclamation
Title = "Stuff"
MsgBox Message, buttonsandicons, Title
Exit Sub
End Sub
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
|