Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find the right USB-Interface by a program 5

Status
Not open for further replies.

german12

Programmer
Nov 12, 2001
563
0
16
DE
I have a desktop PC and a laptop PC - and I use an USB-Stick with a dbf-file to which I want to have access to by a program.
When I use this stick on my desktop the default ist h: and on the laptop the default is k:.

As I do want to maintain only one prg to have access to the USB-Stick - how can I find out by the program where the location for the USB-Stick is to be found at that moment?

My program uses the statement "set default to" plus "use".

e.g. set default to k:
use my.dbf

and on the laptop
set default to h:
use my.dbf

Of course I do not want to change the program every time.

The size of the USB = 256 MB - if the size could be of value
when looking for the right interface.

Is there a possibility by few program-lines to find out automatically to which interface (h: or k:)I have to go to?

Regards from Germany

Klaus






Peace worldwide - it starts here...
 
Klaus;

Code:
IF FILE("k:\my.dbf")
    SET DEFAULT TO k:
ELSE
    SET DEFAULT TO h:
ENDIF
USE my.dbf


Ed

Please let me know if the suggestion(s) I provide are helpful to you.
Sometimes you're the windshield... Sometimes you're the bug.
smallbug.gif
 
Hi Klaus,

What OS's are in use. In NT and W2K you should be able to change the L: mapping to K: in the Administrative Tools->Computer Management->Disk Management.

Regards,

Mike
 
is anything off this thread any use?

thread184-1014682


Neil

I like work. It fascinates me. I can sit and look at it for hours...
 
Thanks to all of you.
Every solution was interesting.
The simplest solution is now ok.
As I know which file has to be used, I can live with Ed's solution - it works.
Stupid, but I forgot the If-File statement to use.

That's the good thing with this forum, which I loke very much that even simplest advices can ease your life....




Peace worldwide - it starts here...
 
Maybe the following can be of any interest to you, even if you have a solution for now.
I've got a company with different PC's in the office, production hall (CNC-machine's),stock,etc. They work under different operating systems, 98, XP, XPPRO. All the info is stored on a server with a directory "ADMIN". In the evening or weekends I take the program and database with me on a USB stick, so I can work on my home PC or portable. Trouble was that all the PC's gave me a different drive id for the USB-stick (F:,H:,I:,etc). So I made this section in the mainprogram to find the server at work or my USB stick at home (PC or portable), to find the correct connection.

\\server\E\ADMIN is the server PC at the factory
shutdown.mem is a file to control if the database isn't closed

LOCAL lOk
lOk=.F.
IF FILE("\\server\E\ADMIN\DATA\shutdown.mem")
xServer="\\server\E\"
SET PATH TO (xServer+"ADMIN\DATA")
lOk=.T.
=MESSAGEBOX("SERVER CONNECTION ON "+xServer,0,"DATABASE LOCATIE",3000)
ELSE
* NO SERVER FOUND SO WE CHECK FOR THE USB STICK ON D,E,...
FOR x=67 TO 80
xServer=CHR(x)+":\"
IF FILE(xServer+"ADMIN\DATA\adminserver.dbc")
SET PATH TO (xServer+"ADMIN\DATA")
lOk=.T.
EXIT
ENDIF
NEXT
=MESSAGEBOX("LOCAL CONNECTION ON "+ALLTRIM(xServer),0,"DATABASE LOCATIE",3000)
ENDIF
* Double check !!!
IF FILE(xServer+"ADMIN\DATA\shutdown.mem")
lOk=.T.
ELSE
lOk=.F.
ENDIF
IF !lOk
=MESSAGEBOX("CONTACT PETER",0,"NO SERVER FOUND")
CANCEL
ENDIF
..... THE PROGRAM STARTS

It's simple and it works. Nobody has to remerber the drive. Even if something changes in the hardware, you are always going to find the correct connection. Works on all window OS.

Greetings, Peter.
This is my first posting !?! Like this forum a lot !
 
Hi Peter,
thx for the good idea to use a loop which makes the prog much more variabel.
I tested it on my pc by changing the usb-stick into 5 different usb-interfaces one after another and every time the dbf-file I work with was found correctly of course.

I will use this fine solution from now on and can use the usb-stick as well for my laptop.

A star for you!

Klaus

Peace worldwide - it starts here...
 
Hi Klaus,

you may make your program more reliably, if you add a check with drivetype(), after you or before you search the file. Because else you may work on an old version of the dbf "accidentally" stored on a hard drive.

Well, FatSlug pointed to the right thread :)

Bye, Olaf.
 
Hi Olaf,
Good hint,
although the drivetype function as per help considers USB as well as diskette as drivetye 2 at least one can avoid from access to Harddisks.

A star for you.

Regards
Klaus


Peace worldwide - it starts here...
 
Hi Klaus,

Thanks!

It's true that drivetype isn't very specific. Type 2 is any removable disk, like floppy, usb stick or a hard drive connected to usb. But as floppies are normaly drive "A" and "B" only it's not hard to guess if it is a usb atteched device rather than an internal hard diks or network drive.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top