Solved

file not found

Posted on 1998-12-14
1
175 Views
Last Modified: 2010-05-03
I'm trying to make a cd with a bunch of solitaire games. I made a menu program for the cd that shells to the games. As I don't know what my friend's cdrom drive letter is I used
Dim x
x = Shell(App.Path + "\filename.exe", 1)
It works fine in a directory on my HD but when I make the cd
I get a file not found error, all of the files are in the root directory of the CD. I'm using VB4 Pro ans sscommand buttons.I want to keep as much on the cd as possible with little to none being put on a HD.
0
Comment
Question by:ralphy
1 Comment
 
LVL 2

Accepted Solution

by:
dm_14 earned 100 total points
ID: 1449990
1. The average PC has one CD ROM driver, so all you need is the driver letter of the CD Rom drive
2. Just incase there are more than one you can check the CD
ROM volume name match your cd title
3. The code below should give you an idea of how to do this :



Public Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" _
        (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

Public Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _
        (ByVal nDrive As String) As Long
       Public Const DRIVE_CDROM = 5


Add the following code to Form1.

Private Sub Form_Load()

       Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
       
End Sub


Private Sub cmdEnd_Click()

       Unload Me
End

End Sub


Private Sub cmdDriveInfo_Click()

       '      'get the available drives, determine their type,
       '      'and if CD, get the CD volume label
       Dim r As Long
       Dim DriveType As Long
       Dim allDrives As String
       Dim JustOneDrive As String
       Dim CDLabel As String
       Dim pos As Integer
       Dim CDfound As Boolean
       '      'pad the string with spaces
       allDrives$ = Space$(64)
       '      'call the API to get the string containing all drives
       r& = GetLogicalDriveStrings(Len(allDrives$), allDrives$)
       '      'trim off any trailing spaces. AllDrives$
       '      'now contains all the drive letters.
       allDrives$ = Left$(allDrives$, r&)
       '      'begin a loop

              Do
                     '      'first check that there is a chr$(0) in the string
                      pos% = InStr(allDrives$, Chr$(0))
                     '      'if there's one, then...
                      If pos% Then
                     '     'extract the drive up to the chr$(0)
                     JustOneDrive$ = Left$(allDrives$, pos% - 1)
                     
                     '     'and remove that from the Alldrives string,
                     '     'so it won't be checked again
                     allDrives$ = Mid$(allDrives$, pos% + 1, Len(allDrives$))
                     
                     '     'with the one drive, call the API to
                     '     'determine the drive type
                     DriveType& = GetDriveType(JustOneDrive$)
                     '     'check if it's what we want

                            If DriveType& = DRIVE_CDROM Then
                                   
                                   '      'got it (or at least the first one,
                                   '      'anyway, if more than one), so set
                                   '      'the found flag... this part can be modified
                                   '      'to continue searching remaining drives for
                                   '      'those systems that might have more than
                                   '      'one CD installed.
                                   CDfound = True
                                   CDLabel$ = rgbGetVolumeLabel(JustOneDrive$)
                                   
                                   '      'we're done for now, so get out
                                   Exit Do
                            End If

                      End If
                      Loop Until allDrives$ = "" Or DriveType& = DRIVE_CDROM
                     '      'display the appropriate message
                      If CDfound Then
                     Label2 = "The CD ROM drive on your system is drive " & UCase$(JustOneDrive$) & vbCrLf
                     Label2 = Label2 & "The volume label is " & CDLabel$
                      Else: Label2 = "No CD ROM drives were detected on your system."
                      End If
              End Sub


Private Function rgbGetVolumeLabel(CDPath$) As String

       '      'create working variables
       '      'to keep it simple, use dummy variables for info
       '      'we're not interested in right now
        Dim r As Long
        Dim DrvVolumeName As String
        Dim pos As Integer
        Dim UnusedVal1 As Long
        Dim UnusedVal2 As Long
        Dim UnusedVal3 As Long
        Dim UnusedStr As String
       
        DrvVolumeName$ = Space$(14)
        UnusedStr$ = Space$(32)
       '      'do what it says
        r& = GetVolumeInformation(CDPath$, _
       DrvVolumeName$, _
       Len(DrvVolumeName$), _
       UnusedVal1&, UnusedVal2&, _
       UnusedVal3&, _
       UnusedStr$, Len(UnusedStr$))
       '      'error check
        If r& = 0 Then Exit Function
       '      'the volume label
        pos% = InStr(DrvVolumeName$, Chr$(0))
        If pos% Then DrvVolumeName$ = Left$(DrvVolumeName$, pos% - 1)
        If Len(Trim$(DrvVolumeName$)) = 0 Then DrvVolumeName$ = "(no label)"
       
        rgbGetVolumeLabel = DrvVolumeName$
End Function

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBS file using code from 2nd file (txt or vbs) 4 32
MS Access Search and Replace Using VBA 6 58
VBA: Select SQL query based on a config Sheet v2 11 38
Help me. 3 48
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now