Sign in to follow this  
Followers 0
quantum900

Help with buttons in multidimensional array

19 posts in this topic

Hello all,

I am having some issues with buttons and click response.

I have a mysql database that I am querying, my script then creates several tabs with specific users on each tab.

The buttons I am creating are in an multidim. array, i.e. $tabButton[<tab>][<user>]

THis is all redering fine, and I know the buttons work if I statically look for them, but what I need is to keep this dynamic.

I tried this:

Case $tabButton[1][1] To $tabButton[UBound($tabButton)-1][UBound($tabButton,2)-1]



MsgBox(4096, "Clicked", "Something was clicked...")

And all that happens is I am contantly barraged with these boxes without the button being clicked.

Also, I should note that my script does have a function that runs every 5-ish seconds refreshing the user status. (This script works great and only changes the user status and does not have any affect on the button).

Any assistance would be appreciated, I have been hittong my head on the wall for a while now.

Here is the full While code:

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Exit

Exit

Case $tabButton[1][1] To $tabButton[UBound($tabButton)-1][UBound($tabButton,2)-1]

MsgBox(4096, "Clicked", "Somethign was clicked...")

EndSwitch

WEnd

Thank you !

Share this post


Link to post
Share on other sites



Do I understand you correct that you get

MsgBox(4096, "Clicked", "Somethign was clicked...")
without clicking on any button?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Water, thank you for your reply, yes without clicking on anything, as soon as the GUI loads the Message box repeatedly pops up until I kill the execution of the script.

Share this post


Link to post
Share on other sites

The array you created holds the IDs of the GUI controls. IIRC this is just an integer starting with 1.

Please have a look at the help file for GuiGetMsg. There are many more events the are returned (MouseMove etc.).

Try

$aEvents = GUIGetMsg(1)
to get extended information about the event.

You have to ignore all events not caused by a click on a control.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Water,

I do understand that it just returns the event. If I say had this:

Case $tabButton[1][3]

MsgBox(4096, "Test", "This is a test")

Then it does work if I click that specific button, but I want it to "listen" for any button, and with the:

Case $tabButton[0][0] to $tabButton[Ubound($tabButton)][Ubound($tabButton,2)]

MsgBox(4096, "Test", "This is a test")

It then just goes wild.

Share this post


Link to post
Share on other sites

The events mentioned in the help file give you negative values.

Can you display the content of the array before you start the loop?

_ArrayDisplay($tabButton)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Exit
        Exit
    Case
        $tabButton[1][1] To $tabButton[UBound($tabButton)-1][UBound($tabButton,2)-1]
        MsgBox(4096, "Clicked", "Somethign was clicked...")
    EndSwitch
WEnd

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Water,

Yes, I did use the display array to see that it was populated with ID's:

Output:

[0]|8|11|14|17|20

[1]|24||||

[2]|28|31|||

[3]|35|38|||

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I think I need to clarify, as i was trying several different ways to get this....

If I use

Case $tabButton[0][0] to $tabButton[Ubound($tabButton)][Ubound($tabButton,2)]
(starting [0][0]) then nothing happens, if I start [1][1] then it just starts popping up windows with no user input Edited by quantum900

Share this post


Link to post
Share on other sites

Sounds like one of the array elements contains a zero.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Well, yes as you can see there are some "tabs" that have more "users" than other tabs, so there will be some cells within the array that are empty. Is this the problem?

Share this post


Link to post
Share on other sites

Yes it's a problem because GUIGetMsg returns 0 if no controls are being activated, so as soon as nothing is happening, the Switch command finds the zero and acts on it.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

BrewManNh,

Thank you so much for that insight! Do you have any suggestions? What if I were to step through that array and set any empty cells to a negative number? (Negative to avoid any potential conflicts)

Thanks again!

Share this post


Link to post
Share on other sites

Ok,

So I added a step through to set any cell that is empty to -2 as seen here by the output of arraydisplay:

[0]|8|11|14|17|20

[1]|24|-2|-2|-2|-2

[2]|28|31|-2|-2|-2

[3]|35|38|-2|-2|-2

I tried the code both starting [0][0] and [1][1]. Now, I do not have the windows popping up unexpectedly, but I get nothing when I click on the buttons.

