Sign in to follow this  
Followers 0
nitekram

Opt("guioneventmode", 1)

10 posts in this topic

Help! This does not seem to work - this is the part of my code that is getting me stuck. I guess I could use a button but I was hoping to save some space and some code. I am suppose to be able to pick the drop down item and then click the go and go the right function on event call. In this case it always goes to the second function call. What am I doing wrong?

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)
Global $mainwindowTitle = "test_this", $mainwindowLable1 = "not able to chose the right dropdown"

If WinExists($mainwindowTitle) Then; CHECK IF ALREADY RUNNING
    MsgBox(0, "ERROR", "APPLICATION ALREADY RUNNING")
    Exit
EndIf

;MAIN WINDOW
$mainwindow = GUICreate($mainwindowTitle)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUICtrlCreateLabel($mainwindowLable1, 30, 10)

ShowStartWindow()
scriptor()
StayActive(1000)


Func ShowStartWindow()
    GUISwitch($mainwindow)
    GUISetState(@SW_SHOW)
    WinActivate($mainwindow)
EndFunc  ;==>ShowStartWindow
;*****************************************************


Func StayActive($SleepTime)
    While 1
        Sleep($SleepTime); Idle around
    WEnd
EndFunc  ;==>StayActive
;*****************************************************


Func scriptor()
    $scriptor_Combo_1 = GUICtrlCreateCombo("Select Script", 50, 35, 150, 21)
    GUICtrlSetData($scriptor_Combo_1, "|test 1|test 2")
    $scriptor_Button1 = GUICtrlCreateButton('GO', 50, 60, 100, 17)  
    GUICtrlSetOnEvent($scriptor_Button1, "scriptor1")
    GUICtrlSetOnEvent($scriptor_Button1, "scriptor2")
    
EndFunc  ;==>scriptor
;*****************************************************
Func scriptor1()
    $scriptor1_my_file1 = "C:\test1.txt"
    $scriptor_file1 = FileOpen($scriptor1_my_file1, 0)
; Check if file opened for reading OK
    If $scriptor_file1 = -1 Then
        MsgBox(0, "Error", "Unable to open file. - iN SrIPtor 1")
    ;Exit;CLEAR MSGBOX NEEDED
    EndIf
    ClipPut(FileRead($scriptor1_my_file1))
    FileClose($scriptor1_my_file1)
EndFunc  ;==>scriptor1
;*****************************************************
Func scriptor2()
    $scriptor_my_file2 = "C:\test2.txt"
    $scriptor_file2 = FileOpen($scriptor_my_file2, 0)
; Check if file opened for reading OK
    If $scriptor_file2 = -1 Then
        MsgBox(0, "Error", "Unable to open file. - iN SrIPtor 2")
    ;Exit;CLEAR MSGBOX NEEDED
    EndIf
    ClipPut(FileRead($scriptor_my_file2))
    FileClose($scriptor_my_file2)
EndFunc  ;==>scriptor2
;*****************************************************


Func Close()
Exit
EndFunc

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

Share this post


Link to post
Share on other sites



It sounds like you're trying to make the button go to the right function based off the combo box value. If that's the case, setting two OnEvents for the button won't do the trick - it will do exactly what you say, and just call the second one (the first is being overwritten). What you should do is make a dummy function for the button to go to, and then inside that function read the value of the combo box and go to the correct function from there.

Example:

[....]
GUICtrlSetOnEvent($scriptor_Button1, "dummyButtonFunc")
[....]
Func dummyButtonFunc()
    If GuiCtrlRead ($scriptor_Combo_1) = "test1" Then
        scriptor1()
    ElseIf GuiCtrlRead ($scriptor_Combo_1) = "test2" Then
        scriptor2()
    EndIf
EndFunc
[....]

The [....] is where the rest of your code would go.

Share this post


Link to post
Share on other sites

It sounds like you're trying to make the button go to the right function based off the combo box value. If that's the case, setting two OnEvents for the button won't do the trick - it will do exactly what you say, and just call the second one (the first is being overwritten). What you should do is make a dummy function for the button to go to, and then inside that function read the value of the combo box and go to the correct function from there.

Example:

[....]
GUICtrlSetOnEvent($scriptor_Button1, "dummyButtonFunc")
[....]
Func dummyButtonFunc()
    If GuiCtrlRead ($scriptor_Combo_1) = "test1" Then
        scriptor1()
    ElseIf GuiCtrlRead ($scriptor_Combo_1) = "test2" Then
        scriptor2()
    EndIf
EndFunc
[....]

The [....] is where the rest of your code would go.

that worked after about 20 trys - i set up all sorts of test to get the day and none came up - then I start looking at _GUICtrlComboFindString and my code again - then i found that your code did not have a space in it - sort of like my brain, out in space - I thank you for your time on this - I would have never even tried that, but I had tried setting each of the events to a variable and then testing for that variable - so I was close I just never thought of the dummy function call - that is why i am a newbee and you and the rest of you are the gurus - thanks again

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

