Jump to content

Just Started Trying To Learn Variables. Need Some Help


Recommended Posts

I'm just trying to make an easy script, but I don't know how to do it. I made a simple GUI that I'll post the code up for. I want to make it like if I typed in 56 in the input box or something like that, that it will pop up with a msg box saying "that number is higher than 10" and if I would type in 6 it would say "that number is lower then 10". They having something like this is the helpfile, but that one you can't type in your own number. I want to learn how to do this so I can have input boxes in my GUI and if I'd type "notepad" that it would open notepad. Just to get me started with that.

#include <GuiConstants.au3>


GuiCreate("MyGUI", 188, 55,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Input_1 = GuiCtrlCreateInput("Put a number in here", 10, 10, 80, 30)
$Button_2 = GuiCtrlCreateButton("ok", 110, 10, 70, 30)



GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
    ;;;
    EndSelect
WEnd
Exit
#endregion --- GuiBuilder generated code End ---
Link to comment
Share on other sites

#include <GuiConstants.au3>


GuiCreate("MyGUI", 188, 55,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Input_1 = GuiCtrlCreateInput("Put a number in here", 10, 10, 80, 30)
$Button_2 = GuiCtrlCreateButton("ok", 110, 10, 70, 30)



GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $button_2
    $var = Number(GuiCtrlRead($input_1))
if $var < 10 then
msgbox(0,'',"That's less than 10")
ElseIf $var = 10 then
MsgBox(0,'',"That's 10")
else
MsgBox(0,'',"That's more than 10")
endif
    EndSelect
WEnd
Exit
#endregion --- GuiBuilder generated code End ---

~cdkid

Edited by cdkid
AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

#include <GuiConstants.au3>
GuiCreate("MyGUI", 188, 55,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Input_1 = GuiCtrlCreateInput("Put a number in here", 10, 10, 80, 30)
$Button_2 = GuiCtrlCreateButton("ok", 110, 10, 70, 30)
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button_2
                DoSomething(GUICtrlRead($Input_1))
    EndSelect
WEnd
Exit

Func DoSomething($val)
        If $val > 10 then
              MsgBox(0,"",$val & "is greater than 10")
        Else
              MsgBox(0,"",$val & "is less than 10")
        Endif
EndFunc
#endregion --- GuiBuilder generated code End ---

or something like that

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Depending on preference, you could also use GUIOnEventMode.

Using this mode was much easier for me to learn AutoIt because it gives you complete control of what could be a complex GUI without having to run through a long list of messages. You can specify exact functions to handle events instead of running through a Select statement and processing them all on the fly.

Here is the script you're trying to write, but using GUI Event mode instead:

#include <GuiConstants.au3>

Opt("GUIOnEventMode",1)

; Create the GUI
GuiCreate("MyGUI", 240, 65)

; Set event for when the GUI is closed to call the function "closeGUI()"
GUISetOnEvent($GUI_EVENT_CLOSE,"closeGUI")

; Create a label for the Input box
GUICtrlCreateLabel("Enter a number to analyze:", 10, 10)

; Create the Input box
; Make the variable "$Input_1" Global so it's value can be accessed from inside the function that handles the "click" event on the Button
Global $Input_1 = GuiCtrlCreateInput("", 145, 7, 80)

; Create the button
$Button_2 = GuiCtrlCreateButton("Analyze", 90, 35, 60, 21)

; Set event for when the button is clicked to call the function "buttonclick"
GuiCtrlSetOnEvent($Button_2, "buttonclick")

; Draw the GUI
GuiSetState()

While 1
    Sleep(1000) ; Idle and do nothing - this keeps the GUI alive
WEnd

Func closeGUI()
; This function is called when the X is clicked to close the GUI
; The "GUISetOnEvent" function on line 9 assigns this function to handle the close event
    Exit
EndFunc;closeGUI()

Func buttonclick()
; This function is called when "$Button_2" is clicked
; The "GUICtrlSetOnEvent" function on line 22 assigns this function to handle the button's click event
    
; Read the value of the input box "$Input_1" and assign it to a variable:
    Dim $input_1_value = GUICtrlRead($Input_1)
    
; Now analyze the value to determine if it's equal to, higher, or lower than 10:

; Display the value entered in the text box:
    MsgBox(0,"Entered Value","The value entered is " & $input_1_value )
        
    If $input_1_value > 10 Then
        MsgBox(0,"Result","The value is greater than 10")
    ElseIf $input_1_value < 10 Then
        MsgBox(0,"Result","The value is less than 10")
    ElseIf $input_1_value = 10 Then
        MsgBox(0,"Result","The value is equal to 10")
    EndIf   
EndFunc;buttonclick()

Hope this helps :)

Link to comment
Share on other sites

Where's GuiOnEventMode? I think I've seen it somewhere, but I can't find it.

look in help for the 3 letters - opt - you will find it in the listing

Depending on preference, you could also use GUIOnEventMode.

Using this mode was much easier for me to learn AutoIt because it gives you complete control of what could be a complex GUI without having to run through a long list of messages. You can specify exact functions to handle events instead of running through a Select statement and processing them all on the fly.

Here is the script you're trying to write, but using GUI Event mode instead:

I hate to add to all this but I have found it very hard to use the GUIOnEventMode without using global variables - is it possible for you to show the code above with 3 buttons all calling the same function and from there they call another function - with using variables and arrays for the buttons. I can show you some code that I have posted - and now that I have learned a little more about what you can do - I find myself wanting to do things to speed things up and to not write as much code.

create 3 buttons

button[1]

button[2]

button[3]

call dummy()

if button[1] then do something (create another gui) with needed information from the MAIN gui - f1()

if button[2] then do something (create another gui) with needed information from the MAIN gui - f2()

if button[3] then do something (create another gui) with needed information from the MAIN gui - f2()

Does any of this make sense?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

It doesn't make sense to me, but I don't think it was directed at me. I've tried using all your scripts as guides to make one by myself, but I'm having difficulty with that. I'm trying to figure out how to do it with names now and I'm having no luck. I think maybe this is to advanced for me yet. Is it really very hard for you? I don't know what to do cause I got the really easy basics down and have no idea what to do so I thought maybe variables. And I have learned I just can't understand it.

Link to comment
Share on other sites

It doesn't make sense to me, but I don't think it was directed at me. I've tried using all your scripts as guides to make one by myself, but I'm having difficulty with that. I'm trying to figure out how to do it with names now and I'm having no luck. I think maybe this is to advanced for me yet. Is it really very hard for you? I don't know what to do cause I got the really easy basics down and have no idea what to do so I thought maybe variables. And I have learned I just can't understand it.

I understand it and am able to do it with Global Variables - I am trying to get out of using the Global as it takes up more memory, at least in most languages it does. If anyone is reading this - how do you work with OnEvent with out Global Varables - or am I going down the wrong path and will need to use them if I do OnEvent. Like I said I have a lot of code that I want to change - before writing it all. I do not want to have to rewrite the code later because now I know how to do it. I would like to know the right way to do it and then write my code that way. Practice makes perfect and perfect practice is the way I want to go.

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

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