Sign in to follow this  
Followers 0
Terrified

help with simple script :)

15 posts in this topic

how can i make it work ;)?

#include <GuiConstants.au3>
HotKeySet("{NUMPAD0}", "rr")
GUICreate("MyGUI", 309, 73)
$Combo_1 = GUICtrlCreateCombo("Send1", 10, 30, 180, 21)
GUICtrlSetData (-1, "Send2|Send3")
Global  $var = "test1'" , $var = "test2'" , $var = "test3"

Func rr()
    Send ("$type")
EndFunc

GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
            $type = Send ("$var")
            $combo = GUICtrlRead($Combo_1)
            If $combo = "Send1"  Then
                $var = "test1'" 
            ElseIf $combo = "send2"  Then
                $var = "test2'" 
            ElseIf $combo = "send3"  Then
                $var = "test3'" 
            EndIf 
    EndSelect 
WEnd

ty :P

Share this post


Link to post
Share on other sites



Re-read the format for Select Cases. You're mixing if statements in there for no reason.

You could just take the cases all out and use if statements if you really want. This is how the format is supposed to be

Select

Case <expression>

statement1

...

[Case

statement2

...]

[Case Else

statementN

...]

EndSelect

Share this post


Link to post
Share on other sites

For openers remove the quotes from the Send strings where you have used variables.

Example

Send ("$type")

becomes

Send ($type)


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Hmm.

I started to fix things but then I gave up

#include <GuiConstants.au3>
HotKeySet("{NUMPAD0}", "rr")
GUICreate("MyGUI", 309, 73)
$Combo_1 = GUICtrlCreateCombo("Send1", 10, 30, 180, 21)
GUICtrlSetData (-1, "Send2|Send3")
Global  $var = "test1'" , $var = "test2'" , $var = "test3"

Func rr()
    Send ($type)
EndFunc

GUISetState()
While 1
    $msg = GUIGetMsg()
    if $msg = $GUI_EVENT_CLOSE Then
        ExitLoop
    EndIf
    
    $type = Send ($var)
    $combo = GUICtrlRead($Combo_1)
    If $combo = "Send1"  Then
        $var = "test1'"
    ElseIf $combo = "send2"  Then
        $var = "test2'"
    ElseIf $combo = "send3"  Then
        $var = "test3'"
    EndIf
        
WEnd

the whole thing is a mess. i give up already .

Share this post


Link to post
Share on other sites

thx to all for helping me but to the man above me -

the script work fine but when i open it, its automaticly fire the send command in a loop, how can i change that only when i hit the hot key it will do the send command, and without loop?

thx for help again

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hmm.

I started to fix things but then I gave up

#include <GuiConstants.au3>
HotKeySet("{NUMPAD0}", "rr")
GUICreate("MyGUI", 309, 73)
$Combo_1 = GUICtrlCreateCombo("Send1", 10, 30, 180, 21)
GUICtrlSetData (-1, "Send2|Send3")
Global  $var = "test1'" , $var = "test2'" , $var = "test3"

Func rr()
    Send ($type)
EndFunc

GUISetState()
While 1
    $msg = GUIGetMsg()
    if $msg = $GUI_EVENT_CLOSE Then
        ExitLoop
    EndIf
    
    $type = Send ($var)
    $combo = GUICtrlRead($Combo_1)
    If $combo = "Send1"  Then
        $var = "test1'"
    ElseIf $combo = "send2"  Then
        $var = "test2'"
    ElseIf $combo = "send3"  Then
        $var = "test3'"
    EndIf
        
WEnd

the whole thing is a mess. i give up already .

The whole thing is messed up really

You have redeclared your global variables over and over.

Global $var = "test1'" , $var = "test2'" , $var = "test3"

By the time that line is read

$var = "test3" and thats all there is to it

What that line really says is

Global $var = "Test3"

That line should read

