Jump to content

Problem to catch the press event on button to generate an event


Recommended Posts

Hi,

i'm tring to write a script with gui where have some input fields and one button and i would like to understand how to process the data entered into these fiels whene the button is pressed.

Many thnaks for any kind of suggestions.

Link to comment
Share on other sites

Hi,

i'm tring to write a script with gui where have some input fields and one button and i would like to understand how to process the data entered into these fiels whene the button is pressed.

Many thnaks for any kind of suggestions.

Welcome to AutoIt. :)

Open the help file and check out the example script under GuiGetMsg.

:(

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

hi,

first of all, thanks for your replay :)

I read it before post my request and I 've tried to insert the part of code into mine but with bad result.

if u can (and want) take a look on the code and give me an opinion on ... is will be very appreciate.

Regards

At end of code where there is the button creation I would like to insert a function which take the entered input , make the calculation and write down it on an other field.

<<<<<<<<<<<<<<<AutoIt CODE>>>>>>>>>>>>>>>>>

#include <GuiConstants.au3>

#include<ButtonConstants.au3>

; GUI

GuiCreate("Sample GUI", 400, 400)

GuiSetIcon(@SystemDir & "\calc.exe", 0)

; INPUT

;1 cent

$1cent=GuiCtrlCreateInput(10, 100, 0, 30, 20,$ES_NUMBER)

GuiCtrlCreateLabel("1 Cent", 50, 0)

$tot1cent = GUICtrlRead($1cent) * 1

;2 cent

$2cent=GUICtrlCreateInput("0", 100, 20, 30, 20,$ES_NUMBER)

GuiCtrlCreateLabel("2 Cent", 50, 20)

$tot2cent = GUICtrlRead($2cent) * 2

;5 cent

$5cent=GUICtrlCreateInput("0", 100, 40, 30, 20,$ES_NUMBER)

GuiCtrlCreateLabel("5 Cent", 50, 40)

$tot5cent = GUICtrlRead($5cent) * 5

;10 cent

$10cent=GUICtrlCreateInput("0", 100, 60, 30, 20,$ES_NUMBER)

GuiCtrlCreateLabel("10 Cent", 50, 60)

;20 cent

$20cent=GUICtrlCreateInput("0", 100, 80, 30, 20,$ES_NUMBER)

GuiCtrlCreateLabel("20 Cent", 50, 80)

;50 cent

$50cent=GUICtrlCreateInput("0", 100, 100, 30, 20,$ES_NUMBER)

GuiCtrlCreateLabel("50 Cent", 50, 100)

;1 euro

$1euro=GUICtrlCreateInput("0", 100, 120, 30, 20,$ES_NUMBER)

GuiCtrlCreateLabel("1 Euro", 50, 120)

;2 euro

$2euro=GUICtrlCreateInput("0", 100, 140, 30, 20,$ES_NUMBER)

GuiCtrlCreateLabel("2 Euro", 50, 140)

;5 euro

$5euro=GUICtrlCreateInput("0", 100, 160, 30, 20,$ES_NUMBER)

GuiCtrlCreateLabel("5 Euro", 50, 160)

;10 euro

$10euro=GUICtrlCreateInput("0", 100, 180, 30, 20,$ES_NUMBER)

GuiCtrlCreateLabel("10 Euro", 50, 180)

;20 euro

$20euro=GUICtrlCreateInput("0", 100, 200, 30, 20,$ES_NUMBER)

GuiCtrlCreateLabel("20 Euro", 50, 200)

;50 euro

$50euro=GUICtrlCreateInput("0", 100, 220, 30, 20,$ES_NUMBER)

GuiCtrlCreateLabel("50 Euro", 50, 220)

;100 euro

$100euro=GUICtrlCreateInput("0", 100, 240, 30, 20,$ES_NUMBER)

GuiCtrlCreateLabel("100 Euro", 50, 240)

;200 euro

$200euro=GUICtrlCreateInput("0", 100, 260, 30, 20,$ES_NUMBER)

GuiCtrlCreateLabel("200 Euro", 50, 260)

;500 euro

$500euro=GUICtrlCreateInput("0", 100, 280, 30, 20,$ES_NUMBER)

GuiCtrlCreateLabel("500 Euro", 50, 280)

;Bancomat

$Bancomat=GUICtrlCreateInput("0", 220, 0, 50, 20)

