Sign in to follow this  
Followers 0
grimmlock

Error on $output[$count]

7 posts in this topic

#1 ·  Posted (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 by grimmlock

Thanks

Grimm

Share this post


Link to post
Share on other sites



Shouldn't it be something like this?

$output[$count]= $oVar.Fields("IP").value

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Guiness

I just tried that and I get the Error: $oVar: Variable used without being declaired.

Thanks for the suggestion though :)

Edited by grimmlock

Thanks

Grimm

Share this post


Link to post
Share on other sites

It was an example, I presume it should be $var, but I have little knowledge of SQL. Sorry.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

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 incorrect

I am not sure what I am doing wrong. :(


Thanks

Grimm

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Here is the entire code:

#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 by grimmlock

Thanks

Grimm

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Try adding: .MoveNext to your loop to move on to the next record.

Does this work better?

#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 by danwilli

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • MarkBe
      By MarkBe
      Hi
      I am trying to check a number of applications are up to date and install the update if required. This will run as a shutdown script, pushed out through Group Policy.
      I am querying various registry keys to determine if
      The software is actually installed The software is at the correct version Once the need for update is determined then it calls another function to run the update.
      If the software is up to date or not installed, it moves down to the next software section which changes the registry key variables and calls the registry query function again
      I have managed to get the function for (un)installs to work but I am having trouble with the registry query function
      #NoTrayIcon #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <FileConstants.au3> ; Here we go! ;########################################################################################################## ;Declare variables Global $RegKey86, $RegKey64, $RegValueName, $RegValueData, $CheckVersion86, $CheckVersion64 ; 7Zip ;########################################################################################################## _7Zip_Function() Func _7Zip_Function() ; Registry location and values that are checked for current software version ; Ensure the x64 key is preceeded with 'HKLM64' $RegKey86="HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\7-Zip" $RegKey64="HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\7-Zip" $RegValueName="DisplayVersion" $RegValueData="16.04" ; Excecution ; --------------------------------------------------------------------------------------------------------- If _CheckSW() = 1 Then _UninstallOldVer() _InstallSW() EndIf EndFunc ;==>_7Zip_Function ; Functions ;########################################################################################################## Func _CheckSW() $CheckVersion86=RegRead ($RegKey86, $RegValueName) $CheckVersion64=RegRead ($RegKey64, $RegValueName) If $CheckVersion86=$RegValueData Or $CheckVersion64=$RegValueData Then Return 0 ElseIf $CheckVersion86="" And $CheckVersion64="" Then Return 0 Else Return 1 EndIf EndFunc ;==>CheckSW  
    • WoodGrain
      By WoodGrain
      Hi guys,
      Could someone please tell me what I'm doing wrong with this code?
      I'm trying to take user input and then run a function with the same name, but it's not calling the function.
      So in the below after pressing Shift+F8 I would enter the text (without quotes) "testFunc".
      As you can see I've also tried this with IF statements, I'm new to using Switch/Case.
      HotKeySet("+{F8}", RunManually) Func RunManually() ;Use a case statement with 1 hot key and an InputBox to manually run functions $funcName = InputBox("Which Func to Run?", "Enter the name of the function to run") MsgBox(0, "Entered value", $funcName) ;If $funcName = testFunc Then testFunc() ;If $funcName = test2Func Then test2Func() Switch $funcName Case testFunc MsgBox(0, "Calling", "Calling Function") testFunc() MsgBox(0, "Called", "Function call finished") Case test2Func MsgBox(0, "Calling", "Calling Function") test2Func() MsgBox(0, "Called", "Function call finished") EndSwitch EndFunc While 1 ;testFunc() Sleep(1000) WEnd Func testFunc() MsgBox(0, "func running", "Seems to work!") EndFunc Func test2Func() MsgBox(0, "func 2 running", "2 Seems to work!") EndFunc Thanks!
    • TheOnlyOne
      By TheOnlyOne
      So currently I have some code waiting for a status to change(there is different indicators to check if this status has changed) 
      Func oneRow($count) $globaltimer = _Timer_SetTimer($gui, 60000*10, "reset") $errTimer = TimerInit() While (1)         If PixelGetColor(1117, 326) = 0xC6C6C6 Then ExitLoop (1)         Sleep(500)         MouseClick("right")         Sleep(600)         If PixelGetColor(1117, 326) = 0xC6C6C6 Then ExitLoop (1)         If TimerDiff($errTimer) > 5000 Then             If PixelGetColor(1100, 310) = 0x707070 Or PixelGetColor(901, 305) = 0xE0E0E0 Or PixelGetColor(1043, 383) = 0xC6C6C6 Then                 Sleep(100)                 Send("{esc}")                 Sleep(1000)             EndIf         EndIf     WEnd .... EndFunc   ;==>oneRow The two timers is for error checking. This works just fine the problem comes when I go into the while 1 loop, my hotkeys at the top of the program seems to stop working, for an example 
      HotKeySet("{f1}", "stop") Func stop() Exit EndFunc ;==>stop Does not work at all after the while loop. The globaltimer is never called even though i tried setting the delay all the way down to 3 seconds. So I thought that maybe one of the function I use is blocking so the timer would never be called/the hotkey wouldn't work? if i make an delay just before the while loop the hotkey works just fine. Oh and the errTimer is supossed to not reset after 5 seconds but should keep making the check it does if five seconds have passed
    • alongsnake
      By alongsnake
      The best example is MouseClick, where you have MouseClick($Button, [$x, $y, [..........]]) Where if X is set, Y must be set too.
      I do know how to make it so that X and Y are optional, but I am not sure how to get Y mandatory if X is set. I did check the help, but didn't see anything there.
      Thanks in advance
    • TheDcoder
      By TheDcoder
      <snip>
      Hello , This time my script is throwing an error which does not make sense... How can I fix this?
      Code Snippet from the screenshot:
       
       
       P.S You saw it right, I am making a small handy tool for AutoIt Coders, TD