f



Mayor unknoun progblem w/ filename returned by commondialong control or API

Hello group,

I am having this very weird problem w/ commondialog control or the 
GetOpenFileName API.
I'll post my relevant code and then explain the problem.

private sub cmdShowSelectNParse_click()

dim fso as new fileSystemObject
dim strShowOpenFileReturned as string
dim strToFIle as string
dim strAppToRun as string

strToFile = app.path & "\BBLog.bdl"
strAppToRun = app.path & "\Parser.exe"

	'Filters and returns strings w/ file name
	with CommonDialog
		.Filter = "Debug FIles (*.bdl)|*.bdl"
		.ShowOpen
		strShowOpenFileReturned = .FileName
	end with
'Just for troubleshooting
debug.print strShowOpenFileReturned

'Copies file returned from commondialog to file spected by Parser.exe
fso.CopyFile strShowOpenFileReturned, strToFile, True

'Executes Application Parser.exe
shell strAppToRun, vbNormalFocus

end sub

So the code:
1) Lets user selects any *.bdl file.
2) Copies the file to filename and directory the Parser application expects
3) runs the Parser application.


Now if I replace the commondialg for a hard coded string
i.e
strShowOpenFileReturned  = "c:\Documents and 
Settings\UsrName\Desktop\TestAny.bdl"

then everything works fine.
By the way this path and file name is the same one returned by the 
commondial.filename (Copied from debug window).

Also, the app.path is c:\Program files\ThisTool

The Parser.exe opens a proprietary database and parses it to a pipe 
delimited text file.

I have tried replacing common dialog for API but the same happens.
I've also tried using shellexecute API to start app.

The application gives error can not find file although file is there.
if I manually execute file it works fine. Just can not do via VB while 
using commondialog control or GetOpenFileName API.

Any Though?

Thanks in advance,
Muxer

0
9/13/2003 10:07:21 PM
comp.lang.basic.visual.misc 10153 articles. 0 followers. Post Follow

6 Replies
9099 Views

Similar Articles

[PageSpeed] 14

    It's hard to tell from your code. It seems to be
a partial pasting of code for the ComDlg control.
One idea: If you're using the API, have you cleared
the nulls in the return string?
  Assuming that you sent in something like a string
of 255 nulls, you'll need to snip off the extras when you
get it back:
   Pt0 = Instr(strShowOpenFileReturned, chr(0))
   strShowOpenFileReturned = left$(strShowOpenFileReturned, (Pt0 - 1))

   If you insert MsgBox "-" & strShowOpenFileReturned & "-"
and you see a message box that says:

-c:\Documents and
Settings\UsrName\Desktop\TestAny.bdl

(no dash at the end) then you'll know there are extra Chr(0)s
in your string.

--
--
Muxer <NoSpammingPlease@Muxer.com> wrote in message
news:tyM8b.236665$2x.67257@rwcrnsc52.ops.asp.att.net...
> Hello group,
>
> I am having this very weird problem w/ commondialog control or the
> GetOpenFileName API.
> I'll post my relevant code and then explain the problem.
>
> private sub cmdShowSelectNParse_click()
>
> dim fso as new fileSystemObject
> dim strShowOpenFileReturned as string
> dim strToFIle as string
> dim strAppToRun as string
>
> strToFile = app.path & "\BBLog.bdl"
> strAppToRun = app.path & "\Parser.exe"
>
> 'Filters and returns strings w/ file name
> with CommonDialog
> .Filter = "Debug FIles (*.bdl)|*.bdl"
> .ShowOpen
> strShowOpenFileReturned = .FileName
> end with
> 'Just for troubleshooting
> debug.print strShowOpenFileReturned
>
> 'Copies file returned from commondialog to file spected by Parser.exe
> fso.CopyFile strShowOpenFileReturned, strToFile, True
>
> 'Executes Application Parser.exe
> shell strAppToRun, vbNormalFocus
>
> end sub
>
> So the code:
> 1) Lets user selects any *.bdl file.
> 2) Copies the file to filename and directory the Parser application
expects
> 3) runs the Parser application.
>
>
> Now if I replace the commondialg for a hard coded string
> i.e
> strShowOpenFileReturned  = "c:\Documents and
> Settings\UsrName\Desktop\TestAny.bdl"
>
> then everything works fine.
> By the way this path and file name is the same one returned by the
> commondial.filename (Copied from debug window).
>
> Also, the app.path is c:\Program files\ThisTool
>
> The Parser.exe opens a proprietary database and parses it to a pipe
> delimited text file.
>
> I have tried replacing common dialog for API but the same happens.
> I've also tried using shellexecute API to start app.
>
> The application gives error can not find file although file is there.
> if I manually execute file it works fine. Just can not do via VB while
> using commondialog control or GetOpenFileName API.
>
> Any Though?
>
> Thanks in advance,
> Muxer
>


0
mayayana4 (7)
9/14/2003 12:18:28 AM
Thanks for your quick response.

I tried using msgbox to print commondialog or the API returned filename 
string. They both return:
-c:\Documents and Settings\UsrName\Desktop\TestAny.bdl-

Now, I tried using OleDragDrop data.file(1) and it works.
However I know commondialog should work.

Any other thoughts?



mayayana wrote:
>     It's hard to tell from your code. It seems to be
> a partial pasting of code for the ComDlg control.
> One idea: If you're using the API, have you cleared
> the nulls in the return string?
>   Assuming that you sent in something like a string
> of 255 nulls, you'll need to snip off the extras when you
> get it back:
>    Pt0 = Instr(strShowOpenFileReturned, chr(0))
>    strShowOpenFileReturned = left$(strShowOpenFileReturned, (Pt0 - 1))
> 
>    If you insert MsgBox "-" & strShowOpenFileReturned & "-"
> and you see a message box that says:
> 
> -c:\Documents and
> Settings\UsrName\Desktop\TestAny.bdl
> 
> (no dash at the end) then you'll know there are extra Chr(0)s
> in your string.
> 
> --
> --
> Muxer <NoSpammingPlease@Muxer.com> wrote in message
> news:tyM8b.236665$2x.67257@rwcrnsc52.ops.asp.att.net...
> 
>>Hello group,
>>
>>I am having this very weird problem w/ commondialog control or the
>>GetOpenFileName API.
>>I'll post my relevant code and then explain the problem.
>>
>>private sub cmdShowSelectNParse_click()
>>
>>dim fso as new fileSystemObject
>>dim strShowOpenFileReturned as string
>>dim strToFIle as string
>>dim strAppToRun as string
>>
>>strToFile = app.path & "\BBLog.bdl"
>>strAppToRun = app.path & "\Parser.exe"
>>
>>'Filters and returns strings w/ file name
>>with CommonDialog
>>.Filter = "Debug FIles (*.bdl)|*.bdl"
>>.ShowOpen
>>strShowOpenFileReturned = .FileName
>>end with
>>'Just for troubleshooting
>>debug.print strShowOpenFileReturned
>>
>>'Copies file returned from commondialog to file spected by Parser.exe
>>fso.CopyFile strShowOpenFileReturned, strToFile, True
>>
>>'Executes Application Parser.exe
>>shell strAppToRun, vbNormalFocus
>>
>>end sub
>>
>>So the code:
>>1) Lets user selects any *.bdl file.
>>2) Copies the file to filename and directory the Parser application
> 
> expects
> 
>>3) runs the Parser application.
>>
>>
>>Now if I replace the commondialg for a hard coded string
>>i.e
>>strShowOpenFileReturned  = "c:\Documents and
>>Settings\UsrName\Desktop\TestAny.bdl"
>>
>>then everything works fine.
>>By the way this path and file name is the same one returned by the
>>commondial.filename (Copied from debug window).
>>
>>Also, the app.path is c:\Program files\ThisTool
>>
>>The Parser.exe opens a proprietary database and parses it to a pipe
>>delimited text file.
>>
>>I have tried replacing common dialog for API but the same happens.
>>I've also tried using shellexecute API to start app.
>>
>>The application gives error can not find file although file is there.
>>if I manually execute file it works fine. Just can not do via VB while
>>using commondialog control or GetOpenFileName API.
>>
>>Any Though?
>>
>>Thanks in advance,
>>Muxer
>>
> 
> 
> 

