AutoitNew94 Posted March 9, 2011 Share Posted March 9, 2011 I need some help cleaning up and correcting this. $var = 0 If $Cmdline[0] > 0 Then For $i = 1 To $Cmdline[0] If $i = 1 Then $var = 1 Next Endif If $Cmdline[$var] = ".." Then For $i = 2 To $Cmdline[0] ConsoleWrite($Cmdline[$i] & @LF) Next EndIf If $var = 1 Then For $i = 1 To $Cmdline[0] ConsoleWrite($Cmdline[$i] & " ") Next EndIf When args passed from the command line. I want SCRIPT.EXE Hello World .. to result in Hello World .. and SCRIPT.EXE .. Hello World to result in Hello World Thank You in advance. "You're not smart enough for me to open my inbox, so stop sending me mail." Link to comment Share on other sites More sharing options...
ChrisL Posted March 9, 2011 Share Posted March 9, 2011 This doesn't resemble your code at the top but it does give the result you asked for. If $CMDLINE[0] > 0 then If $CMDLINE[1] = ".." then For $i = 2 to $CMDLINE[0] ConsoleWrite($CMDLINE[$i] & @crlf) Next ElseIf $CMDLINE[$CMDLINE[0]] = ".." then ConsoleWrite($CMDLINERAW & @crlf) EndIf EndIf [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
jvanegmond Posted March 9, 2011 Share Posted March 9, 2011 In favor of a syntax like: SCRIPT.EXE Hello World .. SCRIPT.EXE .. Hello World You would do well to standardize this to: SCRIPT.EXE Hello World SCRIPT.EXE "Hello World" The example below will automatically maintain "Hello World" as a single string, and split Hello World without quotes into two strings. github.com/jvanegmond Link to comment Share on other sites More sharing options...
AutoitNew94 Posted March 9, 2011 Author Share Posted March 9, 2011 You would do well to standardize this to: SCRIPT.EXE Hello World SCRIPT.EXE "Hello World" Thank you Manadar you are absolutely correct. It is much easier just to use quoted and unquoted strings. If $Cmdline[0] > 0 Then For $i = 1 To $CmdLine[0] ConsoleWrite($CmdLine[$i] & @LF) Next EndIf My next question is could you or someone else point me in the direction of processing chars, so when reading through a string like... "Hello %World%" ...the script knows that %World% is a variable and to change that as needed. More preferably the syntax would resemble $World instead of %World.% Thank you again. "You're not smart enough for me to open my inbox, so stop sending me mail." Link to comment Share on other sites More sharing options...
ChrisL Posted March 9, 2011 Share Posted March 9, 2011 There may be a better way but this seems to work #include <array.au3> If $CMDLINE[0] > 0 then Local $aCMDLine[$CMDLINE[0] +1] For $i = 1 to $CMDLINE[0] Switch 1 Case StringinStr($CMDLINE[$i],"%World%"), StringinStr($CMDLINE[$i],"%Hello%") $aCMDLine[$i] = $CMDLINE[$i] $aCMDLINE[$i] = StringReplace($aCMDLINE[$i],"%World%","Earth") $aCMDLINE[$i] = StringReplace($aCMDLINE[$i],"%Hello%","Evening") Case Else $aCMDLine[$i] = $CMDLINE[$i] EndSwitch Next _ArrayDisplay($aCMDLine,"Modified Commandlines") EndIf [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire 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