Sign in to follow this  
Followers 0
Ryanz

Increment a value within a label upon button press

7 posts in this topic

I'm a newbie to this whole AutoIt scripting thing, so I apologize for my amatuer code, but in a nutshell here is my problem: I have a variable ($iCounter) that is an integer that starts at 0. Whenever the user pushes a button ($hButtonCount) I want it to increment that value and have it displayed within a label ($hCountLabel) . As the code stands currently, pushing the button does nothing to the variable. This is my code:

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <GuiButton.au3>
#include <ButtonConstants.au3>
$iCounter = 0
$hRyanzGUI = GUICreate("Ryanz Test GUI", 500, 400)
$hBackGroundPic = GUICtrlCreatePic("C:\...\RyanzBackGround.jpg",0,0,0,0)
GuiCtrlSetState(-1,$GUI_DISABLE)
$hLogo = GUICtrlCreatePic("D:\...\RyanzAvatardFoH.jpg", 390, 290, 100, 100)
$hButton = GUICtrlCreateButton ("Don't Press This", 100, 100, 300, 200, $BS_BITMAP)
;GUICtrlSetImage($hButton, "C:\...\RyanzButton.bmp")
$hButtonCount = GUICtrlCreateButton ("Counter", 20, 340, 60, 40)
$hCountLabel = GUICtrlCreateLabel ("Counter total: " & $iCounter, 90, 350)
$hLabel = GUICtrlCreateLabel ("Welcome to Ryanz super complicated GUI interface.  Try not to click on the wrong button.", 30, 30)
GUISetState(@SW_SHOW)

While 1
  
   $nMsg = GUIGetMsg()
   Switch $nMsg
Case $hButton
   MsgBox (0, "!!!!!!!!!!!!!!!!!!!", "WTF ARE YOU DOING?!?!?!?")
Case $GUI_EVENT_CLOSE
   Exit
Case $hButtonCount
   $iCounter = $iCounter + 1
  
   EndSwitch
WEnd

Any help would be greatly appreciated. This GUI I'm creating isn't anything important, it's just a project to get my feet wet and start becomming familiar with the code. Thanks in advance for any help.

Share this post


Link to post
Share on other sites



I believe GUICtrlSetData is what you need.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

I believe GUICtrlSetData is what you need.

I tried it and I couldn't implement it correctly.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

It's kind of hard to help you with your code if you don't post what you tried to use.

But really, for GUICtrlSetData? It should be something like:

GUICtrlSetData($hCountLabel, "Counter total: " & $iCounter)
Edited by lark

Share this post


Link to post
Share on other sites

It's kind of hard to help you with your code if you don't post what you tried to use.

But really, for GUICtrlSetData? It should be something like:

GUICtrlSetData($hCountLabel, "Counter total: " & $iCounter)

Okay so I tried:

GUICtrlSetData($hCountLabel, "Counter total: " & $iCounter = $iCounter + 1)

and it just makes the label say "False" once I push the button.

Then I tried:

GUICtrlSetData($hCountLabel, "Counter total: " & $iCounter + 1)

and this will increment the variable to 1 after pushing the button, and will not go beyond that.

Share this post


Link to post
Share on other sites

It seems as if you took away the part $iCounter += 1. When you do

GUICtrlSetData($hCountLabel, "Counter total: " & $iCounter + 1)

that does not change the value stored in the variable. That just takes the value stored inside the variable, adds 1 to it, and displays that. You need to do:

$iCounter += 1
GUICtrlSetData($hCountLabel, "Counter total: " & $iCounter)

Share this post


Link to post
Share on other sites

Woohoo! Thanks, you've fixed the problem. Thanks a lot! :]

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