Jump to content
Sign in to follow this  
Jujo

"Annoyer"

Recommended Posts

Jujo

Guys, I need help!

This is supposed to be my very first GUI. I think it is all OK with it (I looked at scripts here at forum, and combined them ;D), but I don't know how to make it repeat action

This "program" is supposed to ask user for data about frequency and duration of "BEEP", and then, using Beep() function, annoy everybody in the room - simple. That is not problem, but when I enter data, and press the 'Annoy' button, it plays Beep, and after that I press the Annoy button again, but nothing happens.

I think it is problem with Switch, but you tell me.

NOTE: I am beginner, so don't laugh at me about this code.

$GUI = GUICreate("Annoyer", 150, 85)

GUICtrlCreateLabel("Frequency:", 20, 8, -1, 15)
$Frequency = GUICtrlCreateInput("1000", 80, 5, -1, 20)

GUICtrlCreateLabel("Duration:", 20, 38, -1, 15)
$Duration = GUICtrlCreateInput("5", 69, 35, 15, 20)
GUICtrlCreateLabel("seconds", 85, 38, -1, 15)

$Annoy = GUICtrlCreateButton("Annoy!", 40, 60, 60, 20)

GUISetState(@SW_SHOW, $GUI)

While 1
    Switch GUIGetMsg()
        Case $Annoy
            $Frequency = GUICtrlRead($Frequency)
            $Duration = GUICtrlRead($Duration) * 1000
           
                Beep($Frequency, $Duration)
                Sleep($Duration)
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites
cageman

you should use new variables for $frequenty and $duration here.

what you do now is giving the inputforms the value of themselves.

probably strange things happen then. so :

While 1
    Switch GUIGetMsg()
        Case $Annoy
            $Frequencybeep = GUICtrlRead($Frequency)
            $Durationbeep = GUICtrlRead($Duration) * 1000
          
                Beep($Frequencybeep, $Durationbeep)
                Sleep($Durationbeep)
    EndSwitch
WEnd
Edited by cageman

Share this post


Link to post
Share on other sites
Achilles

In case you didn't realize the specific problem that cageman told you, here is what happening:

The variable $Frequency is originally stored as the actual control that you created. When you press the annoy button, it reads the data in the $Frequency control, and assigns the data to the variable $Frequency. $Frequency is now a number that does not represent your control. So the next time you press annoy, it can't read the data from the control.


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites
Jujo

Thanks for help :(

I tought it will be problem with same names, but... :P

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.