Jump to content

Checkboxes and assign and eval - in an array?


Recommended Posts

Hey Guys,

 

So, the functions work, where primarygui() accurately determines the evaluation of the status of the checkboxes - the msgbox picks this up.

 

However, later on, when we re-enter a 'for $i = 0 to ubound($checkbox)' loop, then in the 'batchinitial' function it doesn't picked up that the status&$i = 1, so it jumps out, then within the While 1 loop, it exits the loop in the first row, again because the status& $i= 0

The "assign" line within the primarygui funtion, is this only a local assignment? if so, how can I make it cross function?

 

Thank in adv for your help

 

 

Func excelsheetlist()
    $i = 0
    Global $aWorkSheets = _Excel_SheetList($oWorkbook1)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_SheetList Example 1", "Error listing Worksheets." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    ;_ArrayDisplay($aWorkSheets, "Excel UDF: _Excel_SheetList Example 1")

    ;_ArrayDisplay($aWorkSheets, "Array")
    Global $iRows = UBound($aWorkSheets, $UBOUND_ROWS) ; Total number of rows. In this example it will be 10.
    Global $iCols = UBound($aWorkSheets, $UBOUND_COLUMNS) ; Total number of columns. In this example it will be 20.
    Global $iDimension = UBound($aWorkSheets, $UBOUND_DIMENSIONS) ; The dimension of the array e.g. 1/2/3 dimensional.

    MsgBox($MB_SYSTEMMODAL, "", "The array is a " & $iDimension & " dimensional array with " & _
            $iRows & " row(s) & " & $iCols & " column(s).")

    Dim $checkbox[$iRows]

EndFunc   ;==>excelsheetlist

Func primarygui()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Script Controller", 300, ($iRows * 24))

    ; Create a checkbox control.
    ;Local $idCheckbox = GUICtrlCreateCheckbox("Standard Checkbox", 10, 10, 185, 25)
    Local $Button2 = GUICtrlCreateButton("Close", 210, 200, 85, 25)
    Local $Button3 = GUICtrlCreateButton("Run", 210, 170, 85, 25)
    Local $Button1 = GUICtrlCreateButton("Discharge", 210, 140, 85, 25)

    For $i = 0 To UBound($checkbox) - 1
        $checkbox[$i] = GUICtrlCreateCheckbox($aWorkSheets[$i][0], 8, 0 + ($i * 24)) ;, 81, 17)
    Next

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    ; Loop until the user exits.
    While 1
        $nMsg = GUIGetMsg()

        Select
            Case $nMsg = $GUI_EVENT_CLOSE
                Exit

            Case $nMsg = $Button2 ;Close

                Exit

            Case $nMsg = $Button1
                MsgBox(0, "Discharge Button not configured", "Now Exiting")
                Exit

            Case $nMsg = $Button3 ;Run

                $fSelection = False
                For $i = 0 To UBound($checkbox) - 1
                    If BitAND(GUICtrlRead($checkbox[$i]), $GUI_CHECKED) Then
                        $fSelection = True
                        ExitLoop
                    EndIf
                Next

                If $fSelection Then
                    For $i = 0 To UBound($checkbox) - 1
                        Assign("status" & $i, GUICtrlRead($checkbox[$i]))
                    Next
                    $batchcount = 0
                    For $i = 0 To UBound($checkbox) - 1
                        If Eval("status" & $i) = 1 Then
                            $batchcount = $batchcount + 1
                            ;Call ("o" & $i & "copy") ; if you want to call the functions directly, remove ; before the call and comment or delete the following DirCopy statement
                            MsgBox(0, "Checking", "Checking that: " & $checkbox[$i] & " no, with title: " & $aWorkSheets[$i][0] & " was selected, Batch count: " & $batchcount) ; if you need only the DirCopy
                        EndIf
                    Next
                    ExitLoop

                Else
                    MsgBox(48, 'No Items Selected', 'You have not selected any Patients to Load, Please select from the list')
                EndIf


        EndSelect

    WEnd


    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>primarygui

Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked


Func batchinitial()
    If Eval("status" & $i) = 1 Then
        debugbox()
        $oWorkbook1.Sheets(1).Activate
        $bigloop = $bigloop + 1
        $sheet = $aWorkSheets[$i][0]
        $oWorkbook1.Sheets($sheet).Activate
        debugbox()
    EndIf

