gihansalith
gihansalith

Reputation: 1920

insert multiple values into an array in VB 6.0

I need to insert unique values once into an array without looping like below statement(I'm using visual basic 6.0)

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

but it has got compile error. how should be changed above statement ??

Upvotes: 1

Views: 2653

Answers (2)

C-Pound Guru
C-Pound Guru

Reputation: 16358

From Alex K's answer, but converted to 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

Usage:

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

Upvotes: 2

gihansalith
gihansalith

Reputation: 1920

this is the easier way that I could found

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

Upvotes: 0

Related Questions