GuiCtrlCreateLabel("Bancomat", 150, 0)

;Carte Credito

$CC=GUICtrlCreateInput("0", 220, 20, 50, 20)

GuiCtrlCreateLabel("Carte di Credito", 140, 20)

;Fondo cassa

$FCassa=GUICtrlCreateInput("0", 220, 40, 30, 20,$ES_NUMBER)

GuiCtrlCreateLabel("Fondo Cassa", 140, 40)

;OUTPUT

; Totale Carte e Bancomat

GuiCtrlCreateLabel("TOT POS", 180, 80)

GUICtrlCreateInput(GUICtrlRead($Bancomat), 180, 100, 50, 20,$ES_READONLY)

; Totale Contanti

$tot_contanti=GuiCtrlCreateLabel("TOT CONTANTI", 180, 140)

GUICtrlCreateInput("0", 180, 160, 50, 20, $ES_READONLY)

; Totale Contanti meno fondo cassa

GuiCtrlCreateLabel("TOT - F CASSA", 180, 200)

GUICtrlCreateInput("0", 180, 220, 50, 20,$ES_READONLY)

; BUTTON

$calcola=GuiCtrlCreateButton("Calcola", 10, 330, 100, 30)

; GUI MESSAGE LOOP

GuiSetState()

While GuiGetMsg() <> $GUI_EVENT_CLOSE

WEnd

Link to comment
Share on other sites

Hi,

I solved it using an other way.

Just to let u understand wath I have done ....

<<<<<<<<<<<added it on code beginning>>>>>>>>>>>>>>

Opt("GUIOnEventMode",1)

<<<<<<<<<<<added on code bottom>>>>>>>>>>>>>

; BUTTON

$calcola=GuiCtrlCreateButton("Calcola", 10, 330, 100, 30)

GUICtrlSetOnEvent($calcola,"count")

$exit = GUICtrlCreateButton("Chiudi", 280, 330, 100, 30)

GUICtrlSetOnEvent($exit,"esci")

; GUI MESSAGE LOOP

GuiSetState()

While 1

Sleep (1000)

WEnd

;FUNCTIONS

Func count()

$tot1cent = GUICtrlRead($1cent) * 1 / 100

$tot2cent = GUICtrlRead($2cent) * 2 / 100

$tot5cent = GUICtrlRead($5cent) * 5 / 100

$tot10cent = GUICtrlRead($10cent) * 10 /100

$tot20cent = GUICtrlRead($20cent) * 20 / 100

$tot50cent = GUICtrlRead($50cent) * 50 / 100

$tot1euro = Guictrlread($1euro) * 1

$tot2euro = Guictrlread($2euro) * 2

$tot5euro = Guictrlread($5euro) * 5

$totcounteuro = $tot1euro + $tot2euro + $tot5euro + $tot10euro + $tot20euro + $tot50euro + $tot100euro + $tot200euro + $tot500euro

$totcountcent = $tot1cent + $tot2cent + $tot5cent + $tot10cent + $tot20cent + $tot50cent

$TOT_count_contanti = $totcounteuro + $totcountcent

;MsgBox(0,"tot contanti", $TOT_count_contanti) ;only debug

GUICtrlSetData($tot_contanti,$TOT_count_contanti)

GUICtrlSetData($tot_pos,GUICtrlRead($Bancomat)+GUICtrlRead($CC))

GUICtrlSetData($tot_contanti_meno_fcassa,$TOT_count_contanti - GUICtrlRead($FCassa))

EndFunc

Func esci()

if @GUI_CtrlId = $exit Then

MsgBox(1,"Uscita", "Sei sicuro di voler chiudere?")

Else

MsgBox(0,"You clicked on", "Close")

EndIf

Exit

EndFunc

Link to comment
Share on other sites

Glad to see you figured out a solution!

I prefer OnEvent mode too, especially for GUIs with lots of controls or complicated functions.

But just for your understanding, you original Gui Meesage Loop needed to be something like this:

; GUI MESSAGE LOOP
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Switch $msg 
        Case $GUI_EVENT_CLOSE
            ;jump to esci() function or put the esci code here
            ;example -
            MsgBox(0,"","You've closed the form")
            Exit
            
        Case $calcola 
            ;jump to count() function or put the count code here 
            ;example -
             msgBox(0,"","You pressed the calcola button")
    EndSwitch
WEnd
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...