Hi All,
I never used dynamic arrays i am placing some sample code its throwing error subscript out of range. I trying to know about Redim.
Forall e In doc.field1
Redim Preserve tmp(j) As String
tmp(j)=e
j=j+1
End Forall
doc.field2=tmp(j)
Just can anybody tell me how to use the values stored in the dynamic arrays.
Adv thanks…
Subject: Redim
The designer help gives you all the information you need on arrays. This is just a coding error. At the end of the forall loop, “j” will be greater than the dimensions of “tmp” by 1.
Subject: RE: Redim
Thanks for your quick response Andrew. I understood the topic now.Here how can i equalize “j” and “Tmp”.
Subject: Redim
j = -1Forall e In doc.field1
j=j+1
Redim Preserve tmp(j) As String
tmp(j)=e
End Forall
doc.field2=tmp(j)
This way j and size match, alternatively u can also do
doc.field2=tmp(ubound(tmp))
ubound gets the array size and that should get u the last value that u seek.
OR
dim tmp as variant
tmp = doc.field1
if isarray(tmp) then 'IF field1 is “” then tmp will not be an array
doc.field2 = tmp(ubound(tmp))
end if
be careful, that field1 is not null or else it will throw error