Results 1 to 4 of 4

Thread: Random number by button Clicked... accessed in a loop!!

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    1

    Exclamation Random number by button Clicked... accessed in a loop!!

    I was working in a Game in VB, and I was making a Loop that will start when the game begin and end when someone win.

    But then I found a problem:
    I have my main code in the loop and a Randomizer that starts when a button is clicked.
    So my problem is that I can't work whit the random number in my loop.

    How can I access the random number (it as to be choosen after a click of a button) in my loop?!

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Random number by button Clicked... accessed in a loop!!

    The variable would have to be declared at a scope that is visible to both parts of the code. Other than that I can't say without seeing the code.
    My usual boring signature: Nothing

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Random number by button Clicked... accessed in a loop!!

    Quote Originally Posted by AlexCavaco7 View Post
    I was working in a Game in VB, and I was making a Loop that will start when the game begin and end when someone win.
    That sounds wrong for a start. A WinForms app that has a single loop running for the duration of the session? I can't think of a situation where that would be appropriate. WinForms is an event-driven GUI technology. The app should just sit there until the user does something, e.g. clicks a Button. You would handle the Click event and then do something in the event handler.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Random number by button Clicked... accessed in a loop!!

    Typical game loop, actually, though that is usually not in a WinForms app. However, the OP didn't actually say that this WAS WinForms....though it is strongly implied based on a couple statements in there.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width