Home > Software engineering >  A () function returns an array of simple example cannot compile, solving
A () function returns an array of simple example cannot compile, solving

Time:10-17

 Public Function arrayfunction (I As an Integer) As an Integer () 
Dim x (2) As an Integer
X (0)=I + 10
(1)=I + 20 x
Arrayfunction=x 'x assignment to function arrayfunction
End the Function
Private Sub Command1_Click ()
Dim y (2) As an Integer
Y=arrayfunction (1)
MsgBox y (0)
MsgBox y (1)
End Sub

Compile error, cannot be assigned to an array, why ah, solve, help solve, four questions 40 points

CodePudding user response:

The Dim y (2) As an Integer into a Dim y () As an Integer

CodePudding user response:

 Option Explicit 

The Public Function arrayfunction (I As an Integer) As an Integer ()
Dim X () As an Integer
ReDim X (1)
X (0)=I + 10
(1)=I + 20 X
Arrayfunction=X 'X assignment to function arrayfunction
End the Function
Private Sub Command1_Click ()
Dim (Y) As an Integer
ReDim Y (UBound (arrayfunction (1)))
Y=arrayfunction (1)
MsgBox Y (0)
MsgBox Y (1)
End Sub