Jump to content

Looping thru an array using FOR statement - error: Unknown function name


Recommended Posts

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

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:

; 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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...