Sign in to follow this  
Followers 0
leuce

Adding $CmdLine[1] breaks my script

5 posts in this topic

#1 ·  Posted (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 by leuce

Share this post


Link to post
Share on other sites



what is the value of $inputfile ?

It will only contain a portion of the whole filename when there are spaces in the path.


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by leuce

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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.

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