Jump to content

GUI beginner attempt, cash register


Recommended Posts

Hi guys, I am a true beginner at programming at all.
 
After watching several tutorials, I realised that many nice things could be done with AutoIt.
 
I am currently attempting to make a script for a cash register, for printing bills.
 
The reason is simple, we have a family company, we produce, sell, and give many tourist services. 
 
I will paste the script I'm working on, but just to say in advance I successfully made a programm to open automatically Open Office Writer, and type specific information on certain place.
 
But I'm struggling with Autoit, because whenever I go google and search for specific problem and example, 10 new things appear... :(
 
So, here's the script I came so far at (I guess you can copy paste and run, to try it out and see where I'm wrong), and I don't understand 3 things:
 
1. $ans - is it automatically what I do (keyboard, mouse) after the GUI is set up ?
2. How to make font Comic sans global ?
3. What is the meaning of this function: Opt("GUICoordMode",2) ?
 
 
Le script: 

Local $font = "Comic Sans MS"

GUICreate("Articles", 975, 635, 500, 100) ;==> crta GUI
GUISetFont(20, 400, "", $font)
$ware_1 = GUICtrlCreateButton("Product 1", 5, 5, 250, 100)
$ware_2 = GUICtrlCreateButton("Product 2", 5, 110, 250, 100)
$ware_3 = GUICtrlCreateButton("Product 3", 5, 215, 250, 100)
$ware_4 = GUICtrlCreateButton("Product 4", 5, 320, 250, 100)
$ware_5 = GUICtrlCreateButton("Product 5", 5, 425, 250, 100)
$ware_6 = GUICtrlCreateButton("Product 6", 5, 530, 250, 100)
$ware_7 = GUICtrlCreateButton("Product 7", 260, 5, 250, 100)
$ware_8 = GUICtrlCreateButton("Product 8", 260, 110, 250, 100)
$ware_9 = GUICtrlCreateButton("Product 9", 260, 215, 250, 100)
$ware_10 = GUICtrlCreateButton("Product 10", 260, 320, 250, 100)
$ware_11 = GUICtrlCreateButton("Product 11", 260, 425, 250, 100)
$ware_12 = GUICtrlCreateButton("Product 12", 260, 530, 250, 100)
$ware_13 = GUICtrlCreateButton("Product 13", 515, 5, 250, 100)
$ware_14 = GUICtrlCreateButton("Product 14", 515, 110, 250, 100)
$ware_15 = GUICtrlCreateButton("Product 15", 515, 215, 250, 100)
$ware_16 = GUICtrlCreateButton("Product 16", 515, 320, 250, 100)
$ware_17 = GUICtrlCreateButton("Product 17", 515, 425, 250, 100)
$ware_18 = GUICtrlCreateButton("Product 18", 515, 530, 250, 100)
$Kraj = GUICtrlCreateButton("Finish", 770, 5, 200, 625)
GUISetState() ;==> shows GUI

While 1
    $msg = GUIGetMsg() ;==> proves GUI
    Select
        Case $msg = $ware_1
            $quantity_1 = InputBox("", "Quantity", "", "", 500, 250, 500, 200, "", "")
            $ans = MsgBox(4, "", "You chose an article: Product 1, and quantity: " & $quantity_1)
            Select
                Case $ans = 6
                    $var = "YES"
                Case $ans = 7
                    $var = "NO"
                Case $ans = 2 ; ==> only if there is cancel
                    Exit
            EndSelect
            ; ==> MsgBox(0, "AutoIt", $ans)
        Case $msg = $Kraj
            Exit
        Case $msg = -3 ; 3 = little cross (close)
            Exit
    EndSelect

WEnd

 

Edited by Melba23
Added code tags

YES, I know I ask facepalm questions.

YES, I know you asked the God why I had to register to the forum where normal people are.

YES, I know everything!

Link to comment
Share on other sites

