PhuongM
#1
I was thrown an error when trying to recall the value stored in an array, see code below. What am I missing here?
Public XS2RunList as Variant
Public nXS as long
Sub XS2Run
Dim i as long
Dim XS2RunList = VarArrayCreate([1, nXS],12)
For i = 1 to nXS
XS2RunList[i] = i
Next
Msgbox (XS2RunList[1])
End Sub
Sub MAIN_XP (Param1)
nXS = 3
XS2Run
Msgbox (XS2RunList[1])
End Sub
Maybe XS2RunList isn’t shared between subs correctly. We’ll check that.
PhuongM
#3
I’ve found the culprit for the error. The use of DIM for VarArrayCreate makes this var local.
I removed that DIM and it works. The full code is below.
Public XS2RunList as Variant
Public nXS as long
Sub XS2Run
Dim i as long
XS2RunList = VarArrayCreate([1, nXS],12)
For i = 1 to nXS
XS2RunList[i] = i
Next
Msgbox (XS2RunList[1])
End Sub
Sub MAIN_XP (Param1)
nXS = 3
XS2Run
Msgbox (XS2RunList[1])
End Sub