0
9/14/2003 4:47:08 AM
I> I tried using msgbox to print commondialog or the API returned filename
> string. They both return:
> -c:\Documents and Settings\UsrName\Desktop\TestAny.bdl-
>
> Now, I tried using OleDragDrop data.file(1) and it works.
> However I know commondialog should work.
>
> Any other thoughts?
>

  I don't know. It's hard to tell from the code you posted, but it seems
that your common dialogue must be working fine if it returns the correct
file path string. So I would guess that the problem is somewhere else,
in the way you're handling the return.



0
mayayana4 (7)
9/14/2003 2:56:39 PM
mayayana wrote:
> I> I tried using msgbox to print commondialog or the API returned filename
> 
>>string. They both return:
>>-c:\Documents and Settings\UsrName\Desktop\TestAny.bdl-
>>
>>Now, I tried using OleDragDrop data.file(1) and it works.
>>However I know commondialog should work.
>>
>>Any other thoughts?
>>
> 
> 
>   I don't know. It's hard to tell from the code you posted, but it seems
> that your common dialogue must be working fine if it returns the correct
> file path string. So I would guess that the problem is somewhere else,
> in the way you're handling the return.
> 
> 
> 

Thank you Mayayana!

Group, any other thoughts on this?

0
9/14/2003 9:05:56 PM
Interesting...

One possiblility is that the Parser.exe (its the one generating the error,
right?) is actually looking in whatever is the windows current directory. If you
launch it using Explorer, that would be the directory that it, and the bblog.bdl
file, are sitting in, and all is well. Since it appears your VB app is also
there, the the same is true if you hard code the file path. If, however, you
change the windows current directory, which the common dialog does, then
parser.exe is looking somewhere else.

You could fix this in several ways: expliciting setting the current directory
just before running the shell command might be the simpliest: something like
ChDir(app.path) would appear to work.

I believe there is also an option on the common dialog regarding not changing
the current directory:
    with CommonDialog
        .Flags =  cdlOFNNoChangeDir
    end with
which would avoid the change in the first place.

Hope I sniffed out the snag for you.
Steve

"Muxer" <NoSpammingPlease@Muxer.com> wrote in message
news:tyM8b.236665$2x.67257@rwcrnsc52.ops.asp.att.net...
> Hello group,
>
> I am having this very weird problem w/ commondialog control or the
> GetOpenFileName API.
> I'll post my relevant code and then explain the problem.
>
> private sub cmdShowSelectNParse_click()
>
> dim fso as new fileSystemObject
> dim strShowOpenFileReturned as string
> dim strToFIle as string
> dim strAppToRun as string
>
> strToFile = app.path & "\BBLog.bdl"
> strAppToRun = app.path & "\Parser.exe"
>
> 'Filters and returns strings w/ file name
> with CommonDialog
> .Filter = "Debug FIles (*.bdl)|*.bdl"
> .ShowOpen
> strShowOpenFileReturned = .FileName
> end with
> 'Just for troubleshooting
> debug.print strShowOpenFileReturned
>
> 'Copies file returned from commondialog to file spected by Parser.exe
> fso.CopyFile strShowOpenFileReturned, strToFile, True
>
> 'Executes Application Parser.exe
> shell strAppToRun, vbNormalFocus
>
> end sub
>
> So the code:
> 1) Lets user selects any *.bdl file.
> 2) Copies the file to filename and directory the Parser application expects
> 3) runs the Parser application.
>
>
> Now if I replace the commondialg for a hard coded string
> i.e
> strShowOpenFileReturned  = "c:\Documents and
> Settings\UsrName\Desktop\TestAny.bdl"
>
> then everything works fine.
> By the way this path and file name is the same one returned by the
> commondial.filename (Copied from debug window).
>
> Also, the app.path is c:\Program files\ThisTool
>
> The Parser.exe opens a proprietary database and parses it to a pipe
> delimited text file.
>
> I have tried replacing common dialog for API but the same happens.
> I've also tried using shellexecute API to start app.
>
> The application gives error can not find file although file is there.
> if I manually execute file it works fine. Just can not do via VB while
> using commondialog control or GetOpenFileName API.
>
> Any Though?
>
> Thanks in advance,
> Muxer
>


