VBA question Arrays

January 9, 2010 at 13:57:17
Specs: Windows XP, 128
please help whith arrays

there is a code

For i1 = x To xx
tekst(Tex) = Cells(i1, 1).Value ' must be array?
Tex = Tex + 1 ' increase array, if arrays this string do not need?
Next i1

for each t in Tekst(Tex)
msgbox t
next t

result in msgbox must be
tekst1 = "bla bla bla"
tekst2 = "ajshf ag aeg"
......... etc.
tekstN = "....."

See More: VBA question Arrays

Report •

January 9, 2010 at 16:54:32
here's some sample code to start with:
dim tex(10)
for each t in (tex)
msgbox "tex "&i&" "&t

but note that it reiterates msgboxes for the entire array of
"tex" (as declared, 10 elements) not just the four that are assigned values. the for-loop can also go like this:
for i=1 to 4
msgbox "tex "&i&" "&tex(i)

Report •

January 10, 2010 at 03:56:38
Thanks for reply. Reason is that array is udefined, it can be 10 and can be 100 according on xx value. And each tekst(tex) is a string value and it len can be greater than 40 simbols. its extract text from html files.

Report •

January 10, 2010 at 05:19:29
xx = Ubound(cells())

This will put the size of the array into xx.

If the size of the array is unknown at runtime you can use dynamic arrays.

If (xx Mod 5) = 0 Then
ReDim Preserve tekst(xx+5) As String
End If

This will increase the array length of texst() in multiples of five or whatever other number is appropriate.

The ReDim Preseve is a useful function when using Arrays of undetermined length. I am not sure that it is available in VBA as it is taken from VB6.


Report •

Related Solutions

Ask Question