Hackworth82 Posted March 22, 2016 Share Posted March 22, 2016 Hello. I just started learning AUTOIT. I am trying to loop thru an array and return something if an array element has a specific value. Here is my code: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <array.au3> Local $idRadio3Result3 = 45454 Local $idRadio3Result2 = 12 Local $idRadio3Result1 = 1 Local $aArrayOfRadioButtons[3] = [$idRadio3Result1, $idRadio3Result2, $idRadio3Result3] Local $control ;loop thru the array and find the element that has value of 1 For $i = 0 To UBound($aArrayOfRadioButtons) if $aArrayOfRadioButtons[$i] = 1 Then $control = $aArrayOfRadioButtons[i] ExitLoop EndIf When I run the script, this error appears in console: ...\Desktop\AutoIt\test1.au3" (14) : ==> Unknown function name.: $control = $aArrayOfRadioButtons[i] $control = $aArrayOfRadioButtons[^ ERROR >Exit code: 1 Time: 0.2284 The problem seems to be when I try to assign the value of the found element to the $control variable. I tested the code by replacing this line: $control = $aArrayOfRadioButtons[i] with a console log like this: ConsoleWrite("Test blabla") and it works. So it might be some syntax problem. Thanks for the help. Link to comment Share on other sites More sharing options...
Dgameman1 Posted March 22, 2016 Share Posted March 22, 2016 $control = $aArrayOfRadioButtons[$i] Forgot the $ sign in front of the i Hackworth82 1 Link to comment Share on other sites More sharing options...
Hackworth82 Posted March 22, 2016 Author Share Posted March 22, 2016 Btw, the 'Next' from the end of the first code posted did not copy from some reason, but it's there. Link to comment Share on other sites More sharing options...
Dgameman1 Posted March 23, 2016 Share Posted March 23, 2016 14 hours ago, Hackworth82 said: Btw, the 'Next' from the end of the first code posted did not copy from some reason, but it's there. So, does it work now? Hackworth82 1 Link to comment Share on other sites More sharing options...
Hackworth82 Posted March 23, 2016 Author Share Posted March 23, 2016 yes it does thank you Link to comment Share on other sites More sharing options...
Hackworth82 Posted March 23, 2016 Author Share Posted March 23, 2016 I have another question for you, or anyone here I am trying to create a GUI and the first task is to create a combo and a text input. In the combo user selects the partition and in the input the folder name. So my plan is to concatenate the two string in order to create a path so that i can create a folder. This is my code so far: expandcollapse popup; Create a GUI with various controls. Local $hGUI = GUICreate("Move stuff", 500, 500) ; Create OK button Local $idOK = GUICtrlCreateButton("OK", 400, 460, 85, 25) ; Create Cancel button Local $cancel = GUICtrlCreateButton("Cancel", 300, 460, 85, 25) ; The possible partitions we can create/copy to a folder Global $aArray[2] = ["C:\", "D:\"] ; Put the possible partitions into a list $sList = "" For $i = 0 To UBound($aArray) - 1 $sList &= "|" & $aArray[$i] Next ; Create a label for the combo Local $idlabelPartition = GUICtrlCreateLabel("Please select the partition you want to create the folder in:", 10, 20) ; Create the combo Local $hCombo = GUICtrlCreateCombo("", 10, 40, 200, 20) ; put the list elements into the combo GUICtrlSetData($hCombo, $sList) ; Create a label for the input field Local $idlabelFolder = GUICtrlCreateLabel("Please write the desired folder name:", 10, 70) ;create a text area where user can input the foldername Local $idText = GUICtrlCreateInput("", 10, 90, 300, 20) ; Create a button that when pressed will create the folder with the user inputed name and on the selected partition Local $createFolder = GUICtrlCreateButton("Create Folder", 10, 120, 100, 20) ; Define a variable that contains the path depending on the user selection Local $userPath = GUICtrlRead($hCombo) & GUICtrlRead($idText) ;<<< problem seems to be here. the GUICtrlRead($hCombo) and ;GUICtrlRead($idText) are strings but $userPath will not be the output of string concatenation ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idOK, $cancel ExitLoop Case $createFolder MsgBox(0, "", "The path to create a folder is: " & $userPath) ;<<< this does not return the concatenation, it returns nothing EndSwitch WEnd So the problem is that $userParh returns nothing. So please help if you can. Thx Florin Link to comment Share on other sites More sharing options...
mikell Posted March 23, 2016 Share Posted March 23, 2016 Just move this line Local $userPath = ... etc into the loop Case $createFolder $userPath = GUICtrlRead($hCombo) & GUICtrlRead($idText) MsgBox(0, "", "The path to create a folder is: " & $userPath) Hackworth82 1 Link to comment Share on other sites More sharing options...
Hackworth82 Posted March 23, 2016 Author Share Posted March 23, 2016 4 minutes ago, mikell said: Just move this line Local $userPath = ... etc into the loop Case $createFolder $userPath = GUICtrlRead($hCombo) & GUICtrlRead($idText) MsgBox(0, "", "The path to create a folder is: " & $userPath) wow. yeah, that was the problem. so why this behaviour ? Link to comment Share on other sites More sharing options...
mikell Posted March 23, 2016 Share Posted March 23, 2016 Because you must select the drive in the combo and write the folder name in the input before reading these data and building the path by pressing the $createfolder button Hackworth82 1 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