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!

I need to select a group of files 2

Status
Not open for further replies.

dstema

Programmer
May 6, 2001
20
0
0
US
Hi everybody,
I need a way (like getfile()) to select multiple files. The user is supposed to be able to easily pick up one or more files (txt in my case). Files are not necessary in the same director/drive.
Any word is welcome.
Thanks.
 
John

The first block of code is setting up the control, so can be called from whatever event/method you choose. You will need to supply your own values for the properties, in particular .cInitialDirectory, which is where the dialog will start.

WITH THISFORM.cusCommonDialog
.lAllowMultiSelect = .T.
.cFileName = []
.cInitialDirectory = ALLTRIM(USER.s_folder)
.cTitlebarText = [Select source files]
.aFilterList[1,1] = [Source (bmp,doc,gif,jpg)]
.aFilterList[1,2] = [*.bmp;*.doc;*.gif;*.jpg;*.jpeg]
.nFileCount = 0
.ShowDialog()
ENDW


The second block of code is retrieving the path\filenames of the selected files into a table/cursor, and should follow the first block.

It should be :-

WITH THISFORM.cusCommonDialog
[tab]IF .nFileCount > 0
[tab][tab]FOR i = 1 TO ALEN(.aFileNames,1)
[tab][tab][tab]INSERT INTO AUTO_CREATE (filename) VALUES (UPPER(SYS(5));
[tab][tab][tab][tab]+ LOWER(ADDBS(SYS(2003)));
[tab][tab][tab][tab]+ LOWER(.aFileNames[1,i])
[tab][tab]ENDF
[tab]ELSE
[tab][tab]MESSAGEBOX([No file(s) selected])
[tab]ENDI
ENDW

You can then browse the table/cursor and see what you've got.
FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
Error -> Property CUSCOMMONDIALOG IS NOT FOUND !!

I put the

_COMDLG1 control on my form from the Class Browser

then I put the following in the click event of the command button..



CREATE CURSOR AUTO_CREATE (FileName C(20))

WITH THISFORM.cusCommonDialog
.lAllowMultiSelect = .T.
.cFileName = []
.cInitialDirectory = "c:/" && ALLTRIM(USER.s_folder)
.cTitlebarText = [Select source files]
.aFilterList[1,1] = [Source (bmp,doc,gif,jpg)]
.aFilterList[1,2] = [*.bmp;*.doc;*.gif;*.jpg;*.jpeg]
.nFileCount = 0
.ShowDialog()
ENDW




WITH THISFORM.cusCommonDialog
IF .nFileCount > 0
FOR i = 1 TO ALEN(.aFileNames,1)
INSERT INTO AUTO_CREATE (filename) VALUES (UPPER(SYS(5));
+ LOWER(ADDBS(SYS(2003)));
+ LOWER(.aFileNames[1,i])) && <-- I needed ato add another close bracket here)
ENDF
ELSE
MESSAGEBOX([No file(s) selected])
ENDI
ENDW


I get the error message !! What am I doing wrong here !

(FoxEgg reaches for Prozac bottle ...)
 
CUSCOMMONDIALOG is the name of the common dialog control
My default was olecontrol1, just change the name...

Michael Ouellette
mouellette@compuserve.com
 
Plus Chris is using a different control (_COMDLG) not the original one he started on...
Michael Ouellette
mouellette@compuserve.com
 
John

As Michael has said the class is ._COMDLG, rename it to .cusCommonDialog, and your modified code should work.

FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
OK Chris, Thanks again and sorry to take so long to get back.

It works. .. and it is good....

For those of you with normal IQ I'll summarize the steps that I did to get to a working example.

Create a blank form
Add a command button
Then do <alt> Tools -> Component Gallery -> Foundation Classes -> Dialogs -> Common Dialog (right click) -> Add control to form (or you can copy and paste)

On the form Right click on the control which is called _COMDLG Right click properties --> select rename and call it CusCommonDialog

Then copy Chris' code ----

In the INIT method of the Command button

CREATE CURSOR AUTO_CREATE (FileName C(50))

In the Click Method

WITH THISFORM.cusCommonDialog
.lAllowMultiSelect = .T.
.cFileName = []
.cInitialDirectory = &quot;c:\&quot; && Or whatever you wish
.cTitlebarText = [Select source files]
.aFilterList[1,1] = [Source (bmp,doc,gif,jpg)]
.aFilterList[1,2] = [*.bmp;*.doc;*.gif;*.jpg;*.jpeg]
.nFileCount = 0
.ShowDialog()
ENDW

*The second block of code is retrieving the path\filenames
*of the selected files into a table/cursor, and
*should follow the first block.

*It should be :-

WITH THISFORM.cusCommonDialog
IF .nFileCount > 0
FOR i = 1 TO ALEN(.aFileNames,1)

INSERT INTO AUTO_CREATE (FileName) VALUES (UPPER(SYS(5)) ;
+ LOWER(ADDBS(SYS(2003)))+ LOWER(.aFileNames[1,i]))
*
ENDF

ELSE
MESSAGEBOX([No file(s) selected])
ENDI
ENDW

****** I then out on a Command Buttton with Browse on it
with a click event

Browse

Run Form...

It works like a charm,,,

Thanks everyone for your help on this one.

John Fox
 
John

Pleased to hear all is well - on reviewing the code posted, (as ever in a hurry), there is incorrect code of which should you should be aware.

INSERT INTO AUTO_CREATE (FileName) VALUES (UPPER(SYS(5)) ;
[tab]+ LOWER(ADDBS(SYS(2003)));
[tab]+ LOWER(.aFileNames[1,i]))

should be

INSERT INTO AUTO_CREATE (FileName) VALUES ;
[tab](ADDBS(.cusCommonDialog.cFilepath);
[tab]+ LOWER(.aFileNames[1,i]))

.cusCommonDialog.cFilePath
is the path.
FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
Well here is a turn up for the books...

Your original code...

INSERT INTO AUTO_CREATE (FileName) VALUES (UPPER(SYS(5)) ;
+ LOWER(ADDBS(SYS(2003)));
+ LOWER(.aFileNames[1,i]))


WORKS FINE

Your newer code....

INSERT INTO AUTO_CREATE (FileName) VALUES ;
(ADDBS(.cusCommonDialog.cFilepath);
+ LOWER(.aFileNames[1,i]))

** .cusCommonDialog.cFilePath is the path.


Reports an error !!! Unknown Member cusCommonDialog

... Bugger !

and I cant seem to fix it... and why change it if it already works ?

John



 
Take out cusCommonDialog since it is included in
with thisform.cusCommonDialog


Michael Ouellette
mouellette@compuserve.com
 
Thanks Michael... That does fix it

I'm not smart enough to see any improvement of Rick's modified plan over the Rick's initial version....

Rick... I reckon you should submit this as a FAQ....

Waddyereckon?

John



 
John

Apologies for the futher grief. [blush]

'Rick... I reckon you should submit this as a FAQ....'

I wish I was Rick with all his good looks, talent, money and endless knowledge of VFP [wink]

I'll put a FAQ together over the weekend, thanks for the thought.
FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
Whoops ! It was a typo ! er I had a cold ! er

New Thread.. Who is this rick anyway ?

Sorry.... Chris

Mea Culpa

John
 
FoxEgg

New Thread.. Who is this rick anyway ?

I believe that the &quot;Rick&quot; in question is rgbean (Rick Bean).
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
I guess I don't even have to be part of the discussion to be credited / blamed ! :)

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top