sokol Posted August 18, 2009 Share Posted August 18, 2009 I am making a macro for a web based game. I have everything workin fine, however I have say 100 targets that can be attacked, and rather then list their coordinates in the script I'm trying to use an excel sheet to store them as arrays. My problem is the number I want to attack varies, so I set cell in my excel sheet to determine the array size. This seems to work. Example: #include <Excel.au3> #include <Array.au3> $sFilePath1 = @ScriptDir & "\npc.xlsx" ;This file should already exist $oExcel = _ExcelBookOpen($sFilePath1, 0) If @error = 1 Then MsgBox(0, "Error!", "Unable to Create the Excel Object") Exit ElseIf @error = 2 Then MsgBox(0, "Error!", "File does not exist!") Exit EndIf $aArray0 = _ExcelReadCell($oExcel, 1, 4) ;Number of NPC's to attack $aArray1 = _ExcelReadArray($oExcel, 1, 1, ($aArray0), 1) ;Direction is Vertical $aArray2 = _ExcelReadArray($oExcel, 1, 2, ($aArray0), 1) ;Direction is Horizontal _ArrayDisplay($aArray1, "NPCX") _ArrayDisplay($aArray2, "NPCY") ;MsgBox(0, "Exiting", "Press OK to Save File and Exit") ;_ExcelBookSaveAs($oExcel, @ScriptDir & "\npc.xlsx", "xlsx", 0, 1) ; Now we save it into the script directory; overwrite existing file if necessary _ExcelBookClose($oExcel) ; And finally we close out So I moved on thos phase 2 as this proved to me I can set an array size using the _ExcelReadCell function. Now in the next Example: expandcollapse popup#include <Excel.au3> #include <Array.au3> $sFilePath1 = @ScriptDir & "\npc.xlsx" ;This file should already exist $oExcel = _ExcelBookOpen($sFilePath1, 0) If @error = 1 Then MsgBox(0, "Error!", "Unable to Create the Excel Object") Exit ElseIf @error = 2 Then MsgBox(0, "Error!", "File does not exist!") Exit EndIf ; Method Excel ; Set Number of NPC's to attack $numberofattacks = _ExcelReadCell($oExcel, 1, 4) $aArrayX = _ExcelReadArray($oExcel, 2, 3, ($numberofattacks), 1) ; X Coordinates $aArrayY = _ExcelReadArray($oExcel, 4, 3, ($numberofattacks), 1) ; Y Coordinates Global $names[$numberofattacks] ;ReDim $aArrayX[$aArrayX[0] + 1] $names = $aArrayX ;$Loops = InputBox("Question", "How Many Loops?") Sleep(1000) $i = 0 $count = 0 While $i <= $names $i = $i + 1 $count = $count +1 ToolTip($count & " - Loops" ,0,0) MsgBox(0, "Name", $names[$i]) WEnd _ExcelBookClose($oExcel) ; And finally we close out It brins up the message box shows all 7 of the X coordinates that I have but then at the last terminates with an error. I'm trying to set up arrays so I can call a function to run an atatck loop each time selecting the next X & Y coordinates in my excel sheet. Any ideas and or help with my above problem is appreciated. ~Sokol Link to comment Share on other sites More sharing options...
WolfWorld Posted August 18, 2009 Share Posted August 18, 2009 From Global $names[$numberofattacks] To Global $names[$numberofattacks + 1] Main project - Eat Spaghetti - Obfuscate and Optimize your script. The most advance add-on.Website more of GadGets! Link to comment Share on other sites More sharing options...
sokol Posted August 19, 2009 Author Share Posted August 19, 2009 From Global $names[$numberofattacks] To Global $names[$numberofattacks + 1] Thank you, however I'm still getting The following upon Termination of showing the last array. E:\Examples\Arrays.au3 (46) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: MsgBox(0, "Name", $names[$i]) MsgBox(0, "Name", ^ ERROR ->05:18:50 AutoIT3.exe ended.rc:1 +>05:18:51 AutoIt3Wrapper Finished >Exit code: 1 Time: 10.229 I also apologize in advance for typos, my laptop has some issues with some of the keys not working all the time, and sticking half the time. I also apologize that I'm just learning this so what might seem simple for some is all new to me =) (I'm also searching the forums but haven't found a solution.) Again the script does what it is supposed to, it shows all 7 coordinates listed but then terminates with the above error. Again thank you for the time! ~Sokol Link to comment Share on other sites More sharing options...
99ojo Posted August 19, 2009 Share Posted August 19, 2009 (edited) Thank you, however I'm still getting The following upon Termination of showing the last array. E:\Examples\Arrays.au3 (46) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: MsgBox(0, "Name", $names[$i]) MsgBox(0, "Name", ^ ERROR ->05:18:50 AutoIT3.exe ended.rc:1 +>05:18:51 AutoIt3Wrapper Finished >Exit code: 1 Time: 10.229 I also apologize in advance for typos, my laptop has some issues with some of the keys not working all the time, and sticking half the time. I also apologize that I'm just learning this so what might seem simple for some is all new to me =) (I'm also searching the forums but haven't found a solution.) Again the script does what it is supposed to, it shows all 7 coordinates listed but then terminates with the above error. Again thank you for the time! ~Sokol Hi, change the while loop: $i = 0 $count = 0 While $i <= $names $i = $i + 1 $count = $count +1 ToolTip($count & " - Loops" ,0,0) MsgBox(0, "Name", $names[$i]) WEnd to For $i = 0 To UBound ($names) - 1 ToolTip($i + 1 & " - Loops" ,0,0) MsgBox(0, "Name", $names[$i]) Next You don't need to define $i = 0 and $count = 0 anymore. Also your While Loop would run for ever, because $names is an array. ;-)) Stefan Edited August 19, 2009 by 99ojo Link to comment Share on other sites More sharing options...
sokol Posted August 19, 2009 Author Share Posted August 19, 2009 For $i = 0 To UBound ($names) - 1 ToolTip($i + 1 & " - Loops" ,0,0) MsgBox(0, "Name", $names[$i]) Next You don't need to define $i = 0 and $count = 0 anymore. Also your While Loop would run for ever, because $names is an array. ;-)) Stefan That did the trick and thank you both for the help! ~Sokol 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