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!

CommonDialog Filter 1

Status
Not open for further replies.

Error7

Programmer
Jul 5, 2002
656
0
16
GB
Using the CommonDialog control, I need to display a number of files determined by the users selection.

The network folder containing the files contains a csv for each day of the year and the filename is made up from the date as "yymmdd.csv"

My aim is to create a filter that (a) only displays dates that fall on a weekend and (b) only display dates in the month(s) selected by the user with an option to display all weekends throught the year (i.e. all months).

I have got this working insofar as I can get the CD control to display weekends for an individual month but if the user selects all weekends throughout the year, then the CD control only displays up to "060325.csv"

I think the problem is with the length of the filter that I'm constructing but can't find anything on the web or at MS relating to this.

Does anybody know if there is a maximum length for the filter string or can anybody suggest a workaround?

Thanks

Alan

[gray]Experience is something you don't get until just after you need it.[/gray]
 
First I build a list of weekend dates and add them to a list box. This results in List1 containing the following (for 2006)

060107
060108
060114
060115
060121
060122
060128
060129
060204
060205
060211
060212
060218
060219
060225
060226
060304
060305
060311
060312
060318
060319
060325 < CommonDialog control only displays to here.
060326
060401
060402
060408
060409
060415
060416
060422
060423
060429
060430
060506
060507
060513
060514
060520
060521
060527
060528
060603
060604
060610
060611
060617
060618
060624
060625
060701
060702
060708
060709
060715
060716
060722
060723
060729
060730
060805
060806
060812
060813
060819
060820
060826
060827
060902
060903
060909
060910
060916
060917
060923
060924
060930
061001
061007
061008
061014
061015
061021
061022
061028
061029
061104
061105
061111
061112
061118
061119
061125
061126
061202
061203
061209
061210
061216
061217
061223
061224
061230
061231

Then I read the contents of List1 into a string to create the description half of the filter.

For i = 0 To List1.ListCount - 1
S1$ = S1$ & List1.List(i) & ".csv;"
Next i

Then I add the pipe followed by the actual filter.

S1$ = S1$ & "|" & S1$
CommonDialog1.Filter = S1$

I hope this makes sense.

Alan

[gray]Experience is something you don't get until just after you need it.[/gray]
 
One thing that may help is making the description part of the filter much smaller:
Code:
S1$ = "Weekend CSV Files|" & S1$

Or, instead of using a Common Dialog control, why not let the user select from the Listbox you've already created?
 
Since posting my code I discovered that you don't need to include a description so the filter string is now "|" & S1$.

However, that hasn't helped at all. The Dialog still only displays up to "060325.csv"

I have considered alternatives to using the CD control, a FileListBox being one of them but I need to give the users the ability to access the csv files over a network.

Just letting them select from the ListBox won't provide a method to navigate to a network folder.

Thanks

Alan

[gray]Experience is something you don't get until just after you need it.[/gray]
 
OK, another possible alternative is a control that lets the user browse to a folder, and once there show your listbox.

I've used Hypetia's code from thread222-498611 to browse for a specific folder.
 
Thanks.

I had already tried strongm's code in thread222-573084 but found it difficult to navigate back up the tree. Hypetia's code seems better in this respect so I'll use that and change my CommonDialog to a FileListBox.

Alan

[gray]Experience is something you don't get until just after you need it.[/gray]
 
>difficult to navigate back up the tree

Depends what you have set the root directory to
 
Hi strongm,

To avoid starting navigation on the local machine every time and navigating over the network then delving through several sub folders, I'm saving the settings of the last folder accessed.

Then I use GetSettings next time the prog is run.

Unfortunately using this method there doesn't seem to be a way back up the tree.

Alan

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Correct. As I said, it depends on what root folder you start with; you can never navigate back up past it using the Shell Controls and Automation methods. It isn't that it is 'difficult', rather that it is a documented impossibility (although I don't specifically mention that in the thread you picked the code up from because I was really trying to illustrate getting special folder names rather than folder browsing).

Oh, and if I'm honest I'm of the opinion that the inability to pick a starting folder that won't be used as a browsing root is a sad lack in the Shell method
 
Thanks strongm. I would still prefer to use the CommonDialog because that provides the folder browser and file browser in one interface. It's just a pity about the filter problem. But I suppose I've only myself to blame for trying to make the file selection as simple as possible for the users.

I'm still thinking of alternative ways to achieve the same result.

Alan

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top