2 Replies - 653 Views - Last Post: 08 May 2013 - 05:32 PM Rate Topic: -----

#1 hurdlinghurdles  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-May 13

Need help with simple guess/lottery program

Posted 08 May 2013 - 02:56 PM

Hi,

I just started learning my first language, Visual Basic and am currently working on a lottery program. The program generates 10 winning numbers from 101-200 and then compares to a number the user input into a textbox to see if the user's number was a winning number. My problem is that I need to allow the user 5 guesses before a new set of winning numbers is generated and I do not know how to do this.

My code so far: https://gist.github....5ace55a78476fd9
'Public Array
Dim intLotNums(9) As Integer

'RNG Code
Dim intNewNum As Integer
Dim mGenRand As Random = New Random
Dim intCount As Integer = 0



        For i = LBound(intLotNums) To UBound(intLotNums)
            intNewNum = mGenRand.Next(intLowLmt, intUpLmt + 1)
            intLotNums(intCount) = intNewNum
            intCount += 1
        Next

        For intCount = 0 To 9
            Debug.WriteLine(intLotNums(intCount))
        Next

'Test guess code
Dim dblGuessNum As Double = CDbl(txtGuessNumber.Text)

    For i = LBound(intLotNums) To UBound(intLotNums)
      If dblGuessNum = CDbl(intLotNums(i)) Then
        MsgBox("Congratulations you won the lottery!")
      End If
    Next



intUpLmt and intLowLmt are both constants set to the lowest and highest possible values of the lottery numbers.

The form itself has a txtbox, a "play" button, a reset button and a quit button.
Thank you for any help.

This post has been edited by Atli: 08 May 2013 - 03:13 PM
Reason for edit:: Please post your code here, in [code] tags, rather than linking to them elsewhere. Links tend not to last.


Is This A Good Question/Topic? 0
  • +

Replies To: Need help with simple guess/lottery program

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3243
  • View blog
  • Posts: 10,882
  • Joined: 12-December 12

Re: Need help with simple guess/lottery program

Posted 08 May 2013 - 03:27 PM

You could use another variable:

Dim intGuesses As Integer = 0

and just increase this after every guess, checking if it reaches 5.

Quote

I just started learning my first language

I like the enthusiasm that this implies :)
Was This Post Helpful? 1
  • +
  • -

#3 hurdlinghurdles  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-May 13

Re: Need help with simple guess/lottery program

Posted 08 May 2013 - 05:32 PM

Thank you that worked nicely!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1