VBA中的动态数组



我学习编程逻辑与VBA和我试图做一个数组,但我有一个错误在运行


Dim auxTexto As String
Dim auxNumero As Long
Dim auxIterador As Integer
Dim auxArrayEstatico(0 To 5) As Integer
Dim auxArrayDinamico As String

Sub prueba()
auxTexto = "Hola"
auxNumero = 1

auxArrayEstatico(0) = 2
auxArrayEstatico(1) = 2
auxArrayEstatico(2) = 2
auxArrayEstatico(3) = 2
auxArrayEstatico(4) = 2

MsgBox ("Valor de Array en posicion 3 es " & auxArrayEstatico(3))

ReDim auxArrayDinamico(0 To 3)
auxArrayDinamico(0) = "Hola"

MsgBox (auxArrayDinamico(0))

End Sub

错误提示"编译错误,期望是数组";拜托,有人能帮帮我吗?

删除了"作为字符串",也移动了sub中的变量。

为了更快的调试,尝试用debug.print "hola"...代替msgbox "hola"...。这将把文本发送到即时窗口,以便快速查看。

Option Explicit
Sub prueba()
Dim auxTexto As String
Dim auxNumero As Long
Dim auxIterador As Integer
Dim auxArrayEstatico(0 To 5) As Integer
Dim auxArrayDinamico
auxTexto = "Hola"
auxNumero = 1

auxArrayEstatico(0) = 2
auxArrayEstatico(1) = 2
auxArrayEstatico(2) = 2
auxArrayEstatico(3) = 2
auxArrayEstatico(4) = 2

MsgBox ("Valor de Array en posicion 3 es " & auxArrayEstatico(3))

ReDim auxArrayDinamico(0 To 3)
auxArrayDinamico(0) = "Hola"

MsgBox (auxArrayDinamico(0))

End Sub

最新更新