wbrokaw Posted August 15, 2019 Share Posted August 15, 2019 Here is my script currently: #include <Array.au3> #include <File.au3> Global $arr[0] = _FileListToArrayRec(@ScriptDir,"*.iss") For $i=1 To $arr[0] Run("ssp162.exe") Local $aWnd=WinWaitActive("SSP162.exe", "", 1) Send("0.05" & "{ENTER}") Sleep(100) Send("2" & "{ENTER}") Sleep(100) ControlSend("","","",$arr[0] & "{ENTER}") Sleep(100) StringReplace($arr[0],".iss",".ssp",) Send($aFileList[0] & "{ENTER}") Sleep(100) StringReplace($arr[0],".ssp",".iss") Sleep(100) Send("4" & "{ENTER}") Sleep(100) Send("1" & "{ENTER}") Next When it gets to the ControlSend the variable inputs the number of .iss files and not the name of the file. What am I putting in wrong (I'm sure it is a lot)? Thanks. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted August 15, 2019 Moderators Share Posted August 15, 2019 (edited) @wbrokaw the 0 index (first element returned from _FileListToArrayRec is the number of elements in the array. You shouldn't be specifying the index when you instantiate your array, so this instead of what you have (Stay away from Global whenever possible, as well): $arr = _FileListToArrayRec(@ScriptDir, "*.iss") If you need to visualize what the array looks like you can display it: _ArrayDisplay($arr) Thereafter you are running a loop: For $i = 1 To $arr[0] telling AutoIt to count from one to however many files are in your array. So in your ControlSend statement (as well as all the others) you want to use your $i variable, not a specific index ControlSend("","","",$arr[$i] & "{ENTER}") Edited August 15, 2019 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted August 15, 2019 Share Posted August 15, 2019 @wbrokaw Read carefully the Help file, since: _FileListToArrayRec() returns an array as the function name suggests; ControlSend() needs at least one of the three parameters that you set to ""; StringReplace() returns a string, so you are not storing the string replaced after the usage of the function, and so it's useless. Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
wbrokaw Posted August 15, 2019 Author Share Posted August 15, 2019 I was able to get it working correctly with Local $arr = _FileListToArrayRec(@ScriptDir,"*.iss") For $i=1 To $arr[0] Run("ssp168.exe") Local $aWnd=WinWaitActive("SSP162.exe", "", 1) Send("0.05" & "{ENTER}") Sleep(100) Send("2" & "{ENTER}") Sleep(100) ControlSend("","","",$arr[$i] & "{ENTER}") Sleep(500) Send(StringReplace($arr[$i],".iss",".ssp") & "{ENTER}") Sleep(500) Send("4" & "{ENTER}") Sleep(100) Send("1" & "{ENTER}") Sleep(500) Next I then quickly noticed when I tried letting someone else use this that they did not include the required .exe in the run file which caused the script to run in this example 16 times. I want to add a simple if then statement to this for next loop. When I use the below code it always returns the .exe is missing: If FileExists(@ScriptDir & "\SSP168.exe") Then Run("ssp168.exe") Else Exit EndIf I get the error that the Else has no If statement. Not sure what I'm doing wrong with this one. Thanks Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted August 15, 2019 Moderators Share Posted August 15, 2019 You have no Then keyword at the end of your If line - look at the help file for correct syntax. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
wbrokaw Posted August 16, 2019 Author Share Posted August 16, 2019 13 hours ago, JLogan3o13 said: You have no Then keyword at the end of your If line - look at the help file for correct syntax. It is before the Run function. I tried moving the Run function down a line as that is also acceptable syntax. Local $iFileExists = FileExists($sFilePath) ; Display a message of whether the file exists or not. If $iFileExists Then MsgBox($MB_SYSTEMMODAL, "", "The file exists." & @CRLF & "FileExist returned: " & $iFileExists) Else MsgBox($MB_SYSTEMMODAL, "", "The file doesn't exist." & @CRLF & "FileExist returned: " & $iFileExists) EndIf This is from the Help file. Local $iFileExists = FileExists(@ScriptDir & "\SSP168.exe") If $iFileExists Then Run("ssp168.exe") Else Exit EndIf This is what I currently have. I still get the Else does not have an If error message. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted August 16, 2019 Moderators Share Posted August 16, 2019 (edited) My apologies, I missed the Then above. But you cannot do a single line If, like you have here 14 hours ago, wbrokaw said: If FileExists(@ScriptDir & "\SSP168.exe") Then Run("ssp168.exe") Else Exit EndIf and an else. Are you sure the error is pointing to this If line, and not another in your code? This works just fine for me: Local $boolFileExists = FileExists(@DesktopDir & "\MyFile.xlsx") If $boolFileExists Then ConsoleWrite("Yup" & @CRLF) Else Exit EndIf How about copying the entire error message into the thread so we can see just what you're seeing? Edited August 16, 2019 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
wbrokaw Posted August 16, 2019 Author Share Posted August 16, 2019 31 minutes ago, JLogan3o13 said: Are you sure the error is pointing to this If line, and not another in your code? This works just fine for me: I am testing the If statement in a separate .au3 file. I closed and reopened the script and it seems to have fixed that error 🙄. However, I know the .exe I am looking for is in the folder and it is not running the program it just exits the script so I now don't get an error message and it does not open the program. The script is not in the root drive so I am not putting a double "\" in name. Is there something I am doing wrong with the @ScriptDir? The .exe copied from the folder is SSP162.exe. Link to comment Share on other sites More sharing options...
AdamUL Posted August 16, 2019 Share Posted August 16, 2019 Use the full path to the EXE in the Run command. Quotes are added as the path may contains spaces. Run('"' & @ScriptDir & '\SSP168.exe"') Adam 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