green has a great idea... just one small addition

[....]
GUICtrlSetOnEvent($scriptor_Button1, "dummyButtonFunc")
[....]
Func dummyButtonFunc()
$info =  GuiCtrlRead ($scriptor_Combo_1)   
If $info = "test1" Then scriptor1()
If $info = "test2" Then scriptor2()
EndFunc
[....]

that way the control is read only one time

case. switch could be utilized also

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

Good call - I almost did it that way (I would have in a real-program situation), but I was too lazy to cut and paste and reformat the fast-reply box.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

green has a great idea... just one small addition

ELSEIF $info = "test2" Then scriptor1()
IF $info = "test2" Then scriptor2()

that way the control is read only one time

case. switch could be utilized also

8)

Sorry to ask a stupid question but can you give me an idea what the difference is between these 2 conditions. If you could make it realy simple I would be thankful - my head is spinning.

*********EDIT

sorry - make my self clear - the 2 conditions are If and ElseIt

Edited by nitekram

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

Share this post


Link to post
Share on other sites

Well "IF" starts the if/then conditional statement. You can't have an ElseIf if you don't have an If.

The main difference is the amount of code executed. Every "If" will be executed, but not every "ElseIf" or "else". For example:

$Num = 10
If $Num = 1 Then
    MsgBox (0, "", "num is 1")
ElseIf ($Num >= 2) And ($Num <= 10) Then
    MsgBox (0, "", "num is between 2 and 10, inclusive")
ElseIf ($Num > 10) And ($Num < 100) Then; not executed
    MsgBox (0, "", "num is between 10 and 100, exclusive")
Else; not executed
    MsgBox (0, "", "num is 100 or greater")
EndIf


; all are executed
If $Num = 1 Then MsgBox (0, "", "num is 1")
If ($Num >= 2) And ($Num <= 10) Then MsgBox (0, "", "num is between 2 and 10, inclusive")
If ($Num > 10) And ($Num < 100) Then MsgBox (0, "", "num is between 10 and 100, exclusive")
If $Num >= 100 Then MsgBox (0, "", "num is 100 or greater")

You would use ElseIf and Else if you only want it to match one case and then move on. You would use multiple Ifs if you wanted it to be able to match multiple cases.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Well "IF" starts the if/then conditional statement. You can't have an ElseIf if you don't have an If.

The main difference is the amount of code executed. Every "If" will be executed, but not every "ElseIf" or "else". For example:

You would use ElseIf and Else if you only want it to match one case and then move on. You would use multiple Ifs if you wanted it to be able to match multiple cases.

I think I understand - if you start of with If/IfElse the first condition that is correct goes to Then and then the test stops?

****edit

made it make sense

Edited by nitekram

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

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Ok, the breakdown of the first code segment. If I'm reading your statement correctly, I think you're on the right track. But here it is anyway.

$Num = 10; set $Num to 10 (simple enough)

If $Num = 1 Then; checks to see if $Num is 1.  This test will happen every time.

    MsgBox (0, "", "num is 1"); If $Num is 1, this message will show up.  No other tests will be tried.

ElseIf ($Num >= 2) And ($Num <= 10) Then; If $Num is not 1, check if it is greater than or equal to 2 and less than or equal to 10.

        MsgBox (0, "", "num is between 2 and 10, inclusive"); If $Num is between 2 and 10, this box will show up.  No further tests will be tried.

ElseIf ($Num > 10) And ($Num < 100) Then; not executed, because a test was already passed.  If $Num hadn't passed any of the above tests, this one will check to see if $Num is greater than 10 and less than 100.

    MsgBox (0, "", "num is between 10 and 100, exclusive"); If it is between 10 and 100, this will show up, and the last test will not be executed.

Else; not executed because a test was already passed.  If $Num did not pass any of the above tests, this is a default case.  It must be used at the end, because everything that was not considered above is considered here.  

    MsgBox (0, "", "num is 100 or greater"); this is misleading... the message should be: "num may be less than 1, greater than 99."  It would also run if $Num was a char, or a float... anything but the above integers.

EndIf

Edit - spacing.

Edited by greenmachine

Share this post


Link to post
Share on other sites

Ok, the breakdown of the first code segment. If I'm reading your statement correctly, I think you're on the right track. But here it is anyway.

COOL - I think I understand - until tomorrow where I have to remember it all again. In time I hope that it is all just second nature like it is for you guys. Maybe one day - for now I am a question guy with answer sometimes, but most of the time it is all questions. Like I have said before, I have never been on a forum before and if this is what it is like - well, I have been missing out. You guys are very helpful and we are all greatful for your time and nerves.


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

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