0
9/15/2003 3:00:53 AM
Steve Gerrard wrote:
> Interesting...
> 
> One possiblility is that the Parser.exe (its the one generating the error,
> right?) is actually looking in whatever is the windows current directory. If you
> launch it using Explorer, that would be the directory that it, and the bblog.bdl
> file, are sitting in, and all is well. Since it appears your VB app is also
> there, the the same is true if you hard code the file path. If, however, you
> change the windows current directory, which the common dialog does, then
> parser.exe is looking somewhere else.
> 
> You could fix this in several ways: expliciting setting the current directory
> just before running the shell command might be the simpliest: something like
> ChDir(app.path) would appear to work.
> 
> I believe there is also an option on the common dialog regarding not changing
> the current directory:
>     with CommonDialog
>         .Flags =  cdlOFNNoChangeDir
>     end with
> which would avoid the change in the first place.
> 
> Hope I sniffed out the snag for you.
> Steve
> 
> "Muxer" <NoSpammingPlease@Muxer.com> wrote in message
> news:tyM8b.236665$2x.67257@rwcrnsc52.ops.asp.att.net...
> 
>>Hello group,
>>
>>I am having this very weird problem w/ commondialog control or the
>>GetOpenFileName API.
>>I'll post my relevant code and then explain the problem.
>>
>>private sub cmdShowSelectNParse_click()
>>
>>dim fso as new fileSystemObject
>>dim strShowOpenFileReturned as string
>>dim strToFIle as string
>>dim strAppToRun as string
>>
>>strToFile = app.path & "\BBLog.bdl"
>>strAppToRun = app.path & "\Parser.exe"
>>
>>'Filters and returns strings w/ file name
>>with CommonDialog
>>.Filter = "Debug FIles (*.bdl)|*.bdl"
>>.ShowOpen
>>strShowOpenFileReturned = .FileName
>>end with
>>'Just for troubleshooting
>>debug.print strShowOpenFileReturned
>>
>>'Copies file returned from commondialog to file spected by Parser.exe
>>fso.CopyFile strShowOpenFileReturned, strToFile, True
>>
>>'Executes Application Parser.exe
>>shell strAppToRun, vbNormalFocus
>>
>>end sub
>>
>>So the code:
>>1) Lets user selects any *.bdl file.
>>2) Copies the file to filename and directory the Parser application expects
>>3) runs the Parser application.
>>
>>
>>Now if I replace the commondialg for a hard coded string
>>i.e
>>strShowOpenFileReturned  = "c:\Documents and
>>Settings\UsrName\Desktop\TestAny.bdl"
>>
>>then everything works fine.
>>By the way this path and file name is the same one returned by the
>>commondial.filename (Copied from debug window).
>>
>>Also, the app.path is c:\Program files\ThisTool
>>
>>The Parser.exe opens a proprietary database and parses it to a pipe
>>delimited text file.
>>
>>I have tried replacing common dialog for API but the same happens.
>>I've also tried using shellexecute API to start app.
>>
>>The application gives error can not find file although file is there.
>>if I manually execute file it works fine. Just can not do via VB while
>>using commondialog control or GetOpenFileName API.
>>
>>Any Though?
>>
>>Thanks in advance,
>>Muxer
>>
> 
> 
> 
Steve,

You hit the nail right on the head.

I used the flag you mentioned above and everything works just great.
I knew it was something very simple just could not think out the box.

Thank you very much.

0
9/15/2003 7:34:34 PM
Reply: