Ichiban Ichiban - 1 month ago 5
Vb.net Question

Error in Visual Basic and I have no idea why

First of all i'm french so excuse me if i make some mistakes

I begin in Visual Basic, i have been in class since 2 months and i have my first "big" project at the university

My module is the following:

Public Function CanPlay(ByVal i As Integer) As Boolean

Dim possible As Boolean
Dim t() As Integer

For i = 1 to 6
If t(i) = 0 Then
possible = False
Else possible = True

Next i
Return possible

End Function


I am creating a game named Kalaha and need to say if a player can play or not, if t(i) is equal to 0 on all his cases, player can't play
But my first " t(i) = 0" doesn't work, he underlined it in green and say there is no value assigned for t but i just declared it at the beginning ...

Answer

The attempt to declare the array of "t" is incorrect and no attempt was made to initialize it with values.

The following line can be used to both declare and initialize the array.

Dim t As Integer() = New Integer() {0, 0, 1, 2, 3, 4, 5 }

Also note that VB.NET uses zero based arrays, so your first array value is t(0).