welcome to autoit.

first post in autoit tags, please.

.

GUICreate ("Articles", 975, 635, 500, 100) ;==> crta GUI
Local $font
$font = "Comic Sans MS"
GUISetFont (20, 400, "", $font)
$ware_1 =  GUICtrlCreateButton  ("Product 1",    5,   5, 250, 100)
$ware_2 =  GUICtrlCreateButton  ("Product 2",    5, 110, 250, 100)
$ware_3 =  GUICtrlCreateButton  ("Product 3",    5, 215, 250, 100)
$ware_4 =  GUICtrlCreateButton  ("Product 4",    5, 320, 250, 100)
$ware_5 =  GUICtrlCreateButton  ("Product 5",    5, 425, 250, 100)
$ware_6 =  GUICtrlCreateButton  ("Product 6",    5, 530, 250, 100)
$ware_7 =  GUICtrlCreateButton  ("Product 7",  260,   5, 250, 100)
$ware_8 =  GUICtrlCreateButton  ("Product 8",  260, 110, 250, 100)
$ware_9 =  GUICtrlCreateButton  ("Product 9",  260, 215, 250, 100)
$ware_10 = GUICtrlCreateButton  ("Product 10", 260, 320, 250, 100)
$ware_11 = GUICtrlCreateButton  ("Product 11", 260, 425, 250, 100)
$ware_12 = GUICtrlCreateButton  ("Product 12", 260, 530, 250, 100)
$ware_13 = GUICtrlCreateButton  ("Product 13", 515,   5, 250, 100)
$ware_14 = GUICtrlCreateButton  ("Product 14", 515, 110, 250, 100)
$ware_15 = GUICtrlCreateButton  ("Product 15", 515, 215, 250, 100)
$ware_16 = GUICtrlCreateButton  ("Product 16", 515, 320, 250, 100)
$ware_17 = GUICtrlCreateButton  ("Product 17", 515, 425, 250, 100)
$ware_18 = GUICtrlCreateButton  ("Product 18", 515, 530, 250, 100)
$Kraj =    GUICtrlCreateButton  ("Finish",       770,   5, 200, 625)
GUISetState()  ;==> shows GUI
while 1
    $msg = GUIGetMsg()  ;==> proves GUI
    select
        case $msg = $ware_1
        $quantity_1 = InputBox ("", "Quantity", "", "", 500, 250, 500, 200, "", "")
        $ans = MsgBox (4,"","You chose an article: Product 1, and quantity: " & $quantity_1)
        Select
            Case $ans = 6
                $var = "YES"
            Case $ans = 7
                $var = "NO"
            Case $ans = 2 ; ==> only if there is cancel
                Exit
        EndSelect
                                                            ; ==> MsgBox(0, "AutoIt", $ans)
        case $msg = $Kraj
            Exit
        case $msg = -3 ; 3 = little cross (close)
            Exit
    EndSelect

WEnd

.

looks better ;)

now i'll check your questions ....

1. $ans is the output of the msgbox (which button was pressed)

2. you set the font correctly for the entire gui

3. Alters the position of a control defined by GUICtrlSetPos.

.

1 = absolute coordinates (default) still relative to the dialog box.
0 = relative position to the start of the last control (upper left corner).
2 = cell positioning relative to current cell. A -1 for left or top parameter don't increment the start.
So next line is -1,offset; next cell is offset,-1; current cell is -1,-1.
Obviously "offset" cannot be -1 which reserved to indicate the no increment. But if you can use a multiple of the width you choose to skip or go back.

.

cheers E.

 

Edit: sorry, i cannot explain GUICoordMode,2. i've never ever seen a script that doesn't use default mode

Edited by Edano

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Link to comment
Share on other sites

Hi, thank you, tell me first please how to edit a post, so It looks nice as yours.

I searched all over my post 3 times, and don't see the way to edit it :(

Does it maybe have a time limit to edit it?