Global $var1 = "Test1", $var2= "Test2", $var3 = "Test3"

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

thx for the help all its working :P

#include <GuiConstants.au3>
HotKeySet("{NUMPAD0}", "rr")
HotKeySet("{NUMPAD1}", "Stop")
GUICreate("MyGUI", 309, 73)
$Combo_1 = GUICtrlCreateCombo("Send1", 10, 30, 180, 21)
GUICtrlSetData (-1, "Send2|Send3")
Global $type = "send1" , $type = "send2" , $type = "send3"

Func rr()
    Send ($type)
EndFunc

Func Stop()
    $kill = 0
    EndFunc

GUISetState()
While 1
    $msg = GUIGetMsg()
    if $msg = $GUI_EVENT_CLOSE Then
        ExitLoop
    EndIf
    
    $combo = GUICtrlRead($Combo_1)
    If $combo = "Send1"  Then
        $type = "test1"
    ElseIf $combo = "send2"  Then
        $type = "test2"
    ElseIf $combo = "send3"  Then
        $type = "test3"
    EndIf
        
WEnd

Share this post


Link to post
Share on other sites

thx for the help all its working :P

#include <GuiConstants.au3>
HotKeySet("{NUMPAD0}", "rr")
HotKeySet("{NUMPAD1}", "Stop")
GUICreate("MyGUI", 309, 73)
$Combo_1 = GUICtrlCreateCombo("Send1", 10, 30, 180, 21)
GUICtrlSetData (-1, "Send2|Send3")
Global $type = "send1" , $type = "send2" , $type = "send3"

Func rr()
    Send ($type)
EndFunc

Func Stop()
    $kill = 0
    EndFunc

GUISetState()
While 1
    $msg = GUIGetMsg()
    if $msg = $GUI_EVENT_CLOSE Then
        ExitLoop
    EndIf
    
    $combo = GUICtrlRead($Combo_1)
    If $combo = "Send1"  Then
        $type = "test1"
    ElseIf $combo = "send2"  Then
        $type = "test2"
    ElseIf $combo = "send3"  Then
        $type = "test3"
    EndIf
        
WEnd
I don't know how because

Global $type = "send1" , $type = "send2" , $type = "send3"

is

Global $type = "send3"

All you do there is set the value of $type first to "send1" then to "Send2" then to "send3"

It's still the same variable and a variable can only hold 1 value at a time.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

I don't know how because

Global $type = "send1" , $type = "send2" , $type = "send3"

is

Global $type = "send3"

All you do there is set the value of $type first to "send1" then to "Send2" then to "send3"

It's still the same variable and a variable can only hold 1 value at a time.

so how can i make the rr func to 3 variables func.?

Share this post


Link to post
Share on other sites

What? It works fine for me now, actually. I don't get why there's a stop command, because it's designed to only display the text once, it's not looping. The only loop is for the GUI itself.

You can take that line GEO mentions out completely, though. This one:

Global $type = "send1" , $type = "send2" , $type = "send3"

It's not doing much of anything.

Share this post


Link to post
Share on other sites

Hmm.

I started to fix things but then I gave up

...

the whole thing is a mess. i give up already .

You give up too soon. Let's see if we can sort this out for you.

Both the examples below will send keystrokes depending on what has been selected in the combo box.

In Example 1 I've tried to keep as much of your original script as possible.

In Example 2 I've made it simpler by putting the text to be sent in the combo box list. If all you want to send is standard alphanumeric key, doing it this way is simpler. Choose the method that works best for you.

EXAMPLE 1

#include <GuiConstantsEx.au3>
HotKeySet("{NUMPAD0}", "rr")

Global $type = ''
Global $combo = ''
Global $msg = 0

GUICreate("MyGUI", 309, 73)
Global $Combo_1 = GUICtrlCreateCombo("Send1", 10, 30, 180, 21)
GUICtrlSetData (-1, "Send2|Send3")
GUISetState()


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Combo_1
            $combo = GUICtrlRead($Combo_1)
            If $combo = "Send1"  Then
                $type = "test1'"
            ElseIf $combo = "send2"  Then
                $type = "test2'"
            ElseIf $combo = "send3"  Then
                $type = "test3'"
            EndIf
    EndSelect
WEnd

Func rr()
    Send($type)
EndFuncoÝ÷ ØEÀ0òÄÙ«­¢+Ø¥¹±Õ±ÐíÕ¥
½¹ÍѹÑÍà¹ÔÌÐì)!½Ñ-åMÐ ÅÕ½Ðíí9U5AÁôÅÕ½Ðì°ÅÕ½ÐíÉÈÅÕ½Ðì¤()±½°ÀÌØíÑåÁôÌäìÌäì)±½°ÀÌØíµÍôÀ()U%
ÉÑ ÅÕ½Ðí5åU$ÅÕ½Ðì°ÌÀä°Ṳ̈(ÀÌØí
½µ½|ÄôU%
Ñɱ
ÉÑ
½µ¼ ÅÕ½ÐíM¹ÄÅÕ½Ðì°ÄÀ°ÌÀ°ÄàÀ°ÈĤ)U%
ÑɱMÑÑ ´Ä°ÅÕ½ÐíÑÍÐÄÌäíñÑÍÐÈÌäíñÑÍÐÌÌäìÅÕ½Ðì°ÅÕ½ÐíÑÍÐÄÌäìÅÕ½Ðì¤)U%MÑMÑÑ ¤()]¡¥±Ä(ÀÌØíµÍôU%Ñ5Í ¤(%M±Ð($%
ÍÀÌØíµÍôÀÌØíU%}Y9Q}
1=M($$%á¥Ñ1½½À($%
ÍÀÌØíµÍôÀÌØí
½µ½|Ä($$$ÀÌØíÑåÁôU%
ÑɱI ÀÌØí
½µ½|Ĥ(%¹M±Ð)]¹()Õ¹ÉÈ ¤(M¹ ÀÌØíÑåÁ¤)¹Õ¹

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

so how can i make the rr func to 3 variables func.?

Actually now I do see why it worked

Change

Global $type = "send1" , $type = "send2" , $type = "send3"

to

Global $type = "test1"

Change the while loop to

While 1
    $msg = GUIGetMsg()
    Switch $Msg
       Case $GUI_EVENT_CLOSE
        ExitLoop
       Case $Combo
         Switch GUICtrlRead($Msg)
            Case "send2"
               $type = "test2"
            Case "send3"
               $type = "test3"
            Case Else
               $type = "test1"
          EndSwitch
    EndSwitch
        
WEnd

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

You give up too soon. Let's see if we can sort this out for you.

Both the examples below will send keystrokes depending on what has been selected in the combo box.

In Example 1 I've tried to keep as much of your original script as possible.

In Example 2 I've made it simpler by putting the text to be sent in the combo box list. If all you want to send is standard alphanumeric key, doing it this way is simpler. Choose the method that works best for you.

can you please explain me why $msg = 0?

Share this post


Link to post
Share on other sites

can you please explain me why $msg = 0?

You don't really need that line unless the GUI is being run inside of a function and you need to reference $Msg outside of that function.

As it stands right now $msg is already being declared Globally with $Msg = GUIGetMsg() and in either case it does not need the value of "0"

Global $Msg will do the same thing if you are running the GUI inside a function.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

can you please explain me why $msg = 0?

It's good practice to initialise variables to a known value when declaring then so you don't get any nasty surprises later. Numeric variables are normally initialised to 0 and string variables to ''. In AutoIt this is not really necessary as I believe it dose it for you, but it is still a good idea to do it.

setting $msg = 0 means that when the script starts $msg does not accidentally have some value that your script may inerperate as a valid message.

Hope this helps.

Happy codeing


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

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