Jump to content

Help needed ........ :(


Clay
 Share

Recommended Posts

Hell-o,

I am hoping that someone - anyone - can provide me with some assistance with a small road bump that I have encountered while creating a script. I am pretty much new to Autoit and I am attempting to use this pretty sweet scripting language to do some testing.

For my purposes I would like the ability to build command line parameters into the script in order to dictate which actions are executed by the script. I have scripted what I believe is the correct manner to extracting whatever commandline parameter is passed to the script and comparing it against a switch statement, however while testing to see if this works I have encountered the following error:

Error: Can not assign values to constants.

I looked through a few forums and from what I have gathered I am apparently doing the correct thing....however the error message tells me otherwise. Could someone more knowledgeable in regards to using the CmdLine [] array PLEASE provide me with some assistance?

I have included a small snippet of the script below

Thank you .... in anticipation of your assistance.

Clay

if $CmdLine[0]= 0 Then

MsgBox(0, "Check", "No CommandLine Arguments Found");debug

Exit(1)

else

$cmdline=$CmdLine[1]

EndIf

Switch <$cmdline>

Case '\BuildGW'

MsgBox(0, "Check", "It is currently selecting BuildGW");debug

]

[Case '\BuildClient'

MsgBox(0, "Check", "It is currently selecting BuildClient");debug

[Case '\BuildSample'

MsgBox(0, "Check", "It is currently selecting BuildSample");debug

Case '\BuildPkg'

MsgBox(0, "Check", "It is currently selecting BuildPkg");debug

[Case Else

MsgBox(0, "Check", "It is currently selecting BuildALL");debug

EndSwitch

Edited by Clay
Link to comment
Share on other sites

Hell-o,

I am hoping that someone - anyone - can provide me with some assistance with a small road bump that I have encountered while creating a script. I am pretty much new to Autoit and I am attempting to use this pretty sweet scripting language to do some testing.

For my purposes I would like the ability to build command line parameters into the script in order to dictate which actions are executed by the script. I have scripted what I believe is the correct manner to extracting whatever commandline parameter is passed to the script and comparing it against a switch statement, however while testing to see if this works I have encountered the following error:

Error: Can not assign values to constants.

I looked through a few forums and from what I have gathered I am apparently doing the correct thing....however the error message tells me otherwise. Could someone more knowledgeable in regards to using the CmdLine [] array PLEASE provide me with some assistance?

I have included a small snippet of the script below

Thank you .... in anticipation of your assistance.

Clay

if $CmdLine[0]= 0 Then

MsgBox(0, "Check", "No CommandLine Arguments Found");debug

Exit(1)

else

$cmdline=$CmdLine[1]

EndIf

Switch <$cmdline>

Case '\BuildGW'

MsgBox(0, "Check", "It is currently selecting BuildGW");debug

]

[Case '\BuildClient'

MsgBox(0, "Check", "It is currently selecting BuildClient");debug

[Case '\BuildSample'

MsgBox(0, "Check", "It is currently selecting BuildSample");debug

Case '\BuildPkg'

MsgBox(0, "Check", "It is currently selecting BuildPkg");debug

[Case Else

MsgBox(0, "Check", "It is currently selecting BuildALL");debug

EndSwitch

Welcome to the AutoIt forums :)

One tip about posting code is to enclose it in code tags then it's easier for people to read. Put [ c o d e ] at the start, less the spaces, and [ / c o d e ] at the end of the code. Instead of the word code yu can use AutoIt which has the advantage of colouring the key words, but it has the disadvatage that it messes things up so often that I am one of a number of people who have given up using them.

Try this

if $CmdLine[0]= 0 Then
MsgBox(0, "Check", "No CommandLine Arguments Found");debug
Exit(1)
EndIf

;$cmdline=$CmdLine[1];change the name of the variable, this attempts to destroy the array
$Command = $CmdLine[1]; would be better


Switch $Command

Case '\BuildGW'
MsgBox(0, "Check", "It is currently selecting BuildGW");debug

Case '\BuildClient'
MsgBox(0, "Check", "It is currently selecting BuildClient");debug

Case '\BuildSample'
MsgBox(0, "Check", "It is currently selecting BuildSample");debug

Case '\BuildPkg'
MsgBox(0, "Check", "It is currently selecting BuildPkg");debug

Case Else
MsgBox(0, "Check", "It is currently selecting BuildALL");debug

EndSwitch

EDIT: Corrected the errors I made which were pointed out by Valuater.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

$cmdline is the constant it is complaing about. $CMDLINE = $CMDLINE[#]

try replacing $CMDLINE with something else....$var = $CMDLINE[#]

Another "Forum tip"....it's not neccesary to reply and quote an entire post from another user (like Martin) when it's right above. :)

Martin forgot the "s" a the end of $Command

Edited by spudw2k
Link to comment
Share on other sites

Welcome to the AutoIt forums :)

One tip about posting code is to enclose it in code tags then it's easier for people to read. Put [ c o d e ] at the start, less the spaces, and [ / c o d e ] at the end of the code. Instead of the word code yu can use AutoIt which has the advantage of colouring the key words, but it has the disadvatage that it messes things up so often that I am one of a number of people who have given up using them.

Try this

if $CmdLine[0]= 0 Then
 MsgBox(0, "Check", "No CommandLine Arguments Found");debug
 Exit(1)
 EndIf
 
;$cmdline=$CmdLine[1];change the name of the variable, this attempts to destroy the array
 $Command = CmdLine[1]; would be better
 
 
 Switch $Commands
 
 Case '\BuildGW'
 MsgBox(0, "Check", "It is currently selecting BuildGW");debug
 
 Case '\BuildClient'
 MsgBox(0, "Check", "It is currently selecting BuildClient");debug
 
 Case '\BuildSample'
 MsgBox(0, "Check", "It is currently selecting BuildSample");debug
 
 Case '\BuildPkg'
 MsgBox(0, "Check", "It is currently selecting BuildPkg");debug
 
 Case Else
 MsgBox(0, "Check", "It is currently selecting BuildALL");debug
 
 EndSwitch
>Running:(3.2.10.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Program Files\AutoIt3\SciTE-Tools\Scitetoolbar_v1_7.au3"    
+>10:04:07 AutoIT3.exe ended.rc:0
+>10:04:08 AutoIt3Wrapper Finished
>Exit code: 0    Time: 2.705
>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /beta /AU3Check /in "C:\Program Files\AutoIt3\Examples\XSkin Folder\trick_old1_old2.au3"
+>10:04:08 Starting AutoIt3Wrapper v.1.9.3
>Running AU3Check (1.54.13.0)  from:C:\Program Files\AutoIt3\beta
C:\Program Files\AutoIt3\Examples\XSkin Folder\trick_old1_old2.au3(7,19) : ERROR: syntax error
$Command = CmdLine[
~~~~~~~~~~~~~~~~~~^
C:\Program Files\AutoIt3\Examples\XSkin Folder\trick_old1_old2.au3(10,17) : WARNING: $Commands: possibly used before declaration.
Switch $Commands
~~~~~~~~~~~~~~~~^
C:\Program Files\AutoIt3\Examples\XSkin Folder\trick_old1_old2.au3(10,17) : ERROR: $Commands: undeclared global variable.
Switch $Commands
~~~~~~~~~~~~~~~~^
C:\Program Files\AutoIt3\Examples\XSkin Folder\trick_old1_old2.au3 - 2 error(s), 1 warning(s)
!>10:04:09 AU3Check ended.rc:2
+>10:04:09 AutoIt3Wrapper Finished
>Exit code: 0    Time: 0.545

8)

NEWHeader1.png

Link to comment
Share on other sites

$cmdline=$CmdLine[1]

You cannot use the $cmdline variable for your own use as it is reserved by AutoIt for the cmdline array variable. Choose any other variable name but that one. You usage of using $CMDLINE[] seems OK except for using $cmdline as previously mentioned. And note that Command Line Parameters are normally done with a leading backslash, not a forwardslash as your code shows. A forwardslash is used for escaping double quotes on a command line.

:)

Link to comment
Share on other sites

>Running:(3.2.10.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Program Files\AutoIt3\SciTE-Tools\Scitetoolbar_v1_7.au3"    
+>10:04:07 AutoIT3.exe ended.rc:0
+>10:04:08 AutoIt3Wrapper Finished
>Exit code: 0    Time: 2.705
>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /beta /AU3Check /in "C:\Program Files\AutoIt3\Examples\XSkin Folder\trick_old1_old2.au3"
+>10:04:08 Starting AutoIt3Wrapper v.1.9.3
>Running AU3Check (1.54.13.0)  from:C:\Program Files\AutoIt3\beta
C:\Program Files\AutoIt3\Examples\XSkin Folder\trick_old1_old2.au3(7,19) : ERROR: syntax error
$Command = CmdLine[
~~~~~~~~~~~~~~~~~~^
C:\Program Files\AutoIt3\Examples\XSkin Folder\trick_old1_old2.au3(10,17) : WARNING: $Commands: possibly used before declaration.
Switch $Commands
~~~~~~~~~~~~~~~~^
C:\Program Files\AutoIt3\Examples\XSkin Folder\trick_old1_old2.au3(10,17) : ERROR: $Commands: undeclared global variable.
Switch $Commands
~~~~~~~~~~~~~~~~^
C:\Program Files\AutoIt3\Examples\XSkin Folder\trick_old1_old2.au3 - 2 error(s), 1 warning(s)
!>10:04:09 AU3Check ended.rc:2
+>10:04:09 AutoIt3Wrapper Finished
>Exit code: 0    Time: 0.545

8)

Well if on the other hand you enclose your script in 'martin' tags it will really get messed up. :)
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Hell-o,

I am hoping that someone - anyone - can provide me with some assistance with a small road bump that I have encountered while creating a script. I am pretty much new to Autoit and I am attempting to use this pretty sweet scripting language to do some testing.

For my purposes I would like the ability to build command line parameters into the script in order to dictate which actions are executed by the script. I have scripted what I believe is the correct manner to extracting whatever commandline parameter is passed to the script and comparing it against a switch statement, however while testing to see if this works I have encountered the following error:

Error: Can not assign values to constants.

I looked through a few forums and from what I have gathered I am apparently doing the correct thing....however the error message tells me otherwise. Could someone more knowledgeable in regards to using the CmdLine [] array PLEASE provide me with some assistance?

I have included a small snippet of the script below

Thank you .... in anticipation of your assistance.

Clay

if $CmdLine[0]= 0 Then

MsgBox(0, "Check", "No CommandLine Arguments Found");debug

Exit(1)

else

$cmdline=$CmdLine[1]

EndIf

Switch <$cmdline>

Case '\BuildGW'

MsgBox(0, "Check", "It is currently selecting BuildGW");debug

]

[Case '\BuildClient'

MsgBox(0, "Check", "It is currently selecting BuildClient");debug

[Case '\BuildSample'

MsgBox(0, "Check", "It is currently selecting BuildSample");debug

Case '\BuildPkg'

MsgBox(0, "Check", "It is currently selecting BuildPkg");debug

[Case Else

MsgBox(0, "Check", "It is currently selecting BuildALL");debug

EndSwitch

Thanks "ALL" for your assistance and advice ...... I hate that I made such a foolish mistake but I am making progress now .. THANKS!!!!!

Edited by Clay
Link to comment
Share on other sites

Hey Guys,

The switch statement seems to fall all the way through to the default option. Can anyone point out to me what I am doing wrong... I tried taking a look at the Documentation but the syntax it presents me with doesn't seem to work.

if $CmdLine[0]= 0 Then
MsgBox(0, "Check", "No CommandLine Arguments Found");debug
Exit(1)
EndIf

;$cmdline=$CmdLine[1];change the name of the variable, this attempts to destroy the array
$Command = CmdLine[1]; would be better


Switch $Commands

Case '\BuildGW'
MsgBox(0, "Check", "It is currently selecting BuildGW");debug

Case '\BuildClient'
MsgBox(0, "Check", "It is currently selecting BuildClient");debug

Case '\BuildSample'
MsgBox(0, "Check", "It is currently selecting BuildSample");debug

Case '\BuildPkg'
MsgBox(0, "Check", "It is currently selecting BuildPkg");debug

Case Else
MsgBox(0, "Check", "It is currently selecting BuildALL");debug

EndSwitch
Link to comment
Share on other sites

  • Developers

The posted script has never ran because it contains errors. try updating & adding these.

$Commands = $CmdLine[1]; would be better
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Commands = ' & $Commands & @crlf & '>Error code: ' & @error & @crlf);### Debug Console

Run this in SciTE and check what the value of $Commands is in the output pane.

Edited by Jos

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

The posted script has never ran because it contains errors. try updating & adding these.

$Commands = $CmdLine[1]; would be better
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Commands = ' & $Commands & @crlf & '>Error code: ' & @error & @crlf);### Debug Console

Run this in SciTE and check what the value of $Commands is in the output pane.

I Figured out a work-around for my issue. Thanks.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...