EndFunc   ;==>batchinitial


OpenExcel()
excelsheetlist()
primarygui()

For $i = 0 To UBound($checkbox) - 1
    batchinitial()

    While 1
        If Eval("status" & $i) = 0 Then ExitLoop
            ;all the rest of my script loops etc
        
    WEnd


Next

 

Edited by MrCheese
Link to post
Share on other sites

Okay - so I added '2' at the end of "assign"

Assign("status" & $i, GUICtrlRead($checkbox[$i]), 2)

 

Now, it doesn't proceed past the 'batchinitial()' function:

Func batchinitial()
    If Eval("status" & $i) = 1 Then
        debugbox()
        $oWorkbook1.Sheets(1).Activate
        $bigloop = $bigloop + 1
        $sheet = $aWorkSheets[$i][0]
        $oWorkbook1.Sheets($sheet).Activate
        debugbox()
    EndIf
EndFunc   ;==>batchinitial

but it does proceed passed the if -> exitloop

For $i = 0 To UBound($checkbox) - 1
    batchinitial()

    While 1
        If Eval("status" & $i) = 0 Then ExitLoop

 

Which would suggest that the status$i value is neither 1 nor 0.

I inserted: Dim $status[0] at the top to see if that helped, but it didn't.

 

Any help would be great! 

Thanks

 

Edited by MrCheese
Link to post
Share on other sites

Do you have a script that compiles without errors? One thing that stands out is in the batchinitial function you specifiy 

If Eval("status" & $i) = 1 Then

But $i is local to primarygui.  You also specifiy 

$bigloop = $bigloop + 1

but $bigloop is not declared anywhere .

Normally, if adding lots of controls I'll use an array (as suggested by others in the post above) to keep a record of the ControlIDs . Then you can loop through this array to action the controls.

Edited by benners
Link to post
Share on other sites

yes - sorry, i removed the rest of the code, as the entire script is about 1500 lines long.

but yes, it compiles fine.

would it work if I move the gui stuff outside of the function into the main script?

Or should I use a different $i?

$i is used to initially run through a spreadsheet to create all the respective checkboxes on the GUI, then its used to determine which checkboxes have been checked, then it ideally documents, stores as "status0 = 1" if the first box is checked.

I thought that this 'assign' function would be global since I marked it as such. - or am I not understanding how it works?

 

edit: I have tested moving the GUI and batch initial out of their functions. It works if and only if i select the first checkbox i.e. status0,

if any of the others are selected, it doesn't pick up on this. indicating that I'm either prasing the Ifs wrong, or I don't have the eval right.

Edited by MrCheese
Link to post
Share on other sites

I don't know much about assign\eval\isdeclared  so my lack of knowledge makes me think they are evil :D, I normally find another way like an array.

Looking at the Assign statement, it just uses the default as the 3rd parameter, should this not be added to make it Global?.

That said,  with the line  "If Eval("status" & $i) = 1 Then",  if it was declared as Global such as, status0, The Eval should return an error as $i has no value so it should just be trying to return the value of "status".

I'm not experienced enough at look at code and pick out the issues, I normally need a runnable script to play with. Again I would try to use an array and condem the Assign\Eval usage to an early grave :evil:

Edited by benners
Link to post
Share on other sites

mmmm okay.

So, I should commit these values to an array, can I add them to an exisiting array;

by, replacing assign/eval here:

If $fSelection Then
                    For $i = 0 To UBound($checkbox) - 1
                        Assign("status" & $i, GUICtrlRead($checkbox[$i]), 2)
                    Next
                    $batchcount = 0
                    For $i = 0 To UBound($checkbox) - 1
                        If Eval("status" & $i) = 1 Then
                            $batchcount = $batchcount + 1
                            ;Call ("o" & $i & "copy") ; if you want to call the functions directly, remove ; before the call and comment or delete the following DirCopy statement
                            MsgBox(0, "Checking", "Checking that: " & $checkbox[$i] & " no, with title: " & $aWorkSheets[$i][0] & " was selected, Batch count: " & $batchcount & " / state: " & $i & " = " & $status[$i]) ; if you need only the DirCopy
                        EndIf
                    Next

 

can i commit the above into the previous array here:

