Currently I’m trying to fill a 3×3 square with random x’s and o’s to make a tic tac toe
game. Unfortunately the game doesn’t seem to output all the x’s and o’s. Logically, from what I can see, it should be able to but it’s not. Any help would be appreciated.
Shared Sub twodimension()
Dim tic(2, 2) As String
Dim min As Integer
Dim x As String
Dim random As New Random()
Dim i As Integer
Dim x1 As Integer
Dim bound0 As Integer = tic.GetUpperBound(0)
Dim bound1 As Integer = tic.GetLowerBound(1)
For i = 0 To bound0
For x1 = 0 To bound1
min = random.Next(2)
If min = 0 Then
x = "x"
Console.WriteLine("{0}", x)
Else
x = "o"
Console.WriteLine("{0}", x)
End If
Console.Write(" "c)
Next
Console.WriteLine()
Next
End Sub
So presumably you’ve got this declaration somewhere, right?
In your code you’ve got
GetLowerBoundwhich will (almost) always returns zero and instead you should haveGetUpperBound().EDIT (in response to comment)
GetUpperBound(int)returns the highest number that you can use for the dimension that you specify.So for the following array:
GetLowerBound(int)returns the lowest number that you can use for the dimension that you specify. In almost every case this is zero but in older versions of VB (and using some COM interop) you can create arrays that don’t “start” at zero and instead start at whatever you wanted. So in old VB you could actually sayDim Bob(1 To 4) As IntegerandGetLowerBound(0)would return1instead of0. For the most part there is no reason to even be aware thatGetLowerBoundexists even.