P.S. If any moderator comes by chance, and the time to edit the post for the user passed, please put my code on the 1. post in autoit ........ form.

 

P.S.S. I just saw where edit it, ok I ruined my 1. post and it's too late to fix it...ccc

Is the script ok? I translated the letters and variables from Croatian into English, and i forgot to translate the "Exit" or "Finish".

How could I continue that script, if there should be like 10 different products on a bill?

Is there some function just to "go to line" : 

$msg = GUIGetMsg()  ;==> proves GUI
Edited by CroatianPig

YES, I know I ask facepalm questions.

YES, I know you asked the God why I had to register to the forum where normal people are.

YES, I know everything!

Link to comment
Share on other sites

  • Moderators

CroatianPig,

Welcome to the AutoIt forum. :)

See here how to use Code tags. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

 

Hi, thank you, tell me first please how to edit a post, so It looks nice as yours.

I searched all over my post 3 times, and don't see the way to edit it :(

Does it maybe have a time limit to edit it?

P.S. If any moderator comes by chance, and the time to edit the post for the user passed, please put my code on the 1. post in autoit ........ form.

 

P.S.S. I just saw where edit it, ok I ruined my 1. post and it's too late to fix it...ccc

Is the script ok? I translated the letters and variables from Croatian into English, and i forgot to translate the "Exit" or "Finish".

How could I continue that script, if there should be like 10 different products on a bill?

Is there some function just to "go to line" : 

$msg = GUIGetMsg()  ;==> proves GUI

 

I was thinking along the same lines as Edano, if you use a function to pass your button to you can read that button and add it to your reply.  I probably didn't do this as well as some of the pros but it looks like it works on my end.

GUICreate ("Articles", 975, 635, 500, 100) ;==> crta GUI
Local $font
$font = "Comic Sans MS"
GUISetFont (20, 400, "", $font)
$ware_1 =  GUICtrlCreateButton  ("Product 1",    5,   5, 250, 100)
$ware_2 =  GUICtrlCreateButton  ("Product 2",    5, 110, 250, 100)
$ware_3 =  GUICtrlCreateButton  ("Product 3",    5, 215, 250, 100)
$ware_4 =  GUICtrlCreateButton  ("Product 4",    5, 320, 250, 100)
$ware_5 =  GUICtrlCreateButton  ("Product 5",    5, 425, 250, 100)
$ware_6 =  GUICtrlCreateButton  ("Product 6",    5, 530, 250, 100)
$ware_7 =  GUICtrlCreateButton  ("Product 7",  260,   5, 250, 100)
$ware_8 =  GUICtrlCreateButton  ("Product 8",  260, 110, 250, 100)
$ware_9 =  GUICtrlCreateButton  ("Product 9",  260, 215, 250, 100)
$ware_10 = GUICtrlCreateButton  ("Product 10", 260, 320, 250, 100)
$ware_11 = GUICtrlCreateButton  ("Product 11", 260, 425, 250, 100)
$ware_12 = GUICtrlCreateButton  ("Product 12", 260, 530, 250, 100)
$ware_13 = GUICtrlCreateButton  ("Product 13", 515,   5, 250, 100)
$ware_14 = GUICtrlCreateButton  ("Product 14", 515, 110, 250, 100)
$ware_15 = GUICtrlCreateButton  ("Product 15", 515, 215, 250, 100)
$ware_16 = GUICtrlCreateButton  ("Product 16", 515, 320, 250, 100)
$ware_17 = GUICtrlCreateButton  ("Product 17", 515, 425, 250, 100)
$ware_18 = GUICtrlCreateButton  ("Product 18", 515, 530, 250, 100)
$Kraj =    GUICtrlCreateButton  ("Finish",       770,   5, 200, 625)
GUISetState()  ;==> shows GUI
while 1
    $msg = GUIGetMsg()  ;==> proves GUI
    select
        case $msg = $ware_1
            _EvaluateQuantity($ware_1)

        case $msg = $ware_2
            _EvaluateQuantity($ware_2)

        case $msg = $ware_3
            _EvaluateQuantity($ware_3)

        case $msg = $ware_4
            _EvaluateQuantity($ware_4)

        case $msg = $ware_5
            _EvaluateQuantity($ware_5)

        case $msg = $ware_6
        _EvaluateQuantity($ware_6)

        case $msg = $ware_7
        _EvaluateQuantity($ware_7)

        case $msg = $ware_8
        _EvaluateQuantity($ware_8)

        case $msg = $ware_9
        _EvaluateQuantity($ware_9)

        case $msg = $ware_10
        _EvaluateQuantity($ware_10)

        case $msg = $ware_11
        _EvaluateQuantity($ware_11)

        case $msg = $ware_12
        _EvaluateQuantity($ware_12)

        case $msg = $ware_13
        _EvaluateQuantity($ware_13)

        case $msg = $ware_14
        _EvaluateQuantity($ware_14)

        case $msg = $ware_15
        _EvaluateQuantity($ware_15)

        case $msg = $ware_16
        _EvaluateQuantity($ware_16)

        case $msg = $ware_17
        _EvaluateQuantity($ware_17)

        case $msg = $ware_18
        _EvaluateQuantity($ware_18)

        case $msg = $Kraj
            Exit
        case $msg = -3 ; 3 = little cross (close)
            Exit
    EndSelect
