Re: creating an array on the fly

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



looks like it started working ok for some reason

--


Gary


"Will" <Will.Cairns@xxxxxxxxx> wrote in message
news:1155129133.102061.227900@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Gary,
Not too difficult.. you'll need to declare the array with no
constraints in the parenthesis first
Each time in your loop you need the statement "Redim Preserve" prior to
making the variable assignment.. see example below.
-------------
Option Base 1
Dim myArray() As String
Dim y As Integer
Dim msg As String

Sub redim_myArray()
msg = "myArray"
For y = 1 To 20
ReDim Preserve myArray(1 To y)
myArray(y) = Cells(y, 1).Value
msg = msg & vbCrLf & y & " " & myArray(y)

Next

MsgBox (msg)

End Sub

ReDim Preserve myArray(1 To y)


Gary Keramidas wrote:
what is the syntax for creating an array while running a for next loop?

let's say the array is called arr, the string to add is called sStr. there
could
be up to 50 elements.

thanks
--


Gary



.



Relevant Pages

  • RE: Structure conversion from C++ to VB-2008?
    ... One of the most important structures is AmiVar structure. ... point number, the array of floating point numbers, a string or IDispatch ... Dim 13012679 as Integer ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Structure conversion from C++ to VB-2008?
    ... Public Structure AmiVar ... Dim type As Integer ... Public *array as Single ... Public *string as String ...
    (microsoft.public.dotnet.languages.vb)
  • RE: Structure conversion from C++ to VB-2008?
    ... One of the most important structures is AmiVar structure. ... point number, the array of floating point numbers, a string or IDispatch ... Dim 13012679 as Integer ...
    (microsoft.public.dotnet.languages.vb)
  • Structure conversion from C++ to VB-2008?
    ... One of the most important structures is AmiVar structure. ... point number, the array of floating point numbers, a string or IDispatch ... Dim 13012679 as Integer ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Structure conversion from C++ to VB-2008?
    ... One of the most important structures is AmiVar structure. ... point number, the array of floating point numbers, a string or IDispatch ... Dim 13012679 as Integer ...
    (microsoft.public.dotnet.languages.vb)