kartune Posted March 21, 2018 Posted March 21, 2018 Hello, I am getting this error message when running my script: Case $aButiD[0] To $aButiD[$iTotButtons - 1] Case ^ ERROR Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded. The script's purpose is to read my ini file and create buttons for the sections and section contents. The first part of the script creates buttons for the sections of the ini, once you click on the section button it should open another set of buttons of all the contents under the section In this case, the section in the .ini file is called "TPA" on the Func flavorco() It opens the contents of "TPA" into buttons. Right now, the section it is reading is determined by $sSection. It is only when I try to change $sSection = "TPA" to $sSection = $flavorco that the error starts to appear Here is the script expandcollapse popup#include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> $optbar = IniReadSectionNames("test.ini") If Not IsArray($optbar) Then Exit Local $Button[UBound($optbar) - 1] $mGUI = GUICreate('Restock Flavor Ingredients', 10 + (130 * UBound($optbar)), 100) For $x = 1 To UBound($optbar) - 1 $var = IniReadSection("test.ini", $optbar[$x]) If @error Then ContinueLoop $X_Coord = 10 + (($x - 1) * 100) $Button[$x - 1] = GUICtrlCreateButton($optbar[$x], $X_Coord, 30, 70, 30) Next GUISetState() While 1 $mMsg = GUIGetMsg() If $mMsg = $GUI_EVENT_CLOSE Then GUIDelete($mGUI) ExitLoop EndIf For $i = 0 To UBound($Button) - 1 If $mMsg = $Button[$i] Then MsgBox(0, '$Msg = ' & $mMsg, GuiCtrlRead($Button[$i]) & ' Pressed', 2) Global $flavorco = $Button ; sets the flavor company's variable Call('flavorco') EndIf Next WEnd Func flavorco() ;opened flavor company's flavors MsgBox(0, '$Msg = ' & $mMsg, GuiCtrlRead($Button[$i]) & $flavorco, 0) Local $sFilePath = @ScriptDir & "\Test.ini" Local $sSection = $Button Local $aArray = IniReadSection($sFilePath, $sSection) _ArrayDelete($aArray, 0) ;_ArrayDisplay($aArray) Local $iIndex Local $iTotButtons = UBound($aArray) Local $iNumPerRow = 5 Local $iButWidth = 100 Local $iButDepth = 30 Local $aButiD[$iTotButtons] Local $hGUI = GUICreate('Ingredients Stock "' & $sFilePath & '"', 10 + ($iButWidth + 10) * $iNumPerRow, _ 10 + Ceiling($iTotButtons / $iNumPerRow) * ($iButDepth + 10), -1, $WS_EX_TOPMOST) For $i = 0 To $iTotButtons - 1 ; $x = $iXBorder + (($iRectWidth + $iSpacing) * Mod($i, $iNumCols)) $x = 10 + (($iButWidth + 10) * Mod($i, $iNumPerRow)) ; $y = $iYBorder + (($iRectDepth + $iSpacing) * Int($i / $iNumCols)) $y = 10 + (($iButDepth + 10) * Int($i / $iNumPerRow)) $aButiD[$i] = GUICtrlCreateButton($aArray[$i][0], $x, $y, $iButWidth, $iButDepth) ;, $BS_NOTIFY) Next GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE GUIDelete($hGUI) ExitLoop Case $aButiD[0] To $aButiD[$iTotButtons - 1] ;clicking on a flavor name $iIndex = ($msg - $aButiD[0]) $RSINGRflavor = $aArray[$iIndex][0] ;flavor name $RSINGRml = $aArray[$iIndex][1] ; ml $RSINGRgal = $aArray[$iIndex][1]*0.000264172 ;converts ml to gal Call('openflavor') EndSwitch WEnd EndFunc Func openflavor() #Region ### START Koda GUI section ### Form=F:\Karl\AutoIt\FJ-Stock JP\GUI Forms\RSINGRSUBFORM.kxf ;opens flavor to view stock and restock submit $RSINGRSUBFORM = GUICreate($sSection & " " & $RSINGRflavor, 242, 213, 530, 269) $RSINGRFlavorTitle = GUICtrlCreateLabel($sSection & " " & $RSINGRflavor, 32, 8, 200, 28) GUICtrlSetFont(-1, 16, 800, 0, "MS Sans Serif") $RSINGRstockcaption = GUICtrlCreateLabel("Current Stock in ml:", 16, 48, 96, 17) $RSINGRstockml = GUICtrlCreateLabel($RSINGRml, 120, 48, 114, 25) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $RSINGRInput = GUICtrlCreateInput("ml", 40, 112, 153, 21) $RSINGRSUBMIT = GUICtrlCreateButton("SUBMIT", 16, 152, 81, 33) $RSINGRCLOSE = GUICtrlCreateButton("CLOSE", 145, 151, 81, 33) $RSINGRgalcaption = GUICtrlCreateLabel("Current Stock in gal:", 16, 80, 97, 17) $RSINGRstockgal = GUICtrlCreateLabel($RSINGRGAL, 120, 80, 114, 25) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### ; $msg = "" While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete($RSINGRSUBFORM) ExitLoop Case $RSINGRCLOSE GUIDelete($RSINGRSUBFORM) ExitLoop EndSwitch WEnd EndFunc Any help is much appreciated! Thanks. My guess is that $Button isn't an actual string?? Whenever I use msgbox it shows up the string exactly, no numbers attached. So i'm not sure whats going on here.
Earthshine Posted March 21, 2018 Posted March 21, 2018 (edited) it does not even compile. >Running AU3Check (3.3.14.2) from:C:\Program Files (x86)\AutoIt3 input:C:\Users\root\Desktop\test.au3 "C:\Users\root\Desktop\test.au3"(90,54) : warning: $sSection: possibly used before declaration. $RSINGRSUBFORM = GUICreate($sSection & ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ "C:\Users\root\Desktop\test.au3"(90,75) : warning: $RSINGRflavor: possibly used before declaration. $RSINGRSUBFORM = GUICreate($sSection & " " & $RSINGRflavor, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ "C:\Users\root\Desktop\test.au3"(94,62) : warning: $RSINGRml: possibly used before declaration. $RSINGRstockml = GUICtrlCreateLabel($RSINGRml, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ "C:\Users\root\Desktop\test.au3"(100,64) : warning: $RSINGRGAL: possibly used before declaration. $RSINGRstockgal = GUICtrlCreateLabel($RSINGRGAL, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ "C:\Users\root\Desktop\test.au3"(90,54) : error: $sSection: undeclared global variable. $RSINGRSUBFORM = GUICreate($sSection & ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ "C:\Users\root\Desktop\test.au3"(90,75) : error: $RSINGRflavor: undeclared global variable. $RSINGRSUBFORM = GUICreate($sSection & " " & $RSINGRflavor, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ "C:\Users\root\Desktop\test.au3"(94,62) : error: $RSINGRml: undeclared global variable. $RSINGRstockml = GUICtrlCreateLabel($RSINGRml, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ "C:\Users\root\Desktop\test.au3"(100,64) : error: $RSINGRGAL: undeclared global variable. $RSINGRstockgal = GUICtrlCreateLabel($RSINGRGAL, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Users\root\Desktop\test.au3 - 4 error(s), 4 warning(s) !>14:52:09 AU3Check ended. Press F4 to jump to next error.rc:2 +>14:52:09 AutoIt3Wrapper Finished. >Exit code: 0 Time: 0.647 I am not updating autoit until the teething pains are gone for good. Edited March 21, 2018 by Earthshine My resources are limited. You must ask the right questions
Moderators JLogan3o13 Posted March 21, 2018 Moderators Posted March 21, 2018 (edited) @kartune before you work on the buttons, I would look at some of the other issues. You're declaring local variables in one function, which are then not available in another. Are you using the full version of SciTE with AU3Check? Edit: see example above Edited March 21, 2018 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!
kartune Posted March 21, 2018 Author Posted March 21, 2018 (edited) Sorry, i just noticed that and corrected it, I am using:SciTE-Lite Version 3.5.4 Sep 18 2015 15:04:36 I will check out the full version and au3check now. Here is the revised code: expandcollapse popup#include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> $optbar = IniReadSectionNames("test.ini") If Not IsArray($optbar) Then Exit Local $Button[UBound($optbar) - 1] $mGUI = GUICreate('Restock Flavor Ingredients', 10 + (130 * UBound($optbar)), 100) For $x = 1 To UBound($optbar) - 1 $var = IniReadSection("test.ini", $optbar[$x]) If @error Then ContinueLoop $X_Coord = 10 + (($x - 1) * 100) $Button[$x - 1] = GUICtrlCreateButton($optbar[$x], $X_Coord, 30, 70, 30) Next GUISetState() While 1 $mMsg = GUIGetMsg() If $mMsg = $GUI_EVENT_CLOSE Then GUIDelete($mGUI) ExitLoop EndIf For $i = 0 To UBound($Button) - 1 If $mMsg = $Button[$i] Then MsgBox(0, '$Msg = ' & $mMsg, GuiCtrlRead($Button[$i]) & ' Pressed', 2) Global $flavorco = $Button ; flavor company Call('flavorco') EndIf Next WEnd Func flavorco() ;opened flavor companys flavors MsgBox(0, '$Msg = ' & $mMsg, GuiCtrlRead($Button[$i]) & $flavorco, 0) Global $sFilePath = @ScriptDir & "\Test.ini" Global $sSection = "TPA" Global $aArray = IniReadSection($sFilePath, $sSection) _ArrayDelete($aArray, 0) ;_ArrayDisplay($aArray) Global $iIndex Global $iTotButtons = UBound($aArray) Global $iNumPerRow = 5 Global $iButWidth = 100 Global $iButDepth = 30 Global $aButiD[$iTotButtons] Global $hGUI = GUICreate('Ingredients Stock "' & $sFilePath & '"', 10 + ($iButWidth + 10) * $iNumPerRow, _ 10 + Ceiling($iTotButtons / $iNumPerRow) * ($iButDepth + 10), -1, $WS_EX_TOPMOST) For $i = 0 To $iTotButtons - 1 ; $x = $iXBorder + (($iRectWidth + $iSpacing) * Mod($i, $iNumCols)) $x = 10 + (($iButWidth + 10) * Mod($i, $iNumPerRow)) ; $y = $iYBorder + (($iRectDepth + $iSpacing) * Int($i / $iNumCols)) $y = 10 + (($iButDepth + 10) * Int($i / $iNumPerRow)) $aButiD[$i] = GUICtrlCreateButton($aArray[$i][0], $x, $y, $iButWidth, $iButDepth) ;, $BS_NOTIFY) Next GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE GUIDelete($hGUI) ExitLoop Case $aButiD[0] To $aButiD[$iTotButtons - 1] ;clicking on a flavor name $iIndex = ($msg - $aButiD[0]) Global $RSINGRflavor = $aArray[$iIndex][0] ;flavor name Global $RSINGRml = $aArray[$iIndex][1] ; ml Global $RSINGRgal = $aArray[$iIndex][1]*0.000264172 ;converts ml to gal Call('openflavor') EndSwitch WEnd EndFunc Func openflavor() #Region ### START Koda GUI section ### Form=F:\Karl\AutoIt\FJ-Stock JP\GUI Forms\RSINGRSUBFORM.kxf ;opens flavor to view stock and restock submit $RSINGRSUBFORM = GUICreate($sSection & " " & $RSINGRflavor, 242, 213, 530, 269) $RSINGRFlavorTitle = GUICtrlCreateLabel($sSection & " " & $RSINGRflavor, 32, 8, 200, 28) GUICtrlSetFont(-1, 16, 800, 0, "MS Sans Serif") $RSINGRstockcaption = GUICtrlCreateLabel("Current Stock in ml:", 16, 48, 96, 17) $RSINGRstockml = GUICtrlCreateLabel($RSINGRml, 120, 48, 114, 25) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $RSINGRInput = GUICtrlCreateInput("ml", 40, 112, 153, 21) $RSINGRSUBMIT = GUICtrlCreateButton("SUBMIT", 16, 152, 81, 33) $RSINGRCLOSE = GUICtrlCreateButton("CLOSE", 145, 151, 81, 33) $RSINGRgalcaption = GUICtrlCreateLabel("Current Stock in gal:", 16, 80, 97, 17) $RSINGRstockgal = GUICtrlCreateLabel($RSINGRGAL, 120, 80, 114, 25) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### ; $msg = "" While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete($RSINGRSUBFORM) ExitLoop Case $RSINGRCLOSE GUIDelete($RSINGRSUBFORM) ExitLoop EndSwitch WEnd EndFunc Edited March 21, 2018 by kartune
Moderators JLogan3o13 Posted March 21, 2018 Moderators Posted March 21, 2018 Can you please provide an example of your test.ini? "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!
kartune Posted March 21, 2018 Author Posted March 21, 2018 2 minutes ago, JLogan3o13 said: Can you please provide an example of your test.ini? sure thing, here it is: [VG] ml=0 [PG] ml=0 [TPA] Apple Candy=100 Bavarian Cream=0 Berry Cereal=0 Blueberry=0 Citrus Punch=0 Clove=0 Coconut Extra=0 Energy Drink=0 Fruit Circles=0 Ginger Ale=0 Graham Cracker Clear=0 Hawaiian Drink=0 Honey Dew=0 Kiwi=0 Menthol=0 MType=0 Papaya=0 Peach=0 Peppermint=0 Ry4=0 Tiramisu=0 Toasted Almond=0 Tobacco=0 Vanilla Bean Ice Cream=0 Vanilla Swirl=0 Watermelon=0 Western=0 [JP] Condensed Milk=0 Garikun=0 Honey Dew=0 Kiwi=0 Matcha=0 Melon Cream Soda=0 Peach=0 Pineapple=0 Strawberry=0 Umeshu=0 Yogurt=0 MType=-0 [CAP] Honey Dew=0 Vanilla Custard=0 [FA] Fresh Cream=0 Meringue=0 Seven Leaves=0 Bavarian Cream=0 [INA] Biscuit=0 (Scroll Up)
Moderators JLogan3o13 Posted March 21, 2018 Moderators Posted March 21, 2018 Thanks, will take a look. In the future you could just attach a file, a lot easier than making someone save it off "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!
kartune Posted March 21, 2018 Author Posted March 21, 2018 Just now, JLogan3o13 said: Thanks, will take a look. In the future you could just attach a file, a lot easier than making someone save it off Thanks, i will remember that :), new to this forum and also coding. Most of my code is copy pasted and then edited.
Subz Posted March 21, 2018 Posted March 21, 2018 To read the button text you need to use: Global $flavorco = GUICtrlRead($Button[$i]) Then you can use $sSection = $Flavorco
kartune Posted March 21, 2018 Author Posted March 21, 2018 It works!!! Thanks a lot guys! I'm so grateful for this forum and the members
Subz Posted March 21, 2018 Posted March 21, 2018 No problem, overall code is quite good, Just a couple of pointers, regarding best practice for variables: You shouldn't declare Global variables within functions. Global variables should only be declared if being used between multiple functions (as JLogan pointed out above) Prefixing your variables helps with identifying the variable type see https://www.autoitscript.com/wiki/Best_coding_practices Quick Example: expandcollapse popup#include <Array.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $sSection Global $sFilePath = @ScriptDir & "\Test.ini" MainGui() Func MainGui() Local $aOptionBar = IniReadSectionNames($sFilePath) If @error Then Exit Local $aButton[$aOptionBar[0]] Local $hMainGui = GUICreate('Restock Flavor Ingredients', 10 + (130 * UBound($aOptionBar)), 100) For $i = 1 To $aOptionBar[0] IniReadSection("test.ini", $aOptionBar[$i]) If @error Then ContinueLoop $iX_Coord = 10 + (($i - 1) * 100) $aButton[$i - 1] = GUICtrlCreateButton($aOptionBar[$i], $iX_Coord, 30, 70, 30) Next GUISetState() While 1 $nMainMsg = GUIGetMsg() Switch $nMainMsg Case $GUI_EVENT_CLOSE GUIDelete($hMainGui) ExitLoop Case $aButton[0] To $aButton[UBound($aButton) - 1] $sSection = GUICtrlRead($nMainMsg) flavorco() ; flavor company EndSwitch WEnd EndFunc Func flavorco() ;opened flavor companys flavors Local $x, $y Local $aFlavors = IniReadSection($sFilePath, $sSection) _ArrayDelete($aFlavors, 0) Local $iIndex Local $iTotButtons = UBound($aFlavors) Local $iNumPerRow = 5 Local $iButWidth = 100 Local $iButDepth = 30 Local $aButiD[$iTotButtons] Local $hFlavors = GUICreate('Ingredients Stock "' & $sFilePath & '"', 10 + ($iButWidth + 10) * $iNumPerRow, 10 + Ceiling($iTotButtons / $iNumPerRow) * ($iButDepth + 10), -1, $WS_EX_TOPMOST) For $i = 0 To $iTotButtons - 1 $x = 10 + (($iButWidth + 10) * Mod($i, $iNumPerRow)) $y = 10 + (($iButDepth + 10) * Int($i / $iNumPerRow)) $aButiD[$i] = GUICtrlCreateButton($aFlavors[$i][0], $x, $y, $iButWidth, $iButDepth) Next GUISetState(@SW_SHOW) While 1 $nFlavorCoMsg = GUIGetMsg() Switch $nFlavorCoMsg Case $GUI_EVENT_CLOSE GUIDelete($hFlavors) ExitLoop Case $aButiD[0] To $aButiD[$iTotButtons - 1] ;clicking on a flavor name $iIndex = ($nFlavorCoMsg - $aButiD[0]) openflavor($aFlavors[$iIndex][0], $aFlavors[$iIndex][1], $aFlavors[$iIndex][1]*0.000264172) EndSwitch WEnd EndFunc Func openflavor($sRSINGRflavor, $iRSINGRml, $iRSINGRgal) #Region ### START Koda GUI section ### Form=F:\Karl\AutoIt\FJ-Stock JP\GUI Forms\RSINGRSUBFORM.kxf ;opens flavor to view stock and restock submit Local $nRSINGRmsg Local $hRSINGRSUBFORM = GUICreate($sSection & " " & $sRSINGRflavor, 242, 213, 530, 269) GUICtrlCreateLabel($sSection & " " & $sRSINGRflavor, 32, 8, 200, 28) GUICtrlSetFont(-1, 16, 800, 0, "MS Sans Serif") GUICtrlCreateLabel("Current Stock in ml:", 16, 48, 96, 17) GUICtrlCreateLabel($iRSINGRml, 120, 48, 114, 25) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") Local $idRSINGRInput = GUICtrlCreateInput("ml", 40, 112, 153, 21) Local $idRSINGRSUBMIT = GUICtrlCreateButton("SUBMIT", 16, 152, 81, 33) Local $idRSINGRCLOSE = GUICtrlCreateButton("CLOSE", 145, 151, 81, 33) GUICtrlCreateLabel("Current Stock in gal:", 16, 80, 97, 17) GUICtrlCreateLabel($iRSINGRgal, 120, 80, 114, 25) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") #EndRegion ### END Koda GUI section ### GUISetState(@SW_SHOW) While 1 $nRSINGRmsg = GUIGetMsg() Switch $nRSINGRmsg Case $GUI_EVENT_CLOSE, $idRSINGRCLOSE GUIDelete($hRSINGRSUBFORM) ExitLoop EndSwitch WEnd EndFunc
kartune Posted March 21, 2018 Author Posted March 21, 2018 Thank you! I am going to clean up my coding as I learn more and practice :).
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