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!

Drive/Dir Boxes....

Status
Not open for further replies.

dodgyone

Technical User
Jan 26, 2001
431
0
0
GB
I have simple Drive, Directory & File components added to my form but if I choose a drive with no disk I get a runtime error.

I've tried doing an 'on error goto' but this error comes up no matter which drive I select... available or not.

Does anyone have any ideas to guard against this?

Thanks...
 
You could use the common dialog box for opening and saving files. Its a lot easier! Takes two ticks.

If you decide to do it this way tell me and I'll give you details.

elziko
 
Thanks for getting back to me elziko...

How do you make a the common dialog box/is it a component?

Could you also give me an example of how to stop error codes where searching through Drive1 as mentioned... Now I've nearly done it I might as well now how to do it properly ;o)
 
Trust me the common control is better.

Goto Project|Componets

Go down the list until you find Microsoft Common Dialog Control 5.0 and make sure this is checked.

You'll then have a new control on your control bar.

Drop one of these onto your form (commondialog1) along with a command button (command1)

Then in the click event of the button and this code:

Private Sub Command1_Click()
CommonDialog1.ShowOpen
Debug.Print CommonDialog1.FileName
End Sub


That will print to the debug window the file that the user chooses to open. Or if you want to save a file:

Private Sub Command1_Click()
CommonDialog1.ShowSave
Debug.Print CommonDialog1.FileName
End Sub


The control also has lots of properties including a filter to give the user an option of only certain files. So if at design time you entered something like "Data Files (*.dat)|*.dat" for the filter the user would only be able to choose data files.

Enjoy,

elziko
 
Thanks... I've got up to there and ensured that only .zip files are shown. How can I take the file location and file name from the dialog box into the code to use as a variable etc?

Also, I noticed that there are many more options in the common dialog window (i.e. open as read-only). Is it possible to turn these off?

Many thanks for your help...
 
I've solved the transfer file location problem but I'm still unsure about how to remove read-only etc....

Any ideas?

Thanks....
 
I dont think its possible. The whole point is to give a standard dialog so that the user can expect the same functionality every time. But someone may well prove me wrong.

elziko
 
OK - so what if I do not have - and can't find - the Common Dialog Controls Library?
 
What version of VB are you using? I think VB6 definitly comes with this control.

Goto Project|Componets and make sure that "Selected items only" is not checked. Then you should be able to scroll down to "Microsoft Common Dialog Control" if you dont see it then search for a file on your drive called comdlg32.ocx and make sure its registered (drag it onto regsvr32). It should then appear in your componets window.

Otherwise maybe your version of VB doesn't come with this in which case you can either get a version that does or create your own as dodgyone was trying. Hopefully you wont run into the same problem as he did. If a drive is ready then you really should get the error.

I think the reason his error handler may have been firing regardless of which drive he selected was because he didn't add a line of code to exit his sub or function before the label that marked the start of his function.

Enjoy

elziko
 
Sorry the last line should read "..that marked the start of his error handling code"

ooops
 
I neglected to reply that your solution worked just fine. DUH... I just didn't see the control in the dropdown box.

Thanks!
 
dodgyone,

if you are still interested...

Private Sub Command1_Click()
' to hide open as read only check box
CommonDialog1.Flags = cdlOFNHideReadOnly
CommonDialog1.ShowOpen
Debug.Print CommonDialog1.FileName
End Sub


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top