• We just launched and are currently in beta. Join us as we build and grow the community.

Rolling Numbers Game in Visual Basic 2008

ethwhwter4s

Mobile App Auditor
E Rep
0
0
0
Rep
0
E Vouches
0
0
0
Vouches
0
Posts
105
Likes
65
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 500 XP
This time I will teach you how to create Rolling Numbers Game in Visual Basic 2008. In these features the numbers are rolled randomly and it has a Progress Bar that serves as a timer.

Let's begin:

Open the Visual Basic 2008, create a Windows Application and do the Form just like this.

first_1.png


Double click the Timer and do the following code. The event is, everytime the timer ticks, the numbers in the Textbox will randomly roll. And if the progress bar reached its maximum value, the timer and the number in the Textbox will stop.

  1. Private

    Sub

    Timer1_Tick(

    ByVal

    sender As

    System.

    Object

    , ByVal

    e As

    System.

    EventArgs

    )

    Handles

    Timer1.

    Tick

  2. 'DECLARING A RANDOM VARIABLE TO STORE THE NUMBERS ON IT.
  3. 'IT REPRESENTS A PSUEDO RANDOM GENERATOR.
  4. Dim

    num As

    Random =

    New

    Random(

    )
  5. 'DECLARING AN INTEGER VARIABLE TO STORE THE NONNEGATIVE RANDOM NUMBERS.
  6. 'STARTS WITH THE MINIMUM VALUE TO THE MAXIMUM VALUE
  7. 'NEXT REPRESENTS TO RETURN A RANDOM NUMBER WITHIN A SPECIFIED RANGE.
  8. Dim

    result As

    Integer

    =

    num.

    Next

    (

    1

    , 7

    )
  9. 'PUT THE RESULT IN THE TEXTBOX.
  10. TextBox1.

    Text

    =

    result.

    ToString
  11. 'PROGRESSBAR INCREASED BY 1.
  12. ProgressBar1.

    Value

    +=

    1
  13. 'THE CONDITION IS, WHEN THE PROGRESSBAR VALUE REACHED TO 100
  14. 'THEN THE TIMER WILL STOP AND THE NUMBER IN THE TEXTBOX WILL STOP ROLLING TOO.
  15. If

    ProgressBar1.

    Value

    =

    100

    Then
  16. 'FILTERING THE CHECKBOX.
  17. 'IF THE CHECKBOX1 IS CHECKED THE MESSAGE WILL APPEAR IN THE LISTBOX.
  18. If

    CheckBox1.

    CheckState

    =

    CheckState.

    Checked

    Then
  19. If

    TextBox1.

    Text

    =

    CheckBox1.

    Text

    Then
  20. 'ADD THE STRING MESSAGE IN THE LISTBOX.
  21. ListBox1.

    Items

    .

    Add

    (

    "The number "

    &

    TextBox1.

    Text

    &

    " won!"

    )
  22. End

    If
  23. End

    If

  24. If

    CheckBox2.

    CheckState

    =

    CheckState.

    Checked

    Then
  25. If

    TextBox1.

    Text

    =

    CheckBox2.

    Text

    Then
  26. ListBox1.

    Items

    .

    Add

    (

    "The number "

    &

    TextBox1.

    Text

    &

    " won!"

    )
  27. End

    If
  28. End

    If
  29. If

    CheckBox3.

    CheckState

    =

    CheckState.

    Checked

    Then
  30. If

    TextBox1.

    Text

    =

    CheckBox3.

    Text

    Then
  31. ListBox1.

    Items

    .

    Add

    (

    "The number "

    &

    TextBox1.

    Text

    &

    " won!"

    )
  32. End

    If
  33. End

    If

  34. If

    CheckBox4.

    CheckState

    =

    CheckState.

    Checked

    Then
  35. If

    TextBox1.

    Text

    =

    CheckBox4.

    Text

    Then
  36. ListBox1.

    Items

    .

    Add

    (

    "The number "

    &

    TextBox1.

    Text

    &

    " won!"

    )
  37. End

    If
  38. End

    If

  39. If

    CheckBox5.

    CheckState

    =

    CheckState.

    Checked

    Then
  40. If

    TextBox1.

    Text

    =

    CheckBox5.

    Text

    Then
  41. ListBox1.

    Items

    .

    Add

    (

    "The number "

    &

    TextBox1.

    Text

    &

    " won!"

    )
  42. End

    If
  43. End

    If

  44. If

    CheckBox6.

    CheckState

    =

    CheckState.

    Checked

    Then
  45. If

    TextBox1.

    Text

    =

    CheckBox6.

    Text

    Then
  46. ListBox1.

    Items

    .

    Add

    (

    "The number "

    &

    TextBox1.

    Text

    &

    " won!"

    )
  47. End

    If
  48. End

    If

  49. If

    CheckBox7.

    CheckState

    =

    CheckState.

    Checked

    Then
  50. If

    TextBox1.

    Text

    =

    CheckBox7.

    Text

    Then
  51. ListBox1.

    Items

    .

    Add

    (

    "The number "

    &

    TextBox1.

    Text

    &

    " won!"

    )
  52. End

    If
  53. End

    If
  54. Timer1.

    Stop

    (

    )
  55. End

    If

  56. End

    Sub

Go back to the Design Views, double click the Button and do the following code for starting the timer and assigning the Progress Bar of a minimum value.

  1. Private

    Sub

    btnRoll_Click(

    ByVal

    sender As

    System.

    Object

    , ByVal

    e As

    System.

    EventArgs

    )

    Handles

    btnRoll.

    Click
  2. 'CLEARING THE LISTBOX
  3. ListBox1.

    Items

    .

    Clear

    (

    )
  4. 'timer starts
  5. Timer1.

    Start

    (

    )
  6. 'PROGRESSBAR VALUE RETURNS TO 0 EVERYTIME YOU CLICK THE BUTTON
  7. ProgressBar1.

    Value

    =

    0
  8. End

    Sub

The complete source code is included and you can dowload it.


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

452,292

324,242

324,250

Top