Jump to content
Sign in to follow this  
0_00_0

[Help Needed]Basic Random Numbers

Recommended Posts

0_00_0

Hello There!

I'm basically trying to make a string of x random numbers from 0-9. For example: genCode(4) could generate 3942. The problem I'm having now is that it just adds them togeather. I'm looking for a concat, or sprintf equivalent in autoIT.

func genCode($length)
    $code = String("")
    $tempRand=0
    $count = 0
    
    while $length > $count
        $tempRand=Random(0, 9)
        $code = String($code) + String($tempRand)
        $count = $count + 1
    WEnd
    
    return $code
EndFunc

Share this post


Link to post
Share on other sites
Valuater

Random(0, 9, 1)

If this is set to 1 then an integer result will be returned. Default is a floating point number.

... if you want 0-9 whole numbers

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
0_00_0

ok thanks a bunch that worked. Aside from generating anywhere from (x-2)->(x) numbers, but this isn't a huge issue right now. Just another quick question, I didn't want to start a whole new topic on it.

Whenever I add a background picture to my GUI it disables all my controls. Here is my GUI code:

#include <GUIConstants.au3>
#include <String.au3>

$width = 250
$height = 225

$hGui = guicreate("Generator", $width, $height)
guisetstate(@SW_SHOW)

;this line give mah GUI errorZ!
guictrlcreatepic("bk.jpg", 0, 0, $width, $height)

$hNum1 = guictrlcreateinput("0123", 15, 70, 35, 25)
$hNum2 = guictrlcreateinput("012345", 55, 70, 45, 25)
$hNum3 = guictrlcreateinput("01234", 105, 70, 40, 25)
$hNum4 = guictrlcreateinput("012345", 150, 70, 45, 25)
$hNum5 = guictrlcreateinput("0123", 200, 70, 35, 25)

$hGenNum1 = guictrlcreateinput("0000", 15, 130, 35, 25)
$hGenNum2 = guictrlcreateinput("000000", 55, 130, 45, 25)
$hGenNum3 = guictrlcreateinput("00000", 105, 130, 40, 25)
$hGenNum4 = guictrlcreateinput("000000", 150, 130, 45, 25)
$hGenNum5 = guictrlcreateinput("0000", 200, 130, 35, 25)

$genButton = GUICtrlCreateButton("GENERATE", ($width/2)-20, 160)

while 1
    $msg = GUIGetMsg()
    
    if $msg = $GUI_EVENT_CLOSE Then
        Exit
        endif
wEnd

Share this post


Link to post
Share on other sites
Jos

Move the Picture control to the end, its now on top of the other controls.

$hNum1 = guictrlcreateinput("0123", 15, 70, 35, 25)
$hNum2 = guictrlcreateinput("012345", 55, 70, 45, 25)
$hNum3 = guictrlcreateinput("01234", 105, 70, 40, 25)
$hNum4 = guictrlcreateinput("012345", 150, 70, 45, 25)
$hNum5 = guictrlcreateinput("0123", 200, 70, 35, 25)

$hGenNum1 = guictrlcreateinput("0000", 15, 130, 35, 25)
$hGenNum2 = guictrlcreateinput("000000", 55, 130, 45, 25)
$hGenNum3 = guictrlcreateinput("00000", 105, 130, 40, 25)
$hGenNum4 = guictrlcreateinput("000000", 150, 130, 45, 25)
$hGenNum5 = guictrlcreateinput("0000", 200, 130, 35, 25)

$genButton = GUICtrlCreateButton("GENERATE", ($width/2)-20, 160)
guictrlcreatepic("bk.jpg", 0, 0, $width, $height)

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Valuater

Also...

"Background" pictures should always be made first and disabled

guictrlcreatepic("bk.jpg", 0, 0, $width, $height)

guictrlsetstate( -1, $GUI_DISABLE)

this way labels and buttons will function

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
0_00_0

Damn you guys are helpful. I just assumed it would be at the back because I added the other controls after it. Disabling it was definitely the smart thing to do, thats the method I took. I'm sure adding it after works too. Thanks a bunch guys! Thats all my questions for now, feel free to lock it up!

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  

×