Senin, 30 Januari 2012

[MS_AccessPros] Re: Dynamic Varialbe -- Arrays

 

It certainly does John - thanks so much!

--- In MS_Access_Professionals@yahoogroups.com, "John Viescas" <john@...> wrote:
>
> Mike-
>
> Maybe this will help you see it:
>
> Dim B (0 To 3) As String, intI As Integer
>
> ' Set values
> B(0) = "A"
> B(1) = "B"
> B(3) = "C"
>
> For intI = 0 To 3
> Debug.Print B(inti)
> End If
>
>
> John Viescas, author
> Microsoft Office Access 2010 Inside Out
> Microsoft Office Access 2007 Inside Out
> Building Microsoft Access Applications
> Microsoft Office Access 2003 Inside Out
> SQL Queries for Mere Mortals
> http://www.viescas.com/
> (Lahaina, HI)
>
>
>
>
>
> -----Original Message-----
> From: MS_Access_Professionals@yahoogroups.com
> [mailto:MS_Access_Professionals@yahoogroups.com] On Behalf Of mithomas48
> Sent: Monday, January 30, 2012 8:05 AM
> To: MS_Access_Professionals@yahoogroups.com
> Subject: [MS_AccessPros] Re: Dynamic Varialbe -- Arrays
>
> Crystal, the array is not carrying over values in the variables. The array is
> just carring over the name of the variable - not the values in them. For
> example...
>
> I am assigning different values to say, 3 variables...
> B0 = "A"
> B1 = "B"
> B2 = "C"
>
> In the array, with each pass, I need to first look at B0 with it's value of "A",
> then second pass look at B1 with its value of "B" and so on.
>
> The below only dumps the variable name in the array.
> strArray(i) = "b" & i
>
> Thanks again!
> Mike
>
>
> --- In MS_Access_Professionals@yahoogroups.com, Crystal <strive4peace2008@>
> wrote:
> >
> > Hi Mike,
> >
> > use an array, not a regular variable.
> >
> > Arrays
> >
> > when you Dim an array, if you do not specify the number of elements then you
> need to ReDim to allocate space.  Use the PRESERVE keyword to preserve the
> current values while the array is redimmed
> >
> > try this to learn more about using arrays:
> >
> > Dim strArray() as string
> > ReDim strArray(0)
> > strArray(0) = "element 0"
> >
> > for i = 1 to 3
> >    ReDim Preserve strArray(i)
> >    strArray(i) = "element " & i
> > next i
> >
> > ' LBound is lower bound.  This will be 0 unless you set Option Base 1
> > ' UBound is upper bound
> >
> > for i = LBound(strArray) to UBound(strArray)
> >    msgbox strArray(i),,i & " out of " & ( UBound(strArray)-
> LBound(strArray)+1)
> > next i
> >
> > '~~~~~~~~~~~~~~~~~~~~~
> > if you don't use Preserve, then the array gets re-dimensioned but loses its
> previous values
> > '~~~~~~~~~~~~~~~~~~~~~
> >
> >
> > alternately, if you know how many elements you will want, you can do this:
> >
> > Dim strArray(5) as string
> >
> > this gives you 6 elements... 0 thru 5
> >
> > Dim strArray(1 to 5) as string
> >
> > this gives you 5 elements... 1 thru 5
> >
> >
> > *********************************
> > paste this code into a general module and run it:
> >
> > '~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > Sub testArray()
> > 'Crystal 100415
> >
> >    'CLICK HERE
> >    ' Press F5 to Run
> >    '(after compiling and saving)
> >  
> >    Dim i As Integer
> >  
> >    Dim strArray() As String
> >    ReDim strArray(0)
> >    strArray(0) = "element 0"
> >     
> >    For i = 1 To 3
> >       ReDim Preserve strArray(i)
> >       strArray(i) = "element " & i
> >    Next i
> >  
> >    ' LBound is lower bound.  This will be 0 unless you set Option Base 1
> >    ' UBound is upper bound
> >  
> >    For i = LBound(strArray) To UBound(strArray)
> >       MsgBox strArray(i), , i & " out of " & (UBound(strArray) -
> LBound(strArray) + 1)
> >    Next i
> >
> > End Sub
> > '~~~~~~~~~~~~~~~~~~~~~~~~
> >
> > and here is another version:
> >
> > '~~~~~~~~~~~~~~~~~~~~~~~~
> > Sub testArray2()
> > 'Crystal 100415
> >
> >    'CLICK HERE
> >    ' Press F5 to Run
> >    '(after compiling and saving)
> >  
> >    Dim i As Integer
> >  
> >    Dim strArray(4) As String
> >     
> >    For i = LBound(strArray) To UBound(strArray)
> >       strArray(i) = "element " & i
> >    Next i
> >  
> >    ' LBound is lower bound.  This will be 0 unless you set Option Base 1
> >    ' UBound is upper bound
> >  
> >    For i = LBound(strArray) To UBound(strArray)
> >       MsgBox strArray(i), , i & " out of " & (UBound(strArray) -
> LBound(strArray) + 1)
> >    Next i
> >
> > End Sub
> > '~~~~~~~~~~~~~~~~~~~~~~~~
> >
> >
> >
> > Warm Regards,
> > Crystal
> >
> > Microsoft MVP
> > remote programming and training
> >
> > Access Basics by Crystal
> > http://www.AccessMVP.com/strive4peace
> > Free 100-page book that covers essentials in Access
> >
> >  *
> >    (: have an awesome day :)
> >  *
> >
> >
> >
> > ________________________________
> > From: mithomas48
> >
> > Thanks Bill, but I'm trying to stay away from using a Select Case or If Else. 
> Isn't there a simple function or something that can dynamically change a
> variable?  For example...
> >
> > In each pass the variable "b" would become b0, then the next pass b1 and so
> on.
> >
> > Thanks again!
> > Mike
> >
> > --- In MS_Access_Professionals@yahoogroups.com, "Bill Mosca" <wrmosca@> wrote:
> > >
> > > Mike
> > >
> > > Use a counter in the loop and a select case
> > >
> > > For x = 1 to 3
> > >    Select Case x
> > >        Case 1
> > >            v1 = Something
> > >            'or
> > >            Something = v1
> > >        Case 2
> > >            v2 = Something
> > >            'or
> > >            Something = v2       
> > >        Case 3
> > >            v3 = Something
> > >            'or
> > >            Something = v3               
> > >    End Select
> > > Next
> > >
> > > Regards,
> > > Bill Mosca, Founder - MS_Access_Professionals
> > > http://www.thatlldoit.com
> > > Microsoft Office Access MVP
> > > https://mvp.support.microsoft.com/profile/Bill.Mosca
> > >
> > >
> > >
> > > --- In MS_Access_Professionals@yahoogroups.com, mithomas48 <no_reply@>
> wrote:
> > > >
> > > > How can I dynamically reset a variable within a loop - without using a
> Select Case, or IF Else?  For Example...
> > > >
> > > > First pass = v1
> > > > Second pass = v2
> > > > Third pass = v3
> > > >
> > > > So I need to dynamically set the last digit.
> > > >
> > > > Thanks in advance!
> > > > Mike
> > > >
> > >
> >
> > [Non-text portions of this message have been removed]
> >
>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>

__._,_.___
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar