Jump to content

Increment a value within a label upon button press

Recommended Posts

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)
$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)

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

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.

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.

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)
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.

  • Create New...