Reputation: 1920
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
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
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