grimmlock Posted January 2, 2013 Posted January 2, 2013 (edited) Hello I am trying to figure out why I am getting the error: Array variable has incorrect number of subscripts or subscript dimension range is incorrect And how to fix it. Here is my code: Func mysql($branch) ; , $element) ; establish an array with too many elements Local $output[80] ; establish a counter starting at zero $count = 0 ; put query together $sql = _MySQLConnect("DHCP","1234","test","192.168.26.18") $var = _Query($sql,"SELECT * FROM Leases WHERE Branch='" & $branch & "'") With $var ;loop through the query result While NOT .EOF ;put data into array $output[$count]=.Fields("IP").value ; This is where the error is. ;increment the counter $count += 1 ; end of the loop wend ; resize the array to the number of elements ReDim $output[$count] EndWith ; return the proper sized array return $output EndFunc Thanks Grimm Edited January 3, 2013 by grimmlock Thanks Grimm
guinness Posted January 3, 2013 Posted January 3, 2013 Shouldn't it be something like this? $output[$count]= $oVar.Fields("IP").value UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
grimmlock Posted January 3, 2013 Author Posted January 3, 2013 (edited) Guiness I just tried that and I get the Error: $oVar: Variable used without being declaired. Thanks for the suggestion though Edited January 3, 2013 by grimmlock Thanks Grimm
guinness Posted January 3, 2013 Posted January 3, 2013 It was an example, I presume it should be $var, but I have little knowledge of SQL. Sorry. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
grimmlock Posted January 3, 2013 Author Posted January 3, 2013 LOL, gotcha.I did use both $var and $oVar and I got the same error:Array variable has incorrect number of subscripts or subscript dimension range is incorrectI am not sure what I am doing wrong. Thanks Grimm
grimmlock Posted January 3, 2013 Author Posted January 3, 2013 (edited) Here is the entire code: expandcollapse popup#include <GUIConstantsEx.au3> #include <GUIConstants.au3> #include <File.au3> #include <Array.au3> #include <mysql.au3> GUICreate("test", 400, 400) GUISetState(@SW_SHOW) Local $Combo = GUICtrlCreateCombo("", 10, 10, 100, 20) GUICtrlSetData(-1, "Branch1|Branch2") ; So you have all the lists able to be selected from the combo Local $List1 = GUICtrlCreateList("", 10, 50, 100, 50) Local $List2 = GuiCtrlCreateList("", 10, 100, 100, 50) Local $List3 = GuiCtrlCreateList("", 10, 150, 100, 50) Local $Button_1 = GUICtrlCreateButton("Notepad", 200, 50, 100, 100) Local $Button_2 = GUICtrlCreateButton("Wake On Lan", 200, 200, 100, 100) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $Combo Switch GuiCtrlRead($Combo) Case "Buena" Local $ip = mysql("Branch1") Local $mac = mysql("Branch1") MsgBox(0, "", GuiCtrlRead($ip[3])) ;~ GuiCtrlSetData($List1, $ip[3]) EndSwitch Case $Button_1 Case $Button_2 EndSwitch WEnd Func mysql($branch) ;, $element) ; establish an array with too many elements Local $output[80] ; establish a counter starting at zero $count = 0 ; put query together $sql = _MySQLConnect("DHCP","1234","test","192.168.26.18") $var = _Query($sql,"SELECT * FROM Leases WHERE Branch='" & $branch & "'") With $var ;loop through the query result While NOT .EOF ;put data into array $output[$count] = .Fields("Name").value ;increment the counter $count += 1 ; end of the loop wend ; resize the array to the number of elements ;~ ReDim $output[$count] EndWith ; return the proper sized array return $output EndFunc Edited January 3, 2013 by grimmlock Thanks Grimm
DW1 Posted January 3, 2013 Posted January 3, 2013 (edited) Try adding: .MoveNext to your loop to move on to the next record. Does this work better? expandcollapse popup#include <GUIConstantsEx.au3> #include <GUIConstants.au3> #include <File.au3> #include <Array.au3> #include <mysql.au3> GUICreate("test", 400, 400) GUISetState(@SW_SHOW) Local $Combo = GUICtrlCreateCombo("", 10, 10, 100, 20) GUICtrlSetData(-1, "Branch1|Branch2") ; So you have all the lists able to be selected from the combo Local $List1 = GUICtrlCreateList("", 10, 50, 100, 50) Local $List2 = GUICtrlCreateList("", 10, 100, 100, 50) Local $List3 = GUICtrlCreateList("", 10, 150, 100, 50) Local $Button_1 = GUICtrlCreateButton("Notepad", 200, 50, 100, 100) Local $Button_2 = GUICtrlCreateButton("Wake On Lan", 200, 200, 100, 100) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $Combo Switch GUICtrlRead($Combo) Case "Buena" Local $ip = mysql("Branch1") Local $mac = mysql("Branch1") MsgBox(0, "", GUICtrlRead($ip[3])) ;~ GuiCtrlSetData($List1, $ip[3]) EndSwitch Case $Button_1 Case $Button_2 EndSwitch WEnd Func mysql($branch) ;, $element) ; establish an array with too many elements Local $output[80] ; establish a counter starting at zero $count = 0 ; put query together $sql = _MySQLConnect("DHCP", "1234", "test", "192.168.26.18") $var = _Query($sql, "SELECT * FROM Leases WHERE Branch='" & $branch & "'") With $var ;loop through the query result While Not .EOF ;put data into array $output[$count] = .Fields("Name").value ;Move to next record .MoveNext ;increment the counter $count += 1 ; end of the loop WEnd ; resize the array to the number of elements ;~ ReDim $output[$count] EndWith ; return the proper sized array Return $output EndFunc ;==>mysql Edited January 3, 2013 by danwilli AutoIt3 Online Help
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