Sign in to follow this  
Followers 0
IsmokeIdrank

Called Command Counter

12 posts in this topic

So I've got a script with multiple 'If' commands and I was wondering if there was a way to have my GUI display how many times each command is called. Not a necessity but something I'd like to add/learn and just wondering if it's possible :)

Share this post


Link to post
Share on other sites



Something like this could help you:

HotkeySet("{ESC}", "EndLoop")
Global $counter = 0

While 1
_DisplayName()
$counter = $counter + 1
WEnd

msgbox(64, "", "The name function was called " & $counter & "times.")

Func _DisplayName()
Msgbox(64, "Name", "MKISH. Press escape key when you are tired.")
EndFunc

Func EndLoop()
ExitLoop
EndFunc

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I'm trying to use a Label to state my amount of calls on the GUI but I can't seem to find a way to the counter to link with the Label to show how much it happened

example script:

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
global $wcounter = 0
$Display = GUICtrlCreatelabel("", 0,50)
If1
$wcounter = $wcounter + 1
     GUICtrlsetdata($display) = $Wcounter
endif1
Edited by IsmokeIdrank

Share this post


Link to post
Share on other sites

Your GUICtrlSetData line is written wrong, a script won't even run with it that way. It should be GUICtrlSetData($display, $Wcounter).


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

Your GUICtrlSetData line is written wrong, a script won't even run with it that way. It should be GUICtrlSetData($display, $Wcounter).

Ah terrible mistake, but even then I'm still not getting it to show up :/

Share this post


Link to post
Share on other sites

You'll need to post more of your script then, because that should update your label's contents. A small reproducer script that can be executed and that displays the problem you're having if you don't want to post all of your script.


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

You'll need to post more of your script then, because that should update your label's contents. A small reproducer script that can be executed and that displays the problem you're having if you don't want to post all of your script.

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <GDIPlus.au3>
global $wcounter = 1
$Display = GUICtrlCreatelabel("", 0,125)
$W = Guictrlcreatelabel("Windown",5,100)
GUISetState()
if pixelgetcolor(914,381) = 0x227994 Then
   mouseclick("left",1018,657)
   EndIf
   if pixelgetcolor(437,461) = 0xEBC97A Then
   mouseclick("left",755,767)
     $wcounter = $wcounter + 1
     GUICtrlsetdata($display, $Wcounter)
   EndIf

Share this post


Link to post
Share on other sites

That script won't do anything either, there's no GUI, and there's no way for it to stay active.


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

#9 ·  Posted (edited)

Sorry, here is my full script other than there being multiple If's but once I get one working I can set them all up

global $myGUI
global $paused
global $checkbox1
global $checkbox2
global $wcounter = 1
global $lcounter = 1
global $dcounter = 1
Local $B
HotKeySet("{ESC}", "Terminate")
$myGUI = GUIcreate("Testt",200,200,-1,-1,$WS_POPUPwindow)
$checkbox1 = GUICtrlCreateCheckbox(" ",50,170)
$checkbox2 = GUICtrlCreateCheckbox(" " ,135,170)
$WDisplay = GUICtrlCreatelabel("", 0,125)
$LDisplay = GUICtrlCreatelabel("", 100,125)
$DDisplay = GUICtrlCreatelabel("", 180,125)
$W = Guictrlcreatelabel("W",5,100)
$I = Guictrlcreatelabel("L",85,100)
$D = Guictrlcreatelabel("D",165,100)
$B = Guictrlcreatepic("C:\Program Files\AutoIt3\Examples\GUI\Logo.jpg",0,0,200,100)
$Check1 = Guictrlcreatelabel("Check1",35,155)
$Check2 = guictrlcreatelabel("Check2",128,155)
GUISetBkColor(0x000000)
GUIctrlsetcolor($w, 0xA98D77)
GUIctrlsetcolor($l, 0xA98D77)
GUIctrlsetcolor($d, 0xA98D77)
GUIctrlsetcolor($check1, 0xA98D77)
GUIctrlsetcolor($check2, 0xA98D77)
Guictrlsetcolor($WDisplay, 0xA98D77)
Guictrlsetcolor($LDisplay, 0xA98D77)
Guictrlsetcolor($DDisplay, 0xA98D77)
GUISetState()
if pixelgetcolor(914,381) = 0x227994 Then
mouseclick("left",1018,657)
EndIf
if pixelgetcolor(437,461) = 0xEBC97A Then
mouseclick("left",755,767)
     $wcounter = $wcounter + 1
     GUICtrlsetdata($display, $Wcounter)
EndIf
Edited by IsmokeIdrank

Share this post


Link to post
Share on other sites

It appears you've changed the variable name pointing to the label you want to update. Use $Wdisplay/$Ldisplay/$Ddisplay instead of just $display in the GUICtrlSetData line.


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

It appears you've changed the variable name pointing to the label you want to update. Use $Wdisplay/$Ldisplay/$Ddisplay instead of just $display in the GUICtrlSetData line.

ah that was a typo in my quoting, even then I can't get it to work :(

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Just wanted to update that I was foolishly expecting the value to update based off of the $wcounter's value being changed without thinking that maybe I should actually get the command to be called so it would replace $wdisplay. So to summarize:

Doing

; ##very cut version of the script##
global $Wcounter = 0
$Wdisplay = GUICtrlCreateLabel("0", 15, 190)

$wcounter = $wcounter + 1
GUICtrlsetdata($Wdisplay, $Wcounter)

will display the amount of times the command was called, for anybody who searches/googles a problem like this

Edited by IsmokeIdrank

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