Results 1 to 2 of 2

Thread: How To Compare Number In Vb, Please Help

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    4

    How To Compare Number In Vb, Please Help

    fgdfdf
    Last edited by chasey1; May 5th, 2006 at 08:51 AM.

  2. #2
    Addicted Member BlueRose's Avatar
    Join Date
    Jan 2002
    Location
    ISTANBUL
    Posts
    245

    Re: How To Compare Number In Vb, Please Help

    Following code generate 6 different numbers between 1 to 49

    VB Code:
    1. Private Sub cmdChoose_Click()
    2. Dim arrNumber(1 To 6) As Integer, m As Integer, k As Integer, isFound As Boolean
    3.  
    4.     Randomize (Timer)
    5.     'generate first number
    6.     arrNumber(1) = GetOneNumber
    7.     k = 2
    8.  
    9.     While (k <= 6)
    10.         arrNumber(k) = GetOneNumber
    11.         ' compare with previous number
    12.         For m = 1 To k - 1
    13.             If arrNumber(m) = arrNumber(k) Then
    14.                 isFound = True
    15.                 Exit For
    16.             End If
    17.         Next m
    18.         'if not the same with previous go to next one otherwise generate again
    19.         If Not isFound Then k = k + 1
    20.     Wend
    21.     'this is just for viewing could be deleted
    22.     For m = 1 To 6
    23.         Print arrNumber(m)
    24.     Next m
    25.    
    26. End Sub
    27.  
    28. Private Function GetOneNumber()
    29.     GetOneNumber = Int(49 * Rnd) + 1
    30. End Function

    you can compare user input with this number and putting a count number for which are the same, you can decide with count number how much the user won.
    Last edited by BlueRose; Apr 23rd, 2006 at 12:24 PM.
    You can do while you think that you can do

    If you think my answer solve your question, please rate it.

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