Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > File I/O and Registry > Opening file with the cd drive


Reply
 
Thread Tools Display Modes
  #1  
Old 06-01-2003, 01:01 PM
wytkat28 wytkat28 is offline
Newcomer
 
Join Date: Jun 2003
Posts: 3
Default Opening file with the cd drive


I want to use my program to open a file from the cd drive. I also want to use the program on different computers. I know that the drive letter of my computer is different then the other computers. How do I open the file while accounting for the different drive letters?
Reply With Quote
  #2  
Old 06-01-2003, 02:32 PM
GavinO's Avatar
GavinO GavinO is offline
Coder of Fortune

Retired Leader
* Expert *
 
Join Date: Dec 2002
Location: Troy, NY USA
Posts: 3,120
Default

You can ask the user which drive the CD is in. You could also scan all the drives in the system for the file, though if the file name happened to be in the same location on another disk, this could cause a problem (fixable by having a signature at the beginning of the file that you check for). You can get all the drives through a DriveList control.
__________________
-- The Gavster
Like to IRC? Try irc.randomirc.com
GavServer
Reply With Quote
  #3  
Old 06-01-2003, 06:58 PM
wytkat28 wytkat28 is offline
Newcomer
 
Join Date: Jun 2003
Posts: 3
Default

Why can't I say...

instead of, "D:\text.txt", (that's my cd drive letter) something in the area of, "DRIVE_CDROM:\text.txt" or something along those lines?
Reply With Quote
  #4  
Old 06-01-2003, 07:07 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,685
Default

Here is a function to get all the CD Drives on a machine (if any). If an empty string is not returned, then loop through each character of the string and add to a drop down list (much like Gavin suggested) next set the listindex to the first one.

Code:
Public Function GetCDS() As String Dim i As Long Dim b() As Byte Dim lPos As Long Dim lDrives As Long ReDim b(63) ' max 32 drives (32 bits) lDrives = GetLogicalDrives() ' bitmask containing drives If lDrives Then ' just in case the call fails Do If (lDrives And 1) Then ' is the bit set? If GetDriveType(Chr$(i + 65) & ":\") = DRIVE_CDROM Then b(lPos) = i + 65 ' convert to ascii lPos = lPos + 2 ' unicode so skip two End If End If i = i + 1 ' increment counter lDrives = lDrives \ 2 ' shift right Loop While lDrives ReDim Preserve b(lPos - 1) ' don't want trailing nulls GetCDS = b ' vb copies to a unicode string End If End Function
Reply With Quote
  #5  
Old 06-01-2003, 07:38 PM
GavinO's Avatar
GavinO GavinO is offline
Coder of Fortune

Retired Leader
* Expert *
 
Join Date: Dec 2002
Location: Troy, NY USA
Posts: 3,120
Default

The reason that there is no system variable by default is that systems may have any number of drives of any type (well, two floppies is the limit there, but anyway) so just CD_DRIVE would not be tremendously useful. You do get the collection of drives presented as shown in the example, tho.
__________________
-- The Gavster
Like to IRC? Try irc.randomirc.com
GavServer
Reply With Quote
  #6  
Old 06-01-2003, 09:14 PM
wytkat28 wytkat28 is offline
Newcomer
 
Join Date: Jun 2003
Posts: 3
Default

cool thanks bunches everyone...I find now that I don't know how to take those found directories and search them for my file, then open that file...please help
Reply With Quote
  #7  
Old 06-01-2003, 09:29 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,685
Default

You can call Dir$ in a loop to enunerate all the files in a directory. Or even write a recursive procedure to enum sub dirs/files. Opening a file requires an Open Statement. Search the forum, you'll see it mentioned repeatedly.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Installation Problem - PLs help urgenlty dpdsouza Installation / Documentation 4 12-02-2004 07:09 PM
File Problems: Files Not Closing etc. Templeton Peck General 5 03-29-2003 11:34 PM
Doesn't want to register! MikeyM Installation / Documentation 5 03-02-2003 08:22 PM
File System Object(FSO) Complete Ref. d1rtyw0rm Tech Discussions 24 08-31-2002 02:08 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->