View Full Version : max items in Array
altrox5
10-06-2015, 10:34 AM
why i cant make (Array arr1() = Array(examle string,string2 etc....) in one line??
the point is that when too many strings in one line does not fit , and the program not working
so how to move the bracket to the next line ?
Kenneth Hobs
10-06-2015, 12:21 PM
It has to do with memory. For details about line continuation limits see: https://msdn.microsoft.com/en-us/library/office/gg264236.aspx
I would normally use a string array and use string concatenation if I were to build a large array that hit that limit.
Option Explicit
Sub ken()
Dim a() As Variant, s As String, v As Variant, ss() As String
s = "a,b"
s = s & ",c,d,55"
ss() = Split(s, ",")
For Each v In ss()
Debug.Print v
Next v
Debug.Print vbLf
a() = Array("aa", "bb", "cc", "dd", 555)
For Each v In a()
Debug.Print v
Next v
Debug.Print vbLf
Dim b() As Variant
b() = Array("aaa", "bbb", "cdc", _
"ddd", 5555)
For Each v In b()
Debug.Print v
Next v
End Sub
mikerickson
10-06-2015, 12:23 PM
The VBA function Array returns a variant
this works
Dim myArray As Variant
myArray = Array("one","two","three")
This doesn't
Dim myArray() as Variant
myArray = Array("one","two","three")
To continue to the next line, space followed by underscore works.
myArray = Array(1, 2, 3, 4, 5 _
,6 ,7, 8)
Kenneth Hobs
10-06-2015, 12:41 PM
You lost me on doesn't Mike. I would not have shown that if it didn't work.
Sub ken()
Dim myArray() As Variant, v As Variant
myArray = Array("one", "two", _
"three")
MsgBox Join(myArray, vbLf)
End Sub
as does
Sub ken()
Dim myArray() As Variant, v As Variant
myArray() = Array("one", "two", _
"three")
MsgBox Join(myArray, vbLf)
End Sub
altrox5
10-06-2015, 12:47 PM
Thx all :)
mikerickson
10-07-2015, 06:27 AM
You lost me on doesn't Mike.I've run into "cannot assign to array" errors when using Array.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.