Any other suggestions?

Thanks in advance!

Share this post


Link to post
Share on other sites

Can you post a reproducer script that demonstrates what you're doing (without the MySQL part) and that also demonstrates what's not working correctly?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Ok, here is the basic version of what I am trying to do....

$Tab1 = GUICtrlCreateTab(0, 0, 697, 449)

; I call to this function to create my interface, including my buttons

func display_tab($gname,$gid,$co_id,$array)

$tab_name=myDecrypt($gname)

GUICtrlCreateTabItem($tab_name)

for $i = 0 to $my_array_num-1

$label[$array][$i] = GUICtrlCreateLabel($client_name[$i], 5, $start, 120, 24, $SS_SUNKEN,$SS_CENTER)

GUICtrlSetFont(-1, 11, 800, 0, "MS Sans Serif")

if $my_status[$i] = 0 Then

GUICtrlSetBkColor(-1, 0xff0000)

$my_button="In"

Else

GUICtrlSetBkColor(-1, 0x00ff00)

$my_button="Out"

EndIf

$tabButton[$array][$i] = GUICtrlCreateButton($my_button, 127, $start, 50, 25)

$notesLabel[$array][$i] = GUICtrlCreateLabel($myNotes[$i], 180, $start, 300, 24, $SS_SUNKEN,$SS_CENTER)

GUICtrlSetFont(-1, 11, 800, 0, "MS Sans Serif")

GUICtrlSetBkColor(-1, 0xffffff)

$start = $start + 25



if UBound($label,2) < $my_array_num Then

ReDim $label[UBound($label)][UBound($label,2) + 1]

EndIf

if UBound($tabButton,2) < $my_array_num Then

ReDim $tabButton[UBound($tabButton)][UBound($tabButton,2) + 1]

EndIf

if UBound($notesLabel,2) < $my_array_num Then

ReDim $notesLabel[UBound($notesLabel)][UBound($notesLabel,2) + 1]

EndIf

Next

EndFunc



Global $label[$array_num+1][2]

Global $tabButton[$array_num+1][1]

Global $notesLabel[$array_num+1][1]



; This is where I step through to put a value into any empty cells

for $j = 0 to Ubound($tabButton)-1

for $k = 0 to Ubound($tabButton,2)-1

if $tabButton[$j][$k] = "" Then

$tabButton[$j][$k]=1

EndIf

Next

Next



GUICtrlSetState(-1,$GUI_SHOW)

GUICtrlCreateTabItem("")



While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Exit

Exit

Case $tabButton[0][0] To $tabButton[UBound($tabButton)-1][UBound($tabButton,2)-1]

MsgBox(4096, "Clicked", "Something was clicked...")

EndSwitch

WEnd

Everything in the script is working well, except I need to be able to determine when a button was clicked to perform an action. Right now with the code as is, I click on a button and nothing happens. The code for the "listen" is the line:

Case $tabButton[0][0] To $tabButton[UBound($tabButton)-1][UBound($tabButton,2)-1]

This is not the entire script, as the call to the function that creates the buttons is not included, but this gives an overal simplified look at what I am doing.

Thanks for any assistance!

Edited by quantum900

Share this post


Link to post
Share on other sites

Unfortunately we can't run this script. A reproducer script should be a stripped down but executable script that shows the behaviour in error without the overhead of unneeded functions.

Can you add all missing functions and variables?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Water & BrewManNH,

I thank the both of you VERY much for your assistance and pointing me to errors. I thought through it and finally decided that I was trying to make things WAY more complicated than they needed to be. My solution was to eliminate the Multidimensional array and build a 1d array of the buttons. Once I did this, things started to work.

So again, thank you for your assistance! I woudl still be beating my head against a wall if it wasn't for you two. I apologize for not puting an executable version of the script up here for you testing, it was during the building of this script for you that I decided to try the 1d array version and got things working.

Share this post


Link to post
Share on other sites

That's usually how it works, you try to recreate it in another (smaller) script and see where you went wrong.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Glad the problem could be solved in a combined effort! That's what the forum is made for :D


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


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
Sign in to follow this  
Followers 0