Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I use Dynamic Array 1

Status
Not open for further replies.

seaport

MIS
Jan 5, 2000
923
US
From Access97 Help file, I know I can declare a dynamic array in the way as following:<br>
<br>
Dim sngArray() As Single<br>
<br>
However, when I ran the following code:<br>
<br>
sngarray(0)=5.5<br>
<br>
I got the error message &quot;subscript out of range.&quot;<br>
<br>
So, what exactly is &quot;Dynamic array&quot; in Visual Basic?<br>

 
Definition of 'Dynamic' will likely resolve to, 'the size of the array can increase or/and decrease at run time', in most texts on any programming language. I usually use something like:<br>
<br>
<br>
Dim theArray as Variant<br>
Dim strString as String<br>
<br>
set theArray = Array(&quot;str1&quot;,&quot;str2&quot;)<br>
<br>
' then add another string like . . .<br>
strString = &quot;str3&quot;<br>
<br>
' by adding room for one more string to the array<br>
' and filling the space in the same call.<br>
<br>
<b> ReDim Preserve theArray(ubound(theArray) + 1)</b> = strString<br>
<br>
' If I'm creating an array for use somewhere further along <br>
' in the code I use something like this guy . . .<br>
<br>
Dim theArray as variant<br>
set theArray = Array(0)<br>
dim fVal as double<br>
dim i as Integer<br>
<br>
fVal = 0.0 <br>
<br>
' then call something like . . .<br>
<br>
for i = LBound(theArray) to 10 <br>
fVal = fVal + 0.1<br>
<b> ReDim Preserve theArray(UBound(theArray) + 1)</b> = fVal<br>
next i<br>
<br>
' sum of the array is now 1 !<br>
<br>
<p>Amiel<br><a href=mailto:amielzz@netscape.net>amielzz@netscape.net</a><br><a href=http:// jazz.adelphia.net> </a><br>Amiel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top