Re: Increment a Variable?



Or:
Dim MyArray(100) As Variant ' or as a specific type
Dim I As Integer

Do While <some condition>

If I >= UBound(MyArray) Then
Redim MyArray(I+1) Preserve
End If
I = I + 1
MyArray(I) = <some value>

Loop


"Dirk Goldgar" wrote:

> "G" <G@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:FE14ED31-1582-490D-8C5C-4FDC222286C0@xxxxxxxxxxxxx
> > I am looping on an varying number of items and would like to assign a
> > different variable to each. Possible to increment a variable and
> > assign the unique variable on each loop? If so, how would I do it?
> >
> > For example, I may have 5 items that I want to set as a myvar1,
> > myvar2, ... myvar5 on one loop, but the next time I may have 15 items
> > (myvar1 ... myvar15) the next time.
> >
> > Any help is greatly appreciated. Thanks.
>
> You can't do that in any practical way, but you can use an array:
>
> Dim MyArray(100) As Variant ' or as a specific type
> Dim I As Integer
>
> Do While <some condition>
>
> If I >= UBound(MyArray) Then
> MsgBox "Oops! Too many items!"
> Exit Do
> Else
> I = I + 1
> MyArray(I) = <some value>
> End If
>
> Loop
>
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>
>
>
.



Relevant Pages

  • Re: For Each...Next not working
    ... Dim TestArrayAs Variant, e As Variant, I As Integer ... Next loop is for. ... I do not want to fill the array with the indices (I can't imagine why ...
    (microsoft.public.excel.programming)
  • RE: Loop ending in wrong place
    ... The problem you are having is how the loop is operating. ... Dim rstExchange As Recordset, rstUsers As Recordset ... Dim Requester As Variant, Received As Variant ... Set dbs = CurrentDb ...
    (microsoft.public.access.modulesdaovba)
  • DlookUp Help
    ... I am trying to use a date for comparison in a do while loop. ... Public Function WorkDaysAdjAs Variant ... Dim StartDate As Variant ... Debug.Print HDay & " Holiday" ...
    (microsoft.public.access.modulesdaovba)
  • Re: Loop ending in wrong place
    ... Next add a line inside of the loop to print some data to the Immediate ... Dim rstExchange As Recordset, rstUsers As Recordset ... Dim Requester As Variant, Received As Variant ... Set dbs = CurrentDb ...
    (microsoft.public.access.modulesdaovba)
  • Re: Fibonacci function/command in excel?...tia sal
    ... >> possible...139 because X1 will overflow inside the loop. ... >> Dim I As Long, X0 As Variant, X1 As Variant ...
    (microsoft.public.excel.programming)