VBA阵列基础知识 - 动态还是静态? [英] VBA array basics - dynamic or static?
问题描述
我需要创建一个基本的一维字符串数组,但我不知道
在代码完成循环之前我将拥有多少个字符串。 />
伪代码:
Dim astrMyArray()
请勿rst.EOF
i = i + 1
如果rst!Something = [某些条件]然后
astrMyArray(i)= rst!Something
结束如果
循环
ReDim astrMyArray(1到i)
第一个例如,我使用的实际循环是不同的,但
这个想法就是其中之一。
如何创建这个基本阵列?
我'一直在寻找关于VBA阵列的一些好的教程,但是没有找到
任何...
提前致谢。
I need to create a basic one-dimensional array of strings, but I don''t know
how many strings I''m going to have until the code is finished looping.
pseudo code:
Dim astrMyArray()
Do While Not rst.EOF
i = i + 1
If rst!Something = [some condition] Then
astrMyArray(i) = rst!Something
End if
Loop
ReDim astrMyArray(1 to i)
The rst is just for example, the actual loop I am using is different, but
the idea is the some.
How do I create this basic Array?
I''ve been looking for some good tutorials on VBA Arrays, but haven''t found
any...
Thanks in advance.
推荐答案
Dim astrMyArray()
虽然不是rst.EOF
i = i + 1
如果是rst!某事= [某种情况]那么
ReDim astrMyAr ray(1到i)
astrMyArray(i)= rst!Something
结束如果
Wend
2005年3月2日星期三17:13:11 GMT,deko <德** @ hotmail.com>写道:
Dim astrMyArray()
While Not rst.EOF
i = i + 1
If rst!Something = [some condition] Then
ReDim astrMyArray(1 to i)
astrMyArray(i) = rst!Something
End if
Wend
On Wed, 02 Mar 2005 17:13:11 GMT, "deko" <de**@hotmail.com> wrote:
我需要创建一个基本的一维字符串数组,但我不知道
我将要拥有多少个字符串,直到代码完成循环。
伪代码:
昏暗的astrMyArray()
做的不是rst.EOF
i = i + 1 >如果是rst!东西= [某种情况]然后
astrMyArray(i)= rst!东西
结束如果
循环
ReDim astrMyArray(1到i)
<例如,第一个例子,我使用的实际循环是不同的,但是这个想法是一些。
如何创建这个基本数组?
我一直在寻找关于VBA阵列的一些很好的教程,但是没有找到
任何......
提前致谢。
I need to create a basic one-dimensional array of strings, but I don''t know
how many strings I''m going to have until the code is finished looping.
pseudo code:
Dim astrMyArray()
Do While Not rst.EOF
i = i + 1
If rst!Something = [some condition] Then
astrMyArray(i) = rst!Something
End if
Loop
ReDim astrMyArray(1 to i)
The rst is just for example, the actual loop I am using is different, but
the idea is the some.
How do I create this basic Array?
I''ve been looking for some good tutorials on VBA Arrays, but haven''t found
any...
Thanks in advance.
> Dim astrMyArray()
> Dim astrMyArray()
虽然不是rst.EOF
i = i + 1
如果是rst!Something = [某些条件]那么
ReDim astrMyArray (1到i)
astrMyArray(i)= rst!东西
结束如果
Wend
While Not rst.EOF
i = i + 1
If rst!Something = [some condition] Then
ReDim astrMyArray(1 to i)
astrMyArray(i) = rst!Something
End if
Wend
感谢您的回复。
所以我只是在每次迭代时重新编写它?好吧,但是那时似乎
数组并不是真正的动态 - 这只是vb做阵列的方式吗?
Thanks for the reply.
so I just redim it every iteration? fine with me, but then it seems the
array is not really dynamic - is this just the way vb does arrays?
好的......但是如何返回数组值?
为什么Debug.Print只返回string9? ?
公共功能测试()
Dim i As Integer
Dim j As Integer
Dim s As String
Dim astr()As String
Do while i< 10
如果我> 5然后
ReDim astr(1到i)
s =" string" &安培;我
astr(i)= s
结束如果
i = i + 1
循环
for j = LBound(astr)To UBound(astr)
Debug.Print astr(j)<< ===== * * *
下一页
结束功能
Okay... but how do I return the array values?
Why does Debug.Print only return "string9" ?
Public Function test()
Dim i As Integer
Dim j As Integer
Dim s As String
Dim astr() As String
Do While i < 10
If i > 5 Then
ReDim astr(1 To i)
s = "string" & i
astr(i) = s
End If
i = i + 1
Loop
For j = LBound(astr) To UBound(astr)
Debug.Print astr(j) <<===== * * *
Next
End Function
这篇关于VBA阵列基础知识 - 动态还是静态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!