Jump to content

Recommended Posts

Posted

As painful as this has become... I've given up and I'm asking for help again... lol Smashing my head into the desk has become too obvious an answer. I have a gui that has a whole list of buttons where I need them to be clickable and initiate an action. My code is pretty simple - as am I - lol What should I have in my GuiSetState() portion of my program to make my buttons clickable? I've tried some "borrowed" Case For... Next statements in random Forum answers and just wound up nowhere. Sorry if this is the 100th time anyone has seen this.

Thanks in Advance - Props to AutoIT - Program is freakin' sweet!

Sites_links2.txt

site1

site2

site3

site4

#include <File.au3>
#include <GUIConstantsEx.au3>
Global $sites_array1

$file_path1 = "sites_links2.txt" ; file contains site names one line at a time. Site1 first line, Site2 second line, Site3...

If Not _FileReadToArray($file_path1, $sites_array1) Then
MsgBox(4096, "Error", " Error reading log to Array error:" & @error)
Exit
EndIf

MsgBox(0, "array", $sites_array1[0])
$test1 = $sites_array1[0]

$varStartHeight=0
$varStartHeight += 5
Local $Button [ $test1 + 1 ]

GUICreate("Test")

For $x = 1 To UBound($sites_array1) - 1
$Button[$x] = GUICtrlCreateButton($sites_array1[$x], 30, $varStartHeight, 55, 27)
$varStartHeight += 30
Next

GUISetState()
While 1
$msg=GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
EndSelect
WEnd

"Maybe I'm on a road that ain't been paved yet. And maybe I see a sign that ain't been made yet"
Song Title: I guess you could say
Artist: Middle Class Rut

  • Moderators
Posted

souldjer777,

I would do it like this: ;)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case Else
            For $i = 1 To UBound($sites_array1) - 1
                If $msg = $Button[$i] Then
                    MsgBox(0, "Pressed", GUICtrlRead($Button[$i]))
                    ExitLoop
                EndIf
            Next
    EndSelect
WEnd

Please ask if you have any questions. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)

While that works, sometimes there would be too many if's and endif's (I mean loops and conditions)

and it got hard to keep track of them so if that happens to you, try this:

Opt("GUIOnEventMode", 1)

$Var = GUICtrlCreateButton("ButtonText", 96, 34, 75, 25)
GUICtrlSetOnEvent($Var, "SomeFunction")

Func SomeFunction()
Sleep(100)
EndFunc
Edited by careca
  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted

Just wanted to say thanks - Melba23 ! Yes - you rock :guitar:

:ILA2:

"Maybe I'm on a road that ain't been paved yet. And maybe I see a sign that ain't been made yet"
Song Title: I guess you could say
Artist: Middle Class Rut

  • Moderators
Posted

souldjer777,

While I do not necessarily agree with careca's opinion that there could be "too many [...] loops and conditions", you might like to see why using OnEvent mode might be useful in this particular case: ;)

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

; Simulate reading file
Global $sites_array1[4] = [4, "Link 1", "Link 2", "Link 3"]

$test1 = $sites_array1[0]

$varStartHeight = 0
$varStartHeight += 5
Local $Button[$test1 + 1]

GUICreate("Test")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

For $x = 1 To UBound($sites_array1) - 1
    $Button[$x] = GUICtrlCreateButton($sites_array1[$x], 30, $varStartHeight, 55, 27)
    GUICtrlSetOnEvent(-1, "_Pressed")
    $varStartHeight += 30
Next

GUISetState()

While 1
    Sleep(10)
WEnd

Func _Pressed()
    MsgBox(0, "Pressed", GUICtrlRead(@GUI_CTRLID)) ; AutoIt tells you which button was pressed automatically
EndFunc

Func _Exit()
    Exit
EndFunc

It is a personal choice which mode to use - there are advantages and disadvantages to both. Just do not mix them in the same script - big alarm bells should go off if you find that you need to and recasting the code to use just the one is probably a better idea. :o

But you can use both if you take great care and only use one at a time - look in my ExtMsgBox UDF to see how it uses MessageLoop regardless of what mode the calling script is using, but then resets the original mode before returning. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

OnEventMode is useful if the GUI isn't of great importance to the application.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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.
×
×
  • Create New...