Hello everyone, I have an array without knowing it's size from the start.
And I need to pass it as an argument in a routine. I can know the actual size before I call the sub, but I don't know how to declare it as an argument, so I am getting error.
Public LonelyChckrs() As Checker
Dim Lonelies As Byte = 0
For i As Byte = 0 To PcCheckerGates.Length - 1
If PcCheckerGates(i).stack.Count = 1 Then Lonelies += 1
Next
Dim ArrayLngth As Byte = Lonelies - 1
ReDim LonelyChckrs(ArrayLngth)
If Lonelies > 0 Then FillArrayWithLonelies(Lonelies, LonelyChckrs(ArrayLngth)) 'here I am getting Error 3
Value of type 'Backgammon.Checker' cannot be converted to '1-dimensional array of Backgammon.Checker'
and here is my routine
I am getting error from the first statement Error 4 Array bounds cannot appear in type specifiers.
Public Sub FillArrayWithLonelies(ByVal Lonelies As Byte, ByVal LonelyChckrs(lonelies-1) As Checker)
Dim j As Byte = 0
For i As Byte = 0 To PcCheckerGates.Length - 1
If PcCheckerGates(i).stack.Count = 1 Then
LonelyChckrs(j) = New Checker
LonelyChckrs(j) = PcCheckerGates(i).stack.Peek
j = j + 1
End If
Next
End Sub
Any suggestions please? Any help will be much appreciated. Thank you so much in advanced.
And I need to pass it as an argument in a routine. I can know the actual size before I call the sub, but I don't know how to declare it as an argument, so I am getting error.
Public LonelyChckrs() As Checker
Dim Lonelies As Byte = 0
For i As Byte = 0 To PcCheckerGates.Length - 1
If PcCheckerGates(i).stack.Count = 1 Then Lonelies += 1
Next
Dim ArrayLngth As Byte = Lonelies - 1
ReDim LonelyChckrs(ArrayLngth)
If Lonelies > 0 Then FillArrayWithLonelies(Lonelies, LonelyChckrs(ArrayLngth)) 'here I am getting Error 3
Value of type 'Backgammon.Checker' cannot be converted to '1-dimensional array of Backgammon.Checker'
and here is my routine
I am getting error from the first statement Error 4 Array bounds cannot appear in type specifiers.
Public Sub FillArrayWithLonelies(ByVal Lonelies As Byte, ByVal LonelyChckrs(lonelies-1) As Checker)
Dim j As Byte = 0
For i As Byte = 0 To PcCheckerGates.Length - 1
If PcCheckerGates(i).stack.Count = 1 Then
LonelyChckrs(j) = New Checker
LonelyChckrs(j) = PcCheckerGates(i).stack.Peek
j = j + 1
End If
Next
End Sub
Any suggestions please? Any help will be much appreciated. Thank you so much in advanced.