Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic (http://www.programmingforums.org/forum18.html)
-   -   "open" dialog boxes (http://www.programmingforums.org/showthread.php?t=2339)

chepfaust Feb 18th, 2005 1:56 PM

"open" dialog boxes
 
hello,

in a program i'm trying to write, i've got a certain part where the user clicks on a button that says "load list" and the program reads from an external text file in a hardcoded location and fills in a listbox based on the contents of that text file.

i've got the reading/writing the external text file part down, but i would like to be able to allow the user to specify what text file they would like to open in the first place by clicking on "load list" as if it were a "browse for file" button.

i know this is a very, very noob question concerning visual basic but most of my programming background comes from qbasic many years ago, and i never had to deal with forms, APIs or all that much graphical interaction back then ;)

i did find one site that provided code that explained how to do it, but it didn't work for me (i'm using VB6, i think it was geared towards .NET) and it was too complex for me to understand how to fix it. so if someone can summarize the basics of what i need to summon an "open" dialog box, i'd appreciate it.

thanks

edit: while i'm at it,

once the user has found the file they want to load and loaded it, i've got another button labeled "edit list" for which i want to open the actual text file they specify in notepad. for the life of me i can't figure out how to actually open an external file. i've tried the shell and appactivate commands but neither seemed to work.

Pizentios Feb 18th, 2005 2:14 PM

check this out:

http://msdn.microsoft.com/library/de...ialogboxes.asp

should help.

chepfaust Feb 18th, 2005 2:20 PM

score!

thanks much :)

Pizentios Feb 18th, 2005 2:42 PM

no prolem man. msdn is a great resource for vb programming.

Cipher Feb 18th, 2005 3:04 PM

use a cmdb

chepfaust Feb 18th, 2005 10:23 PM

ok cool so i got the hang of dialog boxes; it was as easy and simple as i thought it'd be.

however i still haven't figured out how to open an external file (need to open a specified notepad file at the push of a button), so if anybody has any pointers on that i'd appreciate it.

thanks

chepfaust Mar 8th, 2005 7:48 PM

new question concerning open dialog boxes-

when the user clicks on "cancel" in an "open" dialog box, is there any way to get a value from the user's action?

for example my current problem is that in the dialog box, if the user clicks on a file but clicks on "cancel," the program will continue on as if the user clicked on the file and clicked "open." how do i stop this?

thanks

edit:

actually i figured it out, i think. i've now manually set the commondialogOpen.filename to "" before initiating commondialogOpen.action = 1. i think the problem was that once i used the commondialog, the default filename carried over from the previous time i used the CDL, so my manual setting the filename to nothing would allow me to use a if cdlOpen.filename = "" statement to cancel out of the subroutine.

Pizentios Mar 9th, 2005 8:45 AM

I think that the Cancel button returns something like a 0 or something like that, i can't remember, since it's been a long time since i've done anything with VB.

Cipher Mar 9th, 2005 10:02 AM

Here is for Opening the file

:

Private sub loadlist_click()
CommonDialog.ShowOpen
Open CommonDialog1.Filename for Output As 1
Read 1


Rory Mar 10th, 2005 2:05 PM

Quote:

Originally Posted by Pizentios
I think that the Cancel button returns something like a 0 or something like that, i can't remember, since it's been a long time since i've done anything with VB.

If you set the CancelError property of the dialog control to true, a specified run time error is raised, which you can catch.
However, I'd recommend using the APIs themselver directly. They are much better, more flexible, and plus no one seems to have Comdlg in their system, meaning that unless you copy the ocx onto every computer, you'll get a fatal error.


All times are GMT -5. The time now is 7:34 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC