Sign in to follow this  
Followers 0
MaCgyver

Trying to open a file based upon the following...

5 posts in this topic

$message = "Select the report you want to print."

$var = FileOpenDialog($message, "\\sv000bktrade\bnktrade\batch\FWR\Archives\", "Text files (*.txt)")

If @error Then

MsgBox(4096,"","No report selected.")

Else

$var = StringReplace($var, "|", @CRLF)

EndIf

;I've tried fileopen($var) and it wouldn't work. I am still new to all of this, so maybe I'm missing something bigtime here.

Share this post


Link to post
Share on other sites



when you tried

fileopen($var)

did you expect to "see" something..

?

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

MaCgyver,

Sort of like Valuater said, are you assuming that the FileOpen function sends the file to some application for opening? Opening in a way that you can see? Opening like notepad would open a file? As I understand it, the AutoIt FileOpen function (in the read mode) opens a file so that it can be read into memory - it does not open the file to the display for you to read it. [The help file is great, but it does not deal with this misconception... at least not that I can find.]

Your FileOpenDialog line seems to be missing the setting for "Allow MultiSelect"...

[i assumed that you wanted that option since you coded for the "|" later on.]

FileOpenDialog ( "title", "init dir", "filter", options, "default name" )

$var = FileOpenDialog($message, "\\sv000bktrade\bnktrade\batch\FWR\Archives\", "Text files (*.txt)", 4)

If the user had selected multiple files, $var would be holding this:

C:\|textfile1.txt|textfile2.txt|textfile3.txt

This line of your code:

$var = StringReplace($var, "|", @CRLF)

would turn it into this:

C:\

textfile1.txt

textfile2.txt

textfile3.txt

You might want a line like this instead:

$varArray = StringSplit($var, "|")

That line will create this in memory:

$varArray[0] = 4

$varArray[1] = C:\

$varArray[2] = textfile1.txt

$varArray[3] = textfile2.txt

$varArray[4] = textfile3.txt

Having the output of a FileOpenDialog in an array makes it easy to do things with each part of the info, like this:

For $i = 2 to $varArray[0]
    MsgBox(0,"",$varArray[$i])
Next
That loop should work even if the user only selects one file.

If you want to display the file via some app, replace the MsgBox line with the applicable "run" line.

...hope this helps...


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

just to add on my little bit... this is a piece of code i use a lot to run non-executables

func startf($filex, $workingdir, $args = "")
if filexists($filex) then
if $args <> ""
return Run(@comspec & " /c start "  & $filex & " " & $args, $workingdir,@SW_HIDE)
else
return Run(@comspec & " /c start " & $filex,$workingdir,@SW_HIDE)
endif
endif
endfunc

so try somethin like

$message = "Please select a file"
$var = FileOpenDialog($message, "\\sv000bktrade\bnktrade\batch\FWR\Archives\", "Text files (*.txt)")

If @error Then
MsgBox(4096,"","No report selected.")
Else
$var = StringReplace($var, "|", @CRLF)
EndIf
$var = StringSplit($var, @CRLF)
for $i = 0 to $var[0]
startf($var[$i])
Next
func startf($filex, $workingdir, $args = "")
if filexists($filex) then
if $args <> ""
return Run(@comspec & " /c start "  & $filex & " " & $args, $workingdir,@SW_HIDE)
else
return Run(@comspec & " /c start " & $filex,$workingdir,@SW_HIDE)
endif
endif
endfunc

--hope this helps

~cdkid

Edited by cdkid

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!

Share this post


Link to post
Share on other sites

just to add on my little bit... this is a piece of code i use a lot to run non-executables

func startf($filex, $workingdir, $args = "")
if filexists($filex) then
if $args <> ""
return Run(@comspec & " /c start "  & $filex & " " & $args, $workingdir,@SW_HIDE)
else
return Run(@comspec & " /c start " & $filex,$workingdir,@SW_HIDE)
endif
endif
endfunc

so try somethin like

$message = "Please select a file"
$var = FileOpenDialog($message, "\\sv000bktrade\bnktrade\batch\FWR\Archives\", "Text files (*.txt)")

If @error Then
MsgBox(4096,"","No report selected.")
Else
$var = StringReplace($var, "|", @CRLF)
EndIf
$var = StringSplit($var, @CRLF)
for $i = 0 to $var[0]
startf($var[$i])
Next
func startf($filex, $workingdir, $args = "")
if filexists($filex) then
if $args <> ""
return Run(@comspec & " /c start "  & $filex & " " & $args, $workingdir,@SW_HIDE)
else
return Run(@comspec & " /c start " & $filex,$workingdir,@SW_HIDE)
endif
endif
endfunc

--hope this helps

~cdkid

Thanks guys. You've cleared up some things for me. Hey cd kid I tried your code, but got an error on line 15. I added a "then" according to the error but then got another error. I am going to work on it some more. I need to do some research on on it. Thanks anyway. You pointed me in the right direction.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0