WEnd

;\\\\\\\\\\\\\\\\\\\\\\\\\\\\ FUNCTIONS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Func _EvaluateQuantity(ByRef $button)
        $quantity = InputBox ("", "Quantity", "", "", 500, 250, 500, 200, "", "")
        $ans = MsgBox (4,"","You chose an article: " & GUICtrlRead($button) & ", and quantity: " & $quantity)
EndFunc
Link to comment
Share on other sites

With Opt(GUICoordMode, 1) then each of these controls starting position will be based on the (0,0) coordinates of the main form.

Global Const $ware_1 = GUICtrlCreateButton("Product 1", 5, 5, 250, 100)
Global Const $ware_2 = GUICtrlCreateButton("Product 2", 5, 110, 250, 100)
Global Const $ware_3 = GUICtrlCreateButton("Product 3", 5, 215, 250, 100)

With Opt(GUICoordMode, 2) then each of these controls starting position will be based on the ending coordinates of the last control created.

That's the best way I know to explain it.  Maybe someone else can be more eloquent?

Edited by jaberwocky6669
Link to comment
Share on other sites

okay, now that WhiteSpace has begun, i dare to alter the script as well.

.

;http://www.autoitscript.com/forum/topic/153239-gui-beginner-attempt-cash-register/#entry1102600
;Post #6
;D:\DOKUME~1\ADMINI~1\LOKALE~1\Temp\SLICER\Avatar\default_large.png
;by WhiteSpace

;Script grabbed by SLICER by Edano here: http://www.autoitscript.com/forum/topic/152402-slicer-autoit-forum-script-grabber/?p=1093575

GUICreate ("Articles", 975, 635, 500, 100) ;==> crta GUI
GUISetFont (20, 400, "", "Comic Sans MS")
Global $ware[18]
For $j=0 To 2
    For $i=0 To 5
        $ware[$j*6+$i]=GUICtrlCreateButton ("Product "&$i+1+$j*6,5+255*$j,5+105*$i,250,100)
    Next
Next
$Kraj =    GUICtrlCreateButton  ("Finish",       770,   5, 200, 625)
GUISetState()  ;==> shows GUI

While 1
    $msg = GUIGetMsg()  ;==> proves GUI
    For $i=0 To 17
        If $msg=$ware[$i] Then _EvaluateQuantity($i)
    Next
    If $msg = $Kraj Or $msg=-3 Then Exit
WEnd

;\\\\\\\\\\\\\\\\\\\\\\\\\\\\ FUNCTIONS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Func _EvaluateQuantity($button)
    Local $product=GUICtrlRead($ware[$button])
    Local $quantity = InputBox ("", "Quantity of "&$product&":", "", "", 500, 250, 500, 200, "", "")
    Local $ans = MsgBox (4,"","You chose an article: " & $product & ", and quantity: " & $quantity)
EndFunc

.

please ask if you don't understand, but study the help file first :)

E.

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Link to comment
Share on other sites

With Opt(GUICoordMode, 1) then each of these controls starting position will be based on the (0,0) coordinates of the main form.

Global Const $ware_1 = GUICtrlCreateButton("Product 1", 5, 5, 250, 100)
Global Const $ware_2 = GUICtrlCreateButton("Product 2", 5, 110, 250, 100)
Global Const $ware_3 = GUICtrlCreateButton("Product 3", 5, 215, 250, 100)

With Opt(GUICoordMode, 2) then each of these controls starting position will be based on the ending coordinates of the last control created.

That's the best way I know to explain it.  Maybe someone else can be more eloquent?

.

as i said, i did never understand it, and i have never seen an example. but it looks useful once you try it....

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Link to comment
Share on other sites

okay, now that WhiteSpace has begun, i dare to alter the script as well.

.

;http://www.autoitscript.com/forum/topic/153239-gui-beginner-attempt-cash-register/#entry1102600
;Post #6
;D:\DOKUME~1\ADMINI~1\LOKALE~1\Temp\SLICER\Avatar\default_large.png
;by WhiteSpace

;Script grabbed by SLICER by Edano here: http://www.autoitscript.com/forum/topic/152402-slicer-autoit-forum-script-grabber/?p=1093575

GUICreate ("Articles", 975, 635, 500, 100) ;==> crta GUI
GUISetFont (20, 400, "", "Comic Sans MS")
Global $ware[18]
For $j=0 To 2
    For $i=0 To 5
        $ware[$j*6+$i]=GUICtrlCreateButton ("Product "&$i+1+$j*6,5+255*$j,5+105*$i,250,100)
    Next
Next
$Kraj =    GUICtrlCreateButton  ("Finish",       770,   5, 200, 625)
GUISetState()  ;==> shows GUI

While 1
    $msg = GUIGetMsg()  ;==> proves GUI
    For $i=0 To 17
        If $msg=$ware[$i] Then _EvaluateQuantity($i)
    Next
    If $msg = $Kraj Or $msg=-3 Then Exit
WEnd

;\\\\\\\\\\\\\\\\\\\\\\\\\\\\ FUNCTIONS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Func _EvaluateQuantity($button)
    Local $product=GUICtrlRead($ware[$button])
    Local $quantity = InputBox ("", "Quantity of "&$product&":", "", "", 500, 250, 500, 200, "", "")
    Local $ans = MsgBox (4,"","You chose an article: " & $product & ", and quantity: " & $quantity)
EndFunc

.

please ask if you don't understand, but study the help file first :)

E.

 

Ok, I tried it, and it works.

It takes 50% less code than I wrote, and it looks awesome as you used "i" and "j" as for matrixes which I (of course) didn't have a clue it can be used.

How could I increase the font on other windows, same like in the first window?

