Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function that returns a two dimensional array

Status
Not open for further replies.

jwestmore

Programmer
May 27, 2003
14
US
I'm trying to build a function that creates and returns a populated two-dimensional array based on function parameters. I'm receiving a "Can't assign to array" error with the following code. Any suggestions on how to make this work correctly? Thanks in Advance, Jon.

Dim Board() As Integer

Private Sub Form_Load()
Board() = LoadB(4, 4)
End Sub

Function LoadB(x As Integer, y As Integer) As Integer
Dim b() As Integer
Dim i As Integer, j As Integer, size As Integer
ReDim b(x, y) As Integer

size = 0
For j = 0 To x - 1
For i = 0 To y - 1
b(i, j) = size
size = size + 1
Next i
Next j

LoadB = b
End Function
 
Never mind, I've got it, forgot the parentheses on the function return data type:

Dim Board() As Integer

Private Sub Form_Load()
Board() = LoadB(4, 4)
End Sub

Function LoadB(x As Integer, y As Integer) As Integer()
Dim b() As Integer
Dim i As Integer, j As Integer, size As Integer
ReDim b(x, y) As Integer

size = 0
For j = 0 To x - 1
For i = 0 To y - 1
b(i, j) = size
size = size + 1
Next i
Next j

LoadB = b
End Function

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top