I want a function to return an array but I get a compiler error: 'Cannot assign to an array' The code is this:
Private Function función1()
Dim resultado(1) As Integer
resultado = función2(1,1) 'Se produce el error: no se puede asignar a una matriz'
End Function
Private Function función2(Referencia, Cantidad) As Integer()
Dim resultado(1) As Integer
resultado(0) = referencia * 2
resultado(1) = cantidad * 4
función2 = resultado
End Function
I am using access 2007
Test:
Removing the trailing parentheses from the function's return type. Adds the type to the arguments.
First of all, if you define your variable in a module outside of any procedure or function, just below
Option Explicit
, you will have the variable defined in all your procedures, and you don't have to define it all the time. Try this: Insert a standard module, delete everything and copy and paste.Now, every time you run the sub
Actualizar_Resultado
, your Result array will be updated based on the numbers you entered in Reference and Amount.