+ Reply to Thread
Results 1 to 15 of 15

variable

  1. #1

    variable

    Hi, Ive got 20 variables named xmean1, xmean2,
    xmean3............xmean20. I want to refer to these with, For I = 1 TO
    20. Ive tried, xmean(i), xmean & i and (xmean(i)). Any idea on how to
    do this, or is this not possible.
    Regards Robert


  2. #2
    Don Lloyd
    Guest

    Re: variable

    Hi,
    I would think you need to place the xmean variables in an array i.e dim
    xmean(1 to 20)

    They can then be referenced in a loop with xmean(i), i being the loop
    variable.

    Don

    <[email protected]> wrote in message
    news:[email protected]...
    > Hi, Ive got 20 variables named xmean1, xmean2,
    > xmean3............xmean20. I want to refer to these with, For I = 1 TO
    > 20. Ive tried, xmean(i), xmean & i and (xmean(i)). Any idea on how to
    > do this, or is this not possible.
    > Regards Robert
    >




  3. #3
    Bob Phillips
    Guest

    Re: variable

    Create an array of variables

    Dim xmean(1 to 20)

    ... load the array

    For i = 1 To 20
    Debug.Pring xmean(i)
    Next i

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    <[email protected]> wrote in message
    news:[email protected]...
    > Hi, Ive got 20 variables named xmean1, xmean2,
    > xmean3............xmean20. I want to refer to these with, For I = 1 TO
    > 20. Ive tried, xmean(i), xmean & i and (xmean(i)). Any idea on how to
    > do this, or is this not possible.
    > Regards Robert
    >




  4. #4

    Re: variable

    Thankyou for your replys, this is perfect. Can I use the same for a
    static variable. ie
    Static xmean as integer. Thanks Again
    Regards Robert


  5. #5
    Bob Phillips
    Guest

    Re: variable

    Yes you can but you need to size it in the declaration, and also Integer is
    really redundant in 32 bit systems

    Static xmean(1 To 20) As long

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    <[email protected]> wrote in message
    news:[email protected]...
    > Thankyou for your replys, this is perfect. Can I use the same for a
    > static variable. ie
    > Static xmean as integer. Thanks Again
    > Regards Robert
    >




  6. #6

    Re: variable

    Thanks for your advice, much appreciated.
    Regards Robert


  7. #7

    Re: variable

    Sorry, just realised another part to this. Ive been using Erase xmean1,
    how do I use this with a loop, eg for i = 1 to 20 Erase(i) next i.
    Triead this but didnt work
    Regards Robert


  8. #8
    Norman Jones
    Guest

    Re: variable

    Hi Robert,

    You do not need to loop. Try:

    Erase xmean


    ---
    Regards,
    Norman



    <[email protected]> wrote in message
    news:[email protected]...
    > Sorry, just realised another part to this. Ive been using Erase xmean1,
    > how do I use this with a loop, eg for i = 1 to 20 Erase(i) next i.
    > Triead this but didnt work
    > Regards Robert
    >




  9. #9
    Bob Phillips
    Guest

    Re: variable

    Just use

    Erase xmean

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    <[email protected]> wrote in message
    news:[email protected]...
    > Sorry, just realised another part to this. Ive been using Erase xmean1,
    > how do I use this with a loop, eg for i = 1 to 20 Erase(i) next i.
    > Triead this but didnt work
    > Regards Robert
    >




  10. #10

    Re: variable

    Thankyou for that. So somple when you see it. Works fine. Can yo tell
    me When I use redim preserve with varaible declared as Dim xmean(1 to
    4) as varaint, how I structure the command. So far Ive got Redim
    Preserve xmean(i) (1 to x), but I get an error. Thanks again
    Regards Robert


  11. #11
    Norman Jones
    Guest

    Re: variable

    Hi Robert,

    Try something like:

    '=============>>
    Public Sub Tester()
    Dim i As Long
    Dim xmean() As Variant

    ReDim xmean(1 To 20)
    For i = 1 To 20
    xmean(i) = i * 10
    Next i

    For i = 1 To 20
    Debug.Print xmean(i)
    Next i
    ReDim Preserve xmean(1 To 30)

    End Sub
    '<<=============


    ---
    Regards,
    Norman


    <[email protected]> wrote in message
    news:[email protected]...
    > Thankyou for that. So somple when you see it. Works fine. Can yo tell
    > me When I use redim preserve with varaible declared as Dim xmean(1 to
    > 4) as varaint, how I structure the command. So far Ive got Redim
    > Preserve xmean(i) (1 to x), but I get an error. Thanks again
    > Regards Robert
    >




  12. #12

    Re: variable

    Thanks again for your reply, I think Ive confused things with my
    original post. Originally I had 20 variables which the values changed
    with each running of the macro, and dim xmean(1 to 20) was fine for
    this, saved me writing xmean 20 times. Im using the static array a
    little different and this is were Ive confused myself. Basically I
    using worksheet change, so I had 5 static arrays difined, so with each
    worksheet change it retains the original data and added the next value,
    a bit like a counter really. So im looking for an easier way of haveing
    x number of static variables without typing them. I think by writing
    static xmean(1 to 4), Im not saying 4 different arrays, but
    dimensioning a single array. Does that make sense. Im geusing I would
    still need to list them seperatly as I dont know what the end size will
    be.
    Regards Robert


  13. #13
    Bob Phillips
    Guest

    Re: variable

    Do you mean

    Dim xMean(1 To 20, 1 To 5) As Long

    for instance

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    <[email protected]> wrote in message
    news:[email protected]...
    > Thanks again for your reply, I think Ive confused things with my
    > original post. Originally I had 20 variables which the values changed
    > with each running of the macro, and dim xmean(1 to 20) was fine for
    > this, saved me writing xmean 20 times. Im using the static array a
    > little different and this is were Ive confused myself. Basically I
    > using worksheet change, so I had 5 static arrays difined, so with each
    > worksheet change it retains the original data and added the next value,
    > a bit like a counter really. So im looking for an easier way of haveing
    > x number of static variables without typing them. I think by writing
    > static xmean(1 to 4), Im not saying 4 different arrays, but
    > dimensioning a single array. Does that make sense. Im geusing I would
    > still need to list them seperatly as I dont know what the end size will
    > be.
    > Regards Robert
    >




  14. #14

    Re: variable

    Thankyou for your reply. Possibly, if im looking at this in the correct
    way. Would I use this as xmean1 would start at xmean(1,1), xmean2 at
    xmean(1,2) upto 5. then new data would go at (2,1), (2,2). In which
    case could I use redim preserve(1 to x, 1 to 5). And could I use this
    as a static array. Am I close.
    Regards Robert


  15. #15
    Bob Phillips
    Guest

    Re: variable

    Hopefully it is all answered in the other post.

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    <[email protected]> wrote in message
    news:[email protected]...
    > Thankyou for your reply. Possibly, if im looking at this in the correct
    > way. Would I use this as xmean1 would start at xmean(1,1), xmean2 at
    > xmean(1,2) upto 5. then new data would go at (2,1), (2,2). In which
    > case could I use redim preserve(1 to x, 1 to 5). And could I use this
    > as a static array. Am I close.
    > Regards Robert
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1