在VB 6.0中将多个值插入到数组中

时间:2015-06-24 01:41:05

标签: arrays vb6

我需要将一次唯一值插入到数组中,而不像下面的语句那样循环(我使用的是visual basic 6.0)

Dim Marks(0 To 9) As Integer = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9,}

但它有编译错误。如何改变上述陈述?

2 个答案:

答案 0 :(得分:1)

来自Alex K's answer,但转换为int:

Function ArrayInt(ParamArray tokens()) As Integer()
    ReDim arr(UBound(tokens)) As Integer
    Dim i As Long
    For i = 0 To UBound(tokens)
        arr(i) = tokens(i)
    Next
    ArrayInt = arr
End Function

用法:

Dim Marks() As Integer
Marks = ArrayInt(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)

答案 1 :(得分:0)

这是我找到的更容易的方法

Dim marks 
marks = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)