Public Class Form1
Private bingo(75) As String
Private count As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For x As Integer = 1 To 75
Select Case x
Case 1 To 15
bingo(x) = "B " & x
Case 16 To 30
bingo(x) = "I " & x
Case 31 To 45
bingo(x) = "N " & x
Case 46 To 60
bingo(x) = "G " & x
Case 61 To 75
bingo(x) = "O " & x
End Select
Next x
End Sub
Private Sub btnNewGame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewGame.Click
Dim randnum As New Random()
Dim mix As Integer, temp As String
For x As Integer = 1 To 75
mix = randnum.Next(1, 76)
temp = bingo(mix)
bingo(mix) = bingo(x)
bingo(x) = temp
Next x
count = 0
txtBingo.Clear()
End Sub
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
count += 1
txtBingo.Text = bingo(count)
End Sub
End Class
Private Sub frmBingo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Tag = "B1"
Label2.Tag = "B2"
Label3.Tag = "B3"
Label4.Tag = "B4"
Label5.Tag = "B5"
Label6.Tag = "I1"
Label7.Tag = "I2"
Label8.Tag = "I3"
Label9.Tag = "I4"
Label10.Tag = "I5"
Label11.Tag = "N1"
Label12.Tag = "N2"
Label13.Tag = "N3"
Label14.Tag = "N4"
Label15.Tag = "N5"
Label16.Tag = "G1"
Label17.Tag = "G2"
Label18.Tag = "G3"
Label19.Tag = "G4"
Label20.Tag = "G5"
Label21.Tag = "O1"
Label22.Tag = "O2"
Label23.Tag = "O3"
Label24.Tag = "O4"
Label25.Tag = "O5"
NewCard()
End Sub
Private Sub NewCard()
For Each ctrl As Control In Me.Controls
If TypeOf ctrl Is Label Then
Dim TempLabel As Label = DirectCast(ctrl, Label)
Select Case TempLabel.Tag.ToString()(0)
Case "B"c
TempLabel.Text = TempLabel.Tag.ToString()(0) & rRnd.Next(1, 16).ToString()
Case "I"c
TempLabel.Text = TempLabel.Tag.ToString()(0) & rRnd.Next(16, 31).ToString()
Case "N"c
If TempLabel.Tag.ToString().Substring(1) = "3" Then
TempLabel.Text = "Free"
Else
TempLabel.Text = TempLabel.Tag.ToString()(0) & rRnd.Next(31, 46).ToString()
End If
Case "G"c
TempLabel.Text = TempLabel.Tag.ToString()(0) & rRnd.Next(46, 61).ToString()
Case "O"c
TempLabel.Text = TempLabel.Tag.ToString()(0) & rRnd.Next(61, 76).ToString()
End Select
End If
Next
End Sub
Private Sub btnNewCard_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewCard.Click
NewCard()
End Sub
Array will be initialized in the Form Load event. btnNewGame will shuffle the array. btnNext will select a different number each time it's clicked. Click btnNewGame to reshuffle and start over.
VB.NET:Public Class Form1 Private bingo(75) As String Private count As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load For x As Integer = 1 To 75 Select Case x Case 1 To 15 bingo(x) = "B " & x Case 16 To 30 bingo(x) = "I " & x Case 31 To 45 bingo(x) = "N " & x Case 46 To 60 bingo(x) = "G " & x Case 61 To 75 bingo(x) = "O " & x End Select Next x End Sub Private Sub btnNewGame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewGame.Click Dim randnum As New Random() Dim mix As Integer, temp As String For x As Integer = 1 To 75 mix = randnum.Next(1, 76) temp = bingo(mix) bingo(mix) = bingo(x) bingo(x) = temp Next x count = 0 txtBingo.Clear() End Sub Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click count += 1 txtBingo.Text = bingo(count) End Sub End Class
Private Sub btnRandom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRandom.Click
Randomize()
txtRandom.Text = Int(Rnd() * 75)
End Sub