|
From: Johan Stäck on 19 Jul 2008 03:19 I have a VB6 program that creates files. The file names are assembled from various components such as -Time_of_day -User input -Fixed elements I would like to know before trying to open/create a file that the file name is legal on the machine (XP/Vista in varying national settings) on which it is running. Is there a a good way to assert this? Tia, Johan Stäck Skellefteå Sweden
From: MikeD on 19 Jul 2008 09:01 "Johan St�ck" <johan(a)stack.se> wrote in message news:6edis1F6jvq2U1(a)mid.individual.net... >I have a VB6 program that creates files. > The file names are assembled from various components such as > -Time_of_day > -User input > -Fixed elements > > I would like to know before trying to open/create a file that the file > name is legal on the machine (XP/Vista in varying national settings) on > which it is running. > Is there a a good way to assert this? Why not simply trap the error? -- Mike Microsoft MVP Visual Basic
From: Rick Raisley on 21 Jul 2008 08:25 I have a FindIllegal function I run when first running my programs. Basically, it tries to use most (okay many) of the possible characters, and any that cannot be used when naming a file, it saves in a string in the INI file. Next time the program runs, it just reads the INI value, and doesn't have to run it again. Any time the user enters a filename, it's checked against this list of characters: Function FindIllegal() As String Dim a$, f$, x%, FF% On Error Resume Next a$ = "" For x% = 32 To 255 If x% <> 34 Then 'do quotation marks separately. FF% = FreeFile f$ = "C:\hmtest" & Chr$(x%) Open f$ For Binary Access Write As FF% Close FF% DoEvents If Err Then 'Debug.Print Err, Error$ a$ = a$ & Chr$(x%) Err = 0 Else Kill f$ DoEvents If Err Then Err = 0 End If End If Next x% FindIllegal = a$ x% = WriteIniString("Main", "IllegalChar", a$) End Function I'll no doubt have to change where the file is written to with Vista, but you get the idea. This is old code, and I'm sure can be improved upon, but you can probably adapt the idea for your program. -- Regards, Rick Raisley heavymetal-A-T-bellsouth-D-O-T-net "Johan St�ck" <johan(a)stack.se> wrote in message news:6edis1F6jvq2U1(a)mid.individual.net... >I have a VB6 program that creates files. > The file names are assembled from various components such as > -Time_of_day > -User input > -Fixed elements > > I would like to know before trying to open/create a file that the file > name is legal on the machine (XP/Vista in varying national settings) on > which it is running. > Is there a a good way to assert this? > > Tia, > > Johan St�ck > Skellefte� > Sweden
From: Norm Cook on 22 Jul 2008 08:33 "Johan St�ck" <johan(a)stack.se> wrote in message news:6edis1F6jvq2U1(a)mid.individual.net... >I have a VB6 program that creates files. > The file names are assembled from various components such as > -Time_of_day > -User input > -Fixed elements > > I would like to know before trying to open/create a file that the file > name is legal on the machine (XP/Vista in varying national settings) on > which it is running. > Is there a a good way to assert this? I agree with Mike, that trapping the error is probably best. This function may also be of help: Private Function LegalFileName(ByVal FPath As String) As Boolean LegalFileName = Not (FPath Like "*[\/:*?""<>|]*") End Function
|
Pages: 1 Prev: Excel 2007 Chart in VB6 Program Next: save a word document to a byte array |