Jump to content

random numbers


Go to solution Solved by jdelaney,

Recommended Posts

Hmm, are you running a GUI in a While loop? There's no GUI or button created in the code you posted. Take a look at some simple GUI examples with buttons. If that doesn't solve your problem, then post the rest of your code so we can see where you are going wrong.

Edited by czardas
Link to comment
Share on other sites

Hmm, are you running a GUI in a While loop? There's no GUI or button created in the code you posted. Take a look at some simple GUI examples with buttons. If that doesn't solve your problem, then post the rest of your code so we can see where you are going wrong.

yes sorry this is the full script:

$random = GUICtrlCreateButton("random", 520, 392, 41, 25)
$Input = GUICtrlCreateInput("", 560, 392, 49, 21)

case $random
    $random = Random(0, 1000,1)
    GUICtrlSetData($Input,$random)

and it work but when i hit the random button I get the number 547 ( for example) and when  i hit the button agian I get the number 547  it stays on the same number and i dont want that

Edited by Arclite86
Link to comment
Share on other sites

Im now trying to do something like this:

$random = GUICtrlCreateButton("random", 520, 392, 41, 25)
$Input = GUICtrlCreateInput("", 560, 392, 49, 21)

case $random
    Local $i = 1
While $i
$random = Random(0, 1000,1)
    GUICtrlSetData($Input7,$random)
WEnd

but when i push the button now the numbers in the input are going crazy

Edited by Arclite86
Link to comment
Share on other sites

you are defining $random as both a random number and a button name, change the button or the variable name and it will work.

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Random", 1000, 500)
$random = GUICtrlCreateButton("random", 350, 392, 41, 25)
$Input = GUICtrlCreateInput("", 560, 392, 49, 21)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            ExitLoop
        Case $random
            $random1 = Random(0, 1000, 1)
            GUICtrlSetData($Input, $random1)
    EndSwitch
WEnd
Edited by Palestinian
Link to comment
Share on other sites

Im now trying to do something like this:

$random = GUICtrlCreateButton("random", 520, 392, 41, 25)
$Input = GUICtrlCreateInput("", 560, 392, 49, 21)

case $random
    Local $i = 1
While $i
$random = Random(0, 1000,1)
    GUICtrlSetData($Input7,$random)
WEnd

but when i push the button now the numbers in the input are going crazy

That is NOT a working script, you have a Case statement with no Switch or Select statement around it, your random function is inside the while loop. You've got no GUI to attach this to.

Basically you've screwed up in every possible way and you need to get offline and read the help file and stop posting such nonsense on the forum until you have a grasp of at least the basics of the language.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

That is NOT a working script, you have a Case statement with no Switch or Select statement around it, your random function is inside the while loop. You've got no GUI to attach this to.

Basically you've screwed up in every possible way and you need to get offline and read the help file and stop posting such nonsense on the forum until you have a grasp of at least the basics of the language.

its not about if the script is working, I already told the script works I just dindt shown the whole script

its about this part

 
case $random

    Local $i = 1
While $i
$random = Random(0, 1000,1)
    GUICtrlSetData($Input7,$random)
WEnd

BrewManNh every comment I see of you on my post is only about  the help file, I already told that I have looked at it

Basically you've screwed up in every possible way and you need to get offline and read the help file and stop posting such nonsense on the forum until you have a grasp of at least the basics of the language. 

if you dont like my topics than dont post on it.

Link to comment
Share on other sites

I'd like to fix your code.  It would be litteraly 2 variables.

You are not providing working code though, and I don't want to reinvent the wheel.

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

I'd like to fix your code.  It would be litteraly 2 variables.

You are not providing working code though, and I don't want to reinvent the wheel.

ok here is the full script.

GUICreate("forum", 775, 488, 226, 237)
$random = GUICtrlCreateButton("random", 520, 392, 41, 25)
$Input7 = GUICtrlCreateInput("", 560, 392, 49, 21)


GUISetState(@SW_SHOW)

While 1
   $nMsg = GUIGetMsg()
    Switch $nMsg


case $random


$random = Random(0, 1000,1)
    GUICtrlSetData($Input7,$random)


 EndSwitch
WEnd
Link to comment
Share on other sites

  • Solution

thank you...my 2 variable changes:

GUICreate("forum", 775, 488, 226, 237)
$random_button = GUICtrlCreateButton("random", 520, 392, 41, 25)
$Input7 = GUICtrlCreateInput("", 560, 392, 49, 21)


GUISetState(@SW_SHOW)

While 1
   $nMsg = GUIGetMsg()
    Switch $nMsg


case $random_button


$random = Random(0, 1000,1)
    GUICtrlSetData($Input7,$random)


 EndSwitch
WEnd
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

 

thank you...my 2 variable changes:

GUICreate("forum", 775, 488, 226, 237)
$random_button = GUICtrlCreateButton("random", 520, 392, 41, 25)
$Input7 = GUICtrlCreateInput("", 560, 392, 49, 21)


GUISetState(@SW_SHOW)

While 1
   $nMsg = GUIGetMsg()
    Switch $nMsg


case $random_button


$random = Random(0, 1000,1)
    GUICtrlSetData($Input7,$random)


 EndSwitch
WEnd

Thank you very much Jdelaney :)  :thumbsup:  

Edited by Arclite86
Link to comment
Share on other sites

 

you are defining $random as both a random number and a button name, change the button or the variable name and it will work.

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Random", 1000, 500)
$random = GUICtrlCreateButton("random", 350, 392, 41, 25)
$Input = GUICtrlCreateInput("", 560, 392, 49, 21)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            ExitLoop
        Case $random
            $random1 = Random(0, 1000, 1)
            GUICtrlSetData($Input, $random1)
    EndSwitch
WEnd

 

I suppose that one didn't work for you?

Link to comment
Share on other sites

yes sorry this is the full script:

$random = GUICtrlCreateButton("random", 520, 392, 41, 25)
$Input = GUICtrlCreateInput("", 560, 392, 49, 21)

case $random
    $random = Random(0, 1000,1)
    GUICtrlSetData($Input,$random)

 

 

its not about if the script is working, I already told the script works I just dindt shown the whole script

its about this part

Explain the above post with the quote at the top of this reply. Either that's your whole script or it's not, you can't have it both ways.

 

 
case $random

    Local $i = 1
While $i
$random = Random(0, 1000,1)
    GUICtrlSetData($Input7,$random)
WEnd
BrewManNh every comment I see of you on my post is only about  the help file, I already told that I have looked at it

 

Really? I see no evidence you even have a copy of the help file from the nonsense you keep posting, this topic is just one example of that.

 

Basically you've screwed up in every possible way and you need to get offline and read the help file and stop posting such nonsense on the forum until you have a grasp of at least the basics of the language.

if you dont like my topics than dont post on it.

I'm trying to help the forum out by helping YOU out.

  • Read the help file, really read it not just look up names of functions to use
  • post WORKING code, and not snippets you think explain what you think is the problem
  • Reread the help file when your code doesn't work the first time
  • If you post a question, read the answers you're given because Palestinian explained where part of your problem was

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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