Func excelsheetlist()
    $i = 0
    Global $aWorkSheets = _Excel_SheetList($oWorkbook1)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_SheetList Example 1", "Error listing Worksheets." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    ;_ArrayDisplay($aWorkSheets, "Excel UDF: _Excel_SheetList Example 1")

    ;_ArrayDisplay($aWorkSheets, "Array")
    Global $iRows = UBound($aWorkSheets, $UBOUND_ROWS) ; Total number of rows. In this example it will be 10.
    Global $iCols = UBound($aWorkSheets, $UBOUND_COLUMNS) ; Total number of columns. In this example it will be 20.
    Global $iDimension = UBound($aWorkSheets, $UBOUND_DIMENSIONS) ; The dimension of the array e.g. 1/2/3 dimensional.

    MsgBox($MB_SYSTEMMODAL, "", "The array is a " & $iDimension & " dimensional array with " & _
            $iRows & " row(s) & " & $iCols & " column(s).")

    Dim $checkbox[$iRows]

EndFunc   ;==>excelsheetlist

Or won't that work?

Link to post
Share on other sites

Okay - I can get the status into the array:  - code is below for those who might find this useful later on.

However, I'm getting the occasional error where the script just bombs out:

 

>Running:(3.3.14.2):C:\Users\25126209\Documents\autoit-v3-SciTE\autoit-v3\install\autoit3.exe "D:\scripts\PatientConversation_v0.7.au3"   

 

--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop

 

"D:\scripts\PatientConversation_v0.7.au3" (514) : ==> The requested action with this object has failed.:

 

$oWorkbook1.Sheets($sheet).Activate

 

$oWorkbook1^ ERROR

 

->17:15:34 AutoIt3.exe ended.rc:1

 

 

This refers to the $oWorkbook1.Sheets($sheet).Activate section below.

I also attempted to use $oWorkbook1.Sheets($i + 1).Activate, as this refers to the numbered row + 1 in the array that is referred to: if $aWorkSheets[$i][2] = 1

A few questions - i) how can I msgbox up if it fails here, and ii) how can I fix this?

ConvoL()
For $i = 0 To UBound($checkbox) - 1

    If $aWorkSheets[$i][2] = 1 Then

        $bigloop += $bigloop 
        $sheet = $aWorkSheets[$i][0]
        $oWorkbook1.Sheets($sheet).Activate

        While 1
            ttipscalc()
            reset()
            If $secondgo = False Then
                $run = $run + 1
                $ptno = $ptno + 1
            EndIf

            If $run > $ttlrun Then ExitLoop
            If $ptno > $ttlrun Then ExitLoop
            $row = $ptno + $rrdif
            If $restarttrigger = True Then
                ;restartpc()
            EndIf
            While 1
                Checkstatus()
                ;funcs etc etc
            WEnd
        WEnd
    EndIf

Next

 

EDIT:

I am also getting this error:

 

--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop

"D:\scripts\PatientConversation_v0.7.au3" (663) : ==> The requested action with this object has failed.:

$iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count

