leuce Posted September 12, 2007 Share Posted September 12, 2007 (edited) G'day everyone I'm writing a script with which a user must drag and drop a file onto it to be processed. If I include the $CmdLine[1] line in the script, the script refuses to populate a certain StringSplit array. I'm baffled... please help! This script works: #include <File.au3> $cmdfile = FileOpen ("TempA.txt", 128) $command = FileReadLine ($cmdfile) $cmdarray = StringSplit ($command, "#", 1) MsgBox (0, "", $cmdarray[1], 10) MsgBox (0, "", $cmdarray[2], 10) MsgBox (0, "", $cmdarray[3], 10) (the second script is compiled and you drag and drop any other file onto it). The first script runs fine and displays One Two Three but the second script displays a blank $cmdarray[1] and tells me in an error message that $cmdarray[2] has exceeded the number of subscripts. There is NO difference between these two scripts except for that CmdLine[1] line, and that line is crucial to my script ultimately. What is wrong here? Thanks Samuel Edited September 12, 2007 by leuce Link to comment Share on other sites More sharing options...
Developers Jos Posted September 12, 2007 Developers Share Posted September 12, 2007 what is the value of $inputfile ? It will only contain a portion of the whole filename when there are spaces in the path. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
leuce Posted September 12, 2007 Author Share Posted September 12, 2007 (edited) What is the value of $inputfile ? The script breaks regardless of what $inputfile is. My default test file is called af.po, but I've tested it with other files too. It will only contain a portion of the whole filename when there are spaces in the path. No. If I try this: #include <File.au3> $inputfile = $CmdLine[1] MsgBox (0, "", $inputfile, 10) $cmdfile = FileOpen ("TempA.txt", 128) $command = FileReadLine ($cmdfile) $cmdarray = StringSplit ($command, "#", 1) MsgBox (0, "", $cmdarray[1], 10) MsgBox (0, "", $cmdarray[2], 10) MsgBox (0, "", $cmdarray[3], 10) Then the first message does give me the entire path of $inputfile, including spaces. Edited September 12, 2007 by leuce Link to comment Share on other sites More sharing options...
Developers Jos Posted September 12, 2007 Developers Share Posted September 12, 2007 (edited) The script breaks regardless of what $inputfile is. My default test file is called af.po, but I've tested it with other files too.No. If I try this:Then the first message does give me the entire path of $inputfile, including spaces.Its probably a case or wrong workdir thus unable to find TempA.txt.add this to the top of your script:FileChangeDir(@scriptdir) this will set the workdir correctly. Edited September 12, 2007 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
weaponx Posted September 12, 2007 Share Posted September 12, 2007 You should ALWAYS perform a check to make sure $CmdLine[0] doesn't equal zero before attempting to use $CmdLine[1], lest ye desire the wrath of Sir Undefined Variable of Crashalot. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now