Re: Increment a Variable?
- From: Klatuu <Klatuu@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 7 Jul 2005 08:35:02 -0700
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)
>
>
>
.
- Follow-Ups:
- Re: Increment a Variable?
- From: Dirk Goldgar
- Re: Increment a Variable?
- References:
- Increment a Variable?
- From: G
- Increment a Variable?
- Prev by Date: RE: controling control properties
- Next by Date: Re: Need to code a variable Query Critereon in a forms vba.
- Previous by thread: Increment a Variable?
- Next by thread: Re: Increment a Variable?
- Index(es):
Relevant Pages
|