$iRowCount = .Range(^ ERROR

->17:44:19 AutoIt3.exe ended.rc:1

 

 

Which relates to - which is in the primary loop.

I ended up removing this, and just calling the array where this information had previously been stored:

$ttlrun = $aWorksheets[$i][3]

Func checkstatus()
    $msg = "Checking status"
    ttips()
    $column = $ptComment1
    Local $oRangeRead = _Excel_RangeRead($oWorkbook1, Default, $column & $row)
    If $oRangeRead = "Completed" Or $oRangeRead = "Completed - existing encounter" Then
        $exitloop = True
    EndIf
    ; **SCRIPT NEEDED** insert script to determine total number of rows

    With $oWorkbook1.ActiveSheet ; process active sheet
        $oRangeLast = .UsedRange.SpecialCells($xlCellTypeLastCell) ; get a Range that contains the last used cells
        $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count ; get the the row count for the range starting in row/column 1 and ending at the last used row/column
        $iLastCell = .Cells($iRowCount + 1, $columnfind).End($xlUp).Row ; start in the row following the last used row and move up to the first used cell in column "B" and grab this row number
        ;MsgBox(0, "", "Last used cell in column A: " & $iLastCell & @CRLF & "row count: " & $iRowCount)
    EndWith
    $ttlrun = $iRowCount - 1

EndFunc   ;==>checkstatus

 

scripts for info:

----- 

Func excelsheetlist()
    $i = 0
    Global $aWorkSheets = _Excel_SheetList($oWorkbook1)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_SheetList Example 1", "Error listing Worksheets." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    ;_ArrayDisplay($aWorkSheets, "Excel UDF: _Excel_SheetList Example 1")

    ;_ArrayDisplay($aWorkSheets, "Array")
    Global $iRows = UBound($aWorkSheets, $UBOUND_ROWS) ; Total number of rows. In this example it will be 10.
    Global $iCols = UBound($aWorkSheets, $UBOUND_COLUMNS) ; Total number of columns. In this example it will be 20.
    Global $iDimension = UBound($aWorkSheets, $UBOUND_DIMENSIONS) ; The dimension of the array e.g. 1/2/3 dimensional.

    MsgBox($MB_SYSTEMMODAL, "", "The array is a " & $iDimension & " dimensional array with " & _
            $iRows & " row(s) & " & $iCols & " column(s).")

    Dim $checkbox[$iRows]
    _ArrayColInsert($aWorkSheets, 2) ; added to create a new col

EndFunc   ;==>excelsheetlist
excelsheetlist()
;primarygui()

; Create a GUI with various controls.
Local $hGUI = GUICreate("Script Controller", 300, ($iRows * 24))

; Create a checkbox control.
;Local $idCheckbox = GUICtrlCreateCheckbox("Standard Checkbox", 10, 10, 185, 25)
Local $Button2 = GUICtrlCreateButton("Close", 210, 200, 85, 25)
Local $Button3 = GUICtrlCreateButton("Run", 210, 170, 85, 25)
Local $Button1 = GUICtrlCreateButton("Discharge", 210, 140, 85, 25)

For $i = 0 To UBound($checkbox) - 1
    $checkbox[$i] = GUICtrlCreateCheckbox($aWorkSheets[$i][0], 8, 0 + ($i * 24)) ;, 81, 17)
Next

; Display the GUI.
GUISetState(@SW_SHOW, $hGUI)

; Loop until the user exits.
While 1
    $nMsg = GUIGetMsg()

    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit

        Case $nMsg = $Button2 ;Close

            Exit

        Case $nMsg = $Button1
            MsgBox(0, "Discharge Button not configured", "Now Exiting")
            Exit

        Case $nMsg = $Button3 ;Run

            $fSelection = False
            For $i = 0 To UBound($checkbox) - 1
                If BitAND(GUICtrlRead($checkbox[$i]), $GUI_CHECKED) Then
                    $fSelection = True
                    ExitLoop
                EndIf
            Next

            If $fSelection Then

                $batchcount = 0
                For $i = 0 To UBound($checkbox) - 1
                    $sFill = GUICtrlRead($checkbox[$i])
                    $aWorkSheets[$i][2] = $sFill
                    $batchcount += (GUICtrlRead($i) = 1 ? 1 : 0)
                Next

                ExitLoop

            Else
                MsgBox(48, 'No Items Selected', 'You have not selected any Patients to Load, Please select from the list')
            EndIf


    EndSelect

WEnd


; Delete the previous GUI and all controls.
GUIDelete($hGUI)

 

 

 

Edited by MrCheese
Link to post
Share on other sites

Here is one way I would add the checkboxes to an array and the find out which ones are selected (code below). As mentioned It would be better to post a minimal script that does the basics and people can test, rather than snippets of code that are of no use to anyone. 

If the code is 1500 lines long, go through it and remove the stuff you don't need/use.

One example is the excelsheetlist function, Don't declare global variables inside functions. If it's only used in the function make it Local.

Global $iRows = UBound($aWorkSheets, $UBOUND_ROWS) ; Total number of rows. In this example it will be 10.
Global $iCols = UBound($aWorkSheets, $UBOUND_COLUMNS) ; Total number of columns. In this example it will be 20.
Global $iDimension = UBound($aWorkSheets, $UBOUND_DIMENSIONS) ; The dimension of the array e.g. 1/2/3 dimensional.

You only use the $iRows inside the function so make it local, and the other two aren't used anywhere I can see, (as there are only snippets posted)

