Jump to content

Need help with relatively easy script


Recommended Posts

Well I just want to make a random number generator... But I hate the way GUI's work in AutoIt!

Here is what I threw together, but it doesn't work.

GUICreate("Random number generator", 300, 80)

GUISetState (@SW_SHOW)

$labl = GUICtrlCreateLabel ("Generate random numbers", 10, 30, 250, 25)

$generate = GUICtrlCreateButton ("generate", 225, 30, 50)

while 1

GUICtrlSetOnEvent ( $generate, "genrandom" )

wend

Func genrandom()

$nmb = Random(0, 100, 1)

GUICtrlSetData ( $labl, $nmb )

EndFunc

The idea is that there will be a command button and a label. Each time you click the command button the label displays a new random number.

Link to comment
Share on other sites

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

GUICreate("Random number generator", 300, 80)

$labl = GUICtrlCreateLabel ("Generate random numbers", 10, 30, 100, 25)
$generate = GUICtrlCreateButton ("generate",170, 30, 50 , 25)
GUICtrlSetOnEvent (-1, "genrandom" )
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

GUISetState (@SW_SHOW)

while 1
    Sleep(10)
wend

Func genrandom()
    $nmb = Random(0, 100, 1)
    GUICtrlSetData ( $labl, $nmb )
EndFunc

Func CLOSEClicked()
    Exit
EndFunc

You needed the guiconstants included and set the onclick mode first.

Also your label was too big so it covered the button making it unclickable.

This code works but the placement of controls could be better.

enjoy

Link to comment
Share on other sites

Well why using onEventMode?

#include <GUIConstants.au3>

GUICreate("Random number generator", 300, 80)

$labl = GUICtrlCreateLabel ("Generate random numbers", 10, 30, 100, 25)
$generate = GUICtrlCreateButton ("generate",170, 30, 50 , 25)

GUISetState (@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    Switch $msg
        Case $generate
            $nmb = Random(0, 100, 1)
            GUICtrlSetData ( $labl, $nmb )
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

I think its easier and window can be closed by klicking on the "X" of the window :)

And if you hate the way of GUI's in AutoIT . WHy you use it then? Thats the biggest point for autoIT i think..

Edited by Daniel W.

--------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote]

Link to comment
Share on other sites

I like using OnEvent mode because most of my scripts are non gui that react to hotkeys which is set up in a similar way.

Yours does look simpler though.

I added in the CloseCLICKED function which I copied from the helpfile to make the x work.

I agree that the Gui is one of the strong points. With two modes each to his own.

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