Hi there,
I'd like to submit this program I'm working on to thr forum.
I want to display 6 randomly generated numbers on 6 command buttons as captions at the click of another button. One number will be selected only once.
Here's my code:
I'm getting an error message
at the beginning where I'm declaring and initializing the array of integers x(0)
Can anyone help please.
Thanks
I'd like to submit this program I'm working on to thr forum.
I want to display 6 randomly generated numbers on 6 command buttons as captions at the click of another button. One number will be selected only once.
Here's my code:
Code:
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim x As Integer() = New Integer() {x(0), x(1), x(2), x(3), x(4), x(5)} Dim m_blnUsed As Boolean() = _ New Boolean(x.GetUpperBound(0)) {} Dim objrandom As Random = New Random() Dim intrandom As Integer Do intrandom = objrandom.Next(0, m_blnUsed.Length) Loop Until m_blnUsed(intrandom) = False m_blnUsed(intrandom) = True Dim index As Integer For index = 0 To 5 x(index) = x(intrandom) Next Button3.Text = Str(x(0)) Button4.Text = Str(x(1)) Button5.Text = Str(x(2)) Button6.Text = Str(x(3)) Button7.Text = Str(x(4)) Button8.Text = Str(x(5)) End Sub End Class
variable 'x' is used before it has been assigned a value. A null reference exception could result at runtime.
Can anyone help please.
Thanks
Comment