#include <Excel.au3>
#include <GUIConstantsEx.au3>
#include <Array.au3>

Opt('GUIOnEventMode', 1)

; array for ther sheetnames
; returns a 2D array, we will use the 2nd column where the Object of the worksheet should be
; to hold the checkbox checked state
Global $as_SheetNames = Excel_GetSheetList() ; returns a 2D array,
If @error Then CloseProgram()

; array for the checkbox controlIDs
Global $aid_Checkboxes[UBound($as_SheetNames)]

DrawGUI()

While 1
    Sleep(50)
WEnd

Func CloseProgram()
    Exit
EndFunc   ;==>CloseProgram

; update the array when a checkbox is selected
Func Checkbox_Clicked()
    ; search the checkbox array and get the index of the clicked checkbox
    Local $i_Index = _ArraySearch($aid_Checkboxes, @GUI_CtrlId)

    ; update the sheets array with the checked state
    $as_SheetNames[$i_Index][1] = GUICtrlRead(@GUI_CtrlId)
EndFunc   ;==>Checkbox_Clicked

; get the sheet names
Func Excel_GetSheetList()
    Local $oExcel = _Excel_Open(False)
    If @error Then Return SetError(1, MsgBox(0, '_Excel_Open', 'Error: ' & @error), 0)

    Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\test.xlsx")
    If @error Then Return SetError(2, MsgBox(0, '_Excel_BookOpen', 'Error: ' & @error), 0)

    Local $aWorkSheets = _Excel_SheetList($oWorkbook)
    If @error Then Return SetError(2, MsgBox(0, '_Excel_SheetList', 'Error: ' & @error), 0)

    _Excel_Close($oExcel)

    If Not IsArray($aWorkSheets) Then Return SetError(4, MsgBox(0, '$aWorkSheets', 'Unable to get worksheet names'), 0)

    Return $aWorkSheets
EndFunc   ;==>Excel_GetSheetList

; draw the gui
Func DrawGUI()
    GUICreate("test", 200, 200, 1026, 420)
    GUISetOnEvent($GUI_EVENT_CLOSE, 'CloseProgram')

    GUICtrlCreateButton("Open Sheets", 10, 150, 90, 25)
    GUICtrlSetOnEvent(-1, 'GetChecked_BtnClicked')

    For $i = 0 To UBound($as_SheetNames) - 1
        $aid_Checkboxes[$i] = GUICtrlCreateCheckbox($as_SheetNames[$i][0], 8, 10 + ($i * 24))
        GUICtrlSetOnEvent(-1, 'Checkbox_Clicked')
    Next

    GUISetState()
EndFunc   ;==>DrawGUI

; get the selected checkboxes
Func GetChecked_BtnClicked()
    ; find all the selected checkboxes
    Local $ai_Selected = _ArrayFindAll($as_SheetNames, $GUI_CHECKED, 0, 0, 0, 0, 1)
    If Not IsArray($ai_Selected) Then Return MsgBox(0, 'No Results', 'No check boxes were selected')

    Local $oExcel = _Excel_Open()
    If @error Then Return SetError(1, MsgBox(0, '_Excel_Open', 'Error: ' & @error), 0)

    Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\test.xlsx")
    If @error Then Return SetError(2, MsgBox(0, '_Excel_BookOpen', 'Error: ' & @error), 0)

    For $i = 0 To UBound($ai_Selected) - 1
        ; activate the sheet
        $oWorkbook.Sheets($as_SheetNames[$ai_Selected[$i]][0]).Activate
        Sleep(2000)
    Next

    _Excel_Close($oExcel, True, True)
EndFunc   ;==>GetChecked_BtnClicked

 

test.xlsx

Link to post
Share on other sites

Hi - thanks for your reply, I can see how you've improved the flow and the functions. I'll see what I can incorporate. 

Yeah, I see your point, Just most (~90%) of the script is utilised, and some of the content is commercially sensitive. makes pulling that out tricky.

I should be able to simulate my issues in a more simple script and then copy them here.

Link to post
Share on other sites

No problem.  If you post a file (like a spreadsheet) it doesn't need to be the one you use, just one that mimics it so function can be tested. It makes it easier to produce errors as it might run error free on one persons machine but no on another.

Link to post
Share on other sites

In this component:

For $i = 0 To UBound($ai_Selected) - 1
        ; activate the sheet
        $oWorkbook.Sheets($as_SheetNames[$ai_Selected[$i]][0]).Activate
        Sleep(2000)
    Next

 

Compared to mine below, the primary point of difference is that you avoid the need for the if statement as you have already extracted the active checkboxes?

For $i = 0 To UBound($checkbox) - 1 ; loops through the checkboxes

    If $aWorkSheets[$i][2] = 1 Then ; reads where in the array is stored if the checkbox is checked
        $sheet = $aWorkSheets[$i][0] ; sheet name is located here
        $oWorkbook1.Sheets($sheet).Activate ; activated based on sheet name
        
        ;blar blar blar
        
    endif
  next

 

The Sheet.activate component is giving me the odd failure - but more so on one laptop then another. Same vr of WIn and Office.

Link to post
Share on other sites

No idea why that would be. If your method is OK just use that. The sleep is only to wait so you can see the sheets being selected or Excel would just flash up and close. It wouldn't be needed in your script.

I have had a few blips with the Excel UDF as well but have never been able to reproduce enough to get info

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By NassauSky
      Hi all,
      The more projects I work on, the harder it is to find old scripts I created with certain techniques in them. I'd like to leave this here for others to get an idea from and it will be available now by keyword searching in this forum.
      This project needed an evenly distributed button grid setup on a touch screen with half decent sized buttons and spacing so the user would be less likely to press the key beside it. Here is one quick example to give anyone an idea of a way to handle it.
      #include <GUIConstants.au3> GUICreate("Button Grid", 1080, 100) ; will create a dialog box that when displayed is centered GUISetState(@SW_SHOW) ; will display an empty dialog box ;--Create and Position Controls Dim $btnActivated[1][2] ;Col 1 is button id, Col 2 is True/False used in 1 example as depressed Dim $btnArray[100][2] ;Col 1 is button id, Col 2 is True/False used in 1 example as depressed $num = 0 $btnActivated[0][0] = GUICtrlCreateButton("Activated", 0, 0, 100, 100) ;x,y,w,h $btnActivated[0][1] = True GUICtrlSetBkColor(-1,0x00ff00) GUICtrlSetColor(-1,0x005500) GUICtrlSetFont(-1,14) For $Y = 0 To 1 For $X = 0 To 7 ConsoleWrite( ($X * 100) + ($X*20) + 120 & @CRLF) If $Y=0 Then $btnArray[$num][0] = GUICtrlCreateButton($num + 1, ($X * 100) + ($X*20) + 120, 0, 100, 40) ;x,y,w,h Else $btnArray[$num][0] = GUICtrlCreateButton($num + 1, ($X * 100) + ($X*20) + 120, ($Y * 40) + $Y*20, 100, 40) ;x,y,w,h EndIf GUICtrlSetBkColor($btnArray[$num][0], 0xFFFFFF) $num += 1 Next Next ;--Set Button Names GUICtrlSetData($btnArray[0][0],"Autoit") GUICtrlSetData($btnArray[1][0],"Is") GUICtrlSetData($btnArray[2][0],"Cool") ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case $btnActivated[0][0] $btnActivated[0][1] = NOT $btnActivated[0][1] If $btnActivated[0][1] Then GUICtrlSetBkColor($btnActivated[0][0],0x00ff00) GUICtrlSetColor($btnActivated[0][0],0x005500) GUICtrlSetData($btnActivated[0][0],"Activated") GUICtrlSetFont($btnActivated[0][0],14) Else GUICtrlSetBkColor($btnActivated[0][0],0xFF9999) GUICtrlSetColor($btnActivated[0][0],0x550000) GUICtrlSetData($btnActivated[0][0],"DeActivated") GUICtrlSetFont($btnActivated[0][0],13) EndIf Case $btnArray[0][0] If $btnActivated[0][1] Then MsgBox(0,"Notice","Btn1",1) EndIf Case $btnArray[1][0] If $btnActivated[0][1] Then MsgBox(0,"Notice","Btn2",1) EndIf Case $btnArray[2][0] If $btnActivated[0][1] Then MsgBox(0,"Notice","Btn3",1) EndIf EndSwitch WEnd I couldn't find one of my old projects that broke the button array into more columns that included the actual button name in the field. Feel free to share your own or share a more flexible version of this simple example.

    • By TheAlienDoctor
      Hi, I was looking into creating a script that would detect if a file exists, then move it (and in some cases rename it, depending on the file) as well as write to a log file.
      The issue is, there is a lot of files that need to be moved, sometimes some files will exist and others won't depending on the use-case. However if a file does exist, it will always be going into the same directory with the same name.
      Currently I have an array nested inside of the array, with each array inside that array having both the old and new directory, and then a For loop to actually run through and do the file transferring. The issue I am having is how to call the Array inside of the array, because how do I specify  which the old directory is and which the new is?
      Global $FileTransfer[2000] = [Global $Dir1[2] = ["original dir 1", "new dir 1"], Global $Dir2[2] = ["original dir 2", "new dir 2"]] For $FileTransfer = [0] To [1] Step +1 If FileExists({original dir}) Then FileMove({original dir}, new dir, 1) FileOpen("log.latest.txt", 1) FileWrite("log.latest.txt", "{original dir} found, moved it to new dir." & @CRLF) FileClose("log.latest.txt") Else FileOpen("log_latest.txt", 1) FileWrite("log_latest.txt", "{original dir} not found, ignoreing it." & @CRLF) FileClose("log_latest.txt") EndIf Next I have put what I want the old and new directory to be for each array in {}, so hopefully its easier to tell which part is working and whats not.

      I am still reasonably new to AutoIT, any help is appreciated. Thankyou
    • By It_is_me_Me
      I am making some GUI with combobox for the Baudrates communications and I listed 9600, 57600, 115200. 
      I wrote the code to be defaulted to 57600 like this:
      GUICtrlSetData($comboBox_opticalBaudRate, "9600|57600|115200", "57600")
      But I wanted the GUI to remember the last item the user picks so the baudrates will NOT be defaulted to 57600.
      Example, I pick 9600 as my baudrates, then I close the GUI, after opening it, it always prompt 57600 since that is what I did in my code. But I want that if I choose 9600 and close the GUI, opening it again will show 9600 now instead of 57600.
      Is there a way to do it in GUI setting?
       
      Thanks.
    • By arunkw
      I have a spreadsheet - daily routine which has two columns: activity and time as shown here
      | Activity             | Time     | |----------------------|----------| | Sleep               |  6:00 am | | Toilet              |  6:15 am | | Get ready for gym  |  6:30 am | | Exercise            |  7:50 am | | ... more things      |  9:00 pm | | ... still more       | 10:45 pm | | Sleep               |  6:00 am |   I wanted to find out, say in C1 which activity is current for me using now() I.e., if it’s 6:45am on my watch, it should show me Exercise  in C1 Thanks to Adam D. PE, this formula works like magic to get the result =VLOOKUP(MOD(NOW(),1),{B2:B,A2:A},2,1)   Now, I want to reproduce same result in autoit, how to do that? To have easy solution say, I copy-paste spreadsheet data in array directly in code, right? Use for loop and run the above vlookup function and show the answer using tooltip. How to achieve this? please help.  
    • By ashraful089
      #include <ButtonConstants.au3>
      #include <ComboConstants.au3>
      #include <GUIConstantsEx.au3>
      #include <WindowsConstants.au3>
      #Region ### START Koda GUI section ### Form=C:\Users\Engr. Ashraful\Videos\koda_1.7.3.0\Forms\ProgramPlayer\FormProgamToOpen.kxf
      $FormInput = GUICreate("Input", 302, 205, 454, 285)
      $Resolution = GUICtrlCreateCombo("Resolution", 80, 24, 145, 25)
      GUICtrlSetData(-1, "1920|VM1920|1366")
      $ComboProgramType = GUICtrlCreateCombo("Program Type Selection", 80, 64, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
      GUICtrlSetData(-1, "Multimedia|Official|Design|Web")
      $ButtonEnter = GUICtrlCreateButton("Enter", 104, 104, 75, 25)
      GUISetState(@SW_SHOW)
      #EndRegion ### END Koda GUI section ###
      While 1
          $nMsg = GUIGetMsg()
          Switch $nMsg
              Case $GUI_EVENT_CLOSE
                  Exit
          EndSwitch
      WEnd
       
      please help me to read combo box input and use the value for another function/ work
       
×
×
  • Create New...