Is there a way to put it using "global", so that every GUI on that script has "Comic Sans MS" (I chose it just coz it's nicer to read), and font "20".

I've tried putting those lines with font, but nothing works so far...

Whenever I move from a window "Articles" to "Quantity of product", it returns to a small font...

P.S. What is actually "$msg"?      Is it (I try to explain the best I can) a function that "records" and "remembers" whatever you do with keyboard or mouse after some "critical point"?

And oh yea, I tried clicking on $msg and hit f1, but no exact explanation for it.

Edited by CroatianPig

YES, I know I ask facepalm questions.

YES, I know you asked the God why I had to register to the forum where normal people are.

YES, I know everything!

Link to comment
Share on other sites

.

as i said, i did never understand it, and i have never seen an example. but it looks useful once you try it....

 

I realised the best way to understand something, is to see an example or so, and change a few numbers to see what happens, so please, tell me where to put those 3 lines, so I see the difference and possibly understand it.

I tried putting, but it gives me an error.

I tried to replace these 3 lines:

$ware_1 =  GUICtrlCreateButton  ("Product 1",    5,   5, 250, 100)
$ware_2 =  GUICtrlCreateButton  ("Product 2",    5, 110, 250, 100)
$ware_3 =  GUICtrlCreateButton  ("Product 3",    5, 215, 250, 100)

with those "new" 3 lines, but nothing happens so far.

Edited by CroatianPig

YES, I know I ask facepalm questions.

YES, I know you asked the God why I had to register to the forum where normal people are.

YES, I know everything!

Link to comment
Share on other sites

Edano, you just hurt my brain with that awesome display of code, I'm going to attempt to glean some knowledge from that.

 

All of you guys here are smart and creative, and if he hurt your brain with that, imagine how I feel....

At the same time I feel: very happy + very enlightened + humiliated like a pile of s***

YES, I know I ask facepalm questions.

YES, I know you asked the God why I had to register to the forum where normal people are.

YES, I know everything!

Link to comment
Share on other sites

All of you guys here are smart and creative, and if he hurt your brain with that, imagine how I feel....

At the same time I feel: very happy + very enlightened + humiliated like a pile of s***

.

hi there

$i and $j are loop counts, the matrices are called "arrays", and the rest is math. arrays index a variable, you have one with the name aray[0], the next is array[1]  and so on.

for every gui you create you have to define the font again GUISetFont(20, 400, "", $font). this does not work with system windows, like inputbox and msgbox. they are like windows does them. but instead you can create your own inputbox gui, that is the better way.

you are completely right, $msg returns the control that is actuated in the gui. the gui traps that click and gives out the control id for you to use it. there are other more advanced ways to do it, but that is ten steps ahead. now you learn guis, arrays and functions.

please don't feel bad, but this is the way to learn it, study examples and you understand, and as far as i can say, you seem to understand a lot more than other newbies :)

E.


[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Link to comment
Share on other sites

please don't feel bad, but this is the way to learn it, study examples and you understand, and as far as i can say, you seem to understand a lot more than other newbies :)

E.

 

It's ok, I have high (I suppose) maths and physics knowledge only, as I'm an enthusiastical engineer and I love both maths and physics (and I teach them privately to some pupils and students), but the only programming I have ever come "actively" in contact, was in my elementary school, and it was Q Basic or so, which was a comedy and I liked it actually, "if" "then", "print" etc... was pretty cool...

What I'm trying to say, it looks kinda primitive compared to what nowadays means "programming". 

I don't know if there is some, let's say, a scale, as how some programming language complex is, compared to others, but AutoIt (or SciTe - despite I dont know what mean both words) seems kinda... resourcefull... as if someone could, let's say, make a Terminator, if a person was a genious, and could know how to use AutoIt completely.

Ok, I started s***ing, so, what I wanted to ask about the "newest script" (I translated hopefully everything now into English), is the following (I will paste the script first to make it easier):

 

GUICreate ("Articles", 975, 635, 500, 100) ;==> draws GUIGUISetFont (20, 400, "", "Comic Sans MS")
Global $ware[18]
For $j=0 To 2
    For $i=0 To 5
        $ware[$j*6+$i]=GUICtrlCreateButton ("Product "&$i+1+$j*6,5+255*$j,5+105*$i,250,100)
    Next
Next
$Finish =    GUICtrlCreateButton  ("Finish",       770,   5, 200, 625)
GUISetState()  ;==> shows GUI


While 1
    $msg = GUIGetMsg()  ;==> proves GUI
    For $i=0 To 17
        If $msg=$ware[$i] Then _EvaluateQuantity($i)
    Next
    If $msg = $Finish Or $msg=-3 Then Exit
WEnd


;\\\\\\\\\\\\\\\\\\\\\\\\\\\\ FUNCTIONS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Func _EvaluateQuantity($button)
    Local $product=GUICtrlRead($ware[$button])
    Local $quantity = InputBox ("", "Quantity of "&$product&":", "", "", 500, 250, 500, 200, "", "")
    Local $ans = MsgBox (4,"","You chose an article: " & $product & ", and quantity: " & $quantity)
EndFunc

 

Why did you put this line : 

For $i=0 To 17

because isn't our 

$i

 the variable of the row of our GUI? As mentioned before, For 

$i=0 To 5

...

Also, why is the input 

$msg=-3

 of the little cross to exit? I mean, why minus? Because positive 3 doesn't work. Is it the default in Autoit, little cross = -3 ?


Edited by CroatianPig

YES, I know I ask facepalm questions.

YES, I know you asked the God why I had to register to the forum where normal people are.

YES, I know everything!

Link to comment
Share on other sites

$i is just a count. it counts from 0 to 17 (18 buttons) and checks which one was clicked.

GUI Events

There are three types of event messages that GUIGetMsg will return:

  • No Event
  • Control Event
  • System Event

     

    No Event

    When there are no events waiting to be processed GUIGetMsg returns 0. In a usual GUI this is the most common event.

    Control Event

    When a control is clicked or changes a control event is sent - this event is a positive number that corresponds to the controlID that was returned when the control was created with GUICtrlCreate....

    System Event

    System events - such as the GUI closing - are negative numbers. The different events are shown below and are defined in GUIConstantsEx.au3:

    $GUI_EVENT_CLOSE
    $GUI_EVENT_MINIMIZE
    $GUI_EVENT_RESTORE
    $GUI_EVENT_MAXIMIZE
    $GUI_EVENT_PRIMARYDOWN
    $GUI_EVENT_PRIMARYUP
    $GUI_EVENT_SECONDARYDOWN
    $GUI_EVENT_SECONDARYUP
    $GUI_EVENT_MOUSEMOVE
    $GUI_EVENT_RESIZED
    $GUI_EVENT_DROPPED

 


 

.

from help file $GUI_EVENT_CLOSE=-3

 

Edit: look here

Edit: and please use autoit tags, not plain text tags

Edited by Edano

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Link to comment
Share on other sites

CroatianPig,

It is generally advisable to seperate data from code.  In your example adding or subtracting procucts would require code changes.  Changes to your gui are also unneccesarily diffucult as the placement of the buttons are dependent on the window size.

It is certainly possible to keep using buttons to represent products, and as you learn more about gui management you will find smarter ways to do this. 

However, I would like to offer you an alternative.  The following code is a completely different way to look at the task.  It isolates the data from the code by using a simple INI file (attached).  The code is barebones but illustrates the idea.

As you are learning, and learning well I might add, you will find that the possibilities for gui creation are limited only by your knowledge of gui management and creativity.  You are far enough along that a thorough reading of the all gui related sections of the Help file would benefit you.

Use the following code or not.  Just be aware that there are many possibilities.

#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <array.au3>

#AutoIt3Wrapper_Add_Constants=n

local $inifile = @scriptdir & "\vacations.ini"

local $gui010   =   guicreate('Vacations Are Us',900,350)
                    guisetfont(12,400,-1,'Comic Sans MS')
local $aSize    =   wingetclientsize($gui010)
                    guictrlcreatelabel('Products',20,20,200,30)
                    guictrlsetfont(-1,14,800)
local $lst010   =   guictrlcreatelist('',20,50,200,150)
local $edt010   =   guictrlcreateedit('',230,50,660,200,BitOr($ws_hscroll,$es_readonly))
                    guictrlsetfont(-1,10,800,-1,'Courier New')
                    guictrlcreatelabel('Description',230,20,200,30)
                    guictrlsetfont(-1,14,800)
local $inp010   =   guictrlcreateinput('',110,220,20,30)
                    guictrlsetlimit(-1,1)
                    guictrlcreatelabel('Quantity:',20,220,85,30)
                    guictrlsetfont(-1,14,800)
local $btn010   =   guictrlcreatebutton('Book The Trip',10,$aSize[1]-80,$aSize[0]-20)
                    GUICtrlSetBkColor(-1,0x00ffff)
                    guictrlcreatelabel('Status',20,$aSize[1]-35,$aSize[0]-40,50)
local $warn     =   guictrlcreatelabel('',120,$aSize[1]-35,$aSize[0]-120,30,$ss_sunken)
                    GUICtrlSetColor(-1,0xaa0000)

                    ; product (trip) definitions are in an INI file.  Each product corresponds to one section.
                    ; The second array ($aDesc is to hold values from each section)

                    Local $aProducts = IniReadSectionNames($inifile), $aDesc[5][2]

                    for $1 = 1 to ubound($aProducts) - 1
                        guictrlsetdata($lst010,$aProducts[$1])
                    next

                    guisetstate()
                    guictrlsetstate($lst010,$gui_focus)

while 1
    switch guigetmsg()
        case $gui_event_close
            Exit
        case $lst010
            guictrlsetdata($edt010,'')
            $aDesc = inireadsection($inifile,guictrlread($lst010))
            for $1 = 2 to ubound($aDesc) - 1
                guictrlsetdata($edt010,stringformat('%-7s : %-900s',stringupper($aDesc[$1][0]),$aDesc[$1][1]) & @CRLF,1)
            next
        case $btn010
            guictrlsetdata($warn,'')
            if guictrlread($inp010) = '' or not StringIsDigit(guictrlread($inp010)) then
                guictrlsetstate($inp010,$gui_focus)
                guictrlsetdata($warn,'  Quantity Required...')
            endif

            ;
            ; this is where you would do your "bill of sale" routine
            ;

    EndSwitch
WEnd

vacations.txt

The uploader will not let me upload an INI file so I changed it to a txt file.  Just rename it and put it in whatever directory you run the script from.

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Hi BOHICA, it looks nice with those colors and the GUI interface.

I tried to run, but when i press f5, and go to quantity, I can only type 1-digit number. 

Nevermind, I will look into it in details later to try to understand at least something of that code, and the file included and give you a hint.

P.S. I don't know why it isn't showing those locations, coz I pasted that notepad file (vacations) on the desktop and tried to put these 2 roots on the line:

local $inifile = @scriptdir & "C:\Users\Fuzzy\Desktop\vacations.ini"

and

local $inifile = @scriptdir & "C:\Users\Fuzzy\Desktop\vacations"

and it's not working....

 

 

Edano, thanks for the explanation. I will try later to combine and ask you if I ran into problems (99% I will) about that script you made with auto-opening of Notepad (easier to open than MS word) and auto-typing all the selected quantities, and aswell, have another GUI so I can change font on every pop-up window.

Edited by CroatianPig

YES, I know I ask facepalm questions.

YES, I know you asked the God why I had to register to the forum where normal people are.

YES, I know everything!

Link to comment
Share on other sites

I tried to run, but when i press f5, and go to quantity, I can only type 1-digit number

 

Yes, because of this statement:

guictrlsetlimit(-1,1)

Nevermind, I will look into it in details later to try to understand at least something of that code, and the file included and give you a hint

 

Good Luck, please consider my suggestion to read the gui management sections of the Help file.  It would be worthwhile to spend an hour going through either piece of code and making sure that you understand what each statement is doing.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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