+ Reply to Thread
Results 1 to 4 of 4

maximum variables within sub

  1. #1
    mike allen
    Guest

    maximum variables within sub

    i have one sub that calls another and apparently have run out of room for
    variables. my code is similar to this one, but with many more variables w/in
    sub2:
    sub1()
    a=1
    b=2
    c=3
    d=4
    call sub2(a,b,c,d,e,f)
    range("a1") = e
    range("a2") = f
    end sub

    sub2(a,b,c,d,e,f)
    e = a + b + c
    f = a*b*c/d
    end sub

    this works great, but i have been adding many variables from sub1 that are
    needed to complete sub2 and apparently have run out of space. i have, i
    think, 60 variables when it was working, but adding 1 more caused it to
    malfunction. surely vba doesn't limit you to 60 variables. any thoughts?
    thanks, mike allen



  2. #2
    ben
    Guest

    RE: maximum variables within sub

    no just 60 variables to pass

    "mike allen" wrote:

    > i have one sub that calls another and apparently have run out of room for
    > variables. my code is similar to this one, but with many more variables w/in
    > sub2:
    > sub1()
    > a=1
    > b=2
    > c=3
    > d=4
    > call sub2(a,b,c,d,e,f)
    > range("a1") = e
    > range("a2") = f
    > end sub
    >
    > sub2(a,b,c,d,e,f)
    > e = a + b + c
    > f = a*b*c/d
    > end sub
    >
    > this works great, but i have been adding many variables from sub1 that are
    > needed to complete sub2 and apparently have run out of space. i have, i
    > think, 60 variables when it was working, but adding 1 more caused it to
    > malfunction. surely vba doesn't limit you to 60 variables. any thoughts?
    > thanks, mike allen
    >
    >
    >


  3. #3
    Myrna Larson
    Guest

    Re: maximum variables within sub

    It may well limit the number of arguments. You have a couple of options here.
    One is to put your individual variables into an array, i.e.

    Dim Vars AS Variant
    Vars = Array(1,2,3,4,5,6)

    or

    Dim Vars() As Long
    ReDim Vars(1 to 10)
    For i = 1 to 10
    Vars(i) = i
    Next i

    Then you call the 2nd Sub with just one argument, Vars or Vars()

    The other option is to use a user-defined type variable, i.e.

    Type MultipleVarsType
    a as integer
    b as byte
    c as long
    d as double
    e as string
    f as double
    End Type

    Sub1()

    Dim V As MultipleVarsType
    With V
    .a = 3
    .b = 27
    .c = 387587
    .d = 3.14159#
    .e = "some text"
    .f = exp(1)
    End With

    Sub2 V
    End Sub

    Sub2(X as MultipleVarsType)
    X.a = X.a / 38
    End Sub

    On Wed, 26 Jan 2005 14:16:51 -0600, "mike allen" <[email protected]>
    wrote:

    >i have one sub that calls another and apparently have run out of room for
    >variables. my code is similar to this one, but with many more variables w/in
    >sub2:
    >sub1()
    > a=1
    > b=2
    > c=3
    > d=4
    > call sub2(a,b,c,d,e,f)
    > range("a1") = e
    > range("a2") = f
    >end sub
    >
    >sub2(a,b,c,d,e,f)
    > e = a + b + c
    > f = a*b*c/d
    >end sub
    >
    >this works great, but i have been adding many variables from sub1 that are
    >needed to complete sub2 and apparently have run out of space. i have, i
    >think, 60 variables when it was working, but adding 1 more caused it to
    >malfunction. surely vba doesn't limit you to 60 variables. any thoughts?
    >thanks, mike allen
    >



  4. #4
    mike allen
    Guest

    Re: maximum variables within sub

    great info. i couldn't really follow the last suggestion, but i got a
    variation of the first suggestion to work. thank you. mike allen
    "Myrna Larson" <[email protected]> wrote in message
    news:[email protected]...
    > It may well limit the number of arguments. You have a couple of options
    > here.
    > One is to put your individual variables into an array, i.e.
    >
    > Dim Vars AS Variant
    > Vars = Array(1,2,3,4,5,6)
    >
    > or
    >
    > Dim Vars() As Long
    > ReDim Vars(1 to 10)
    > For i = 1 to 10
    > Vars(i) = i
    > Next i
    >
    > Then you call the 2nd Sub with just one argument, Vars or Vars()
    >
    > The other option is to use a user-defined type variable, i.e.
    >
    > Type MultipleVarsType
    > a as integer
    > b as byte
    > c as long
    > d as double
    > e as string
    > f as double
    > End Type
    >
    > Sub1()
    >
    > Dim V As MultipleVarsType
    > With V
    > .a = 3
    > .b = 27
    > .c = 387587
    > .d = 3.14159#
    > .e = "some text"
    > .f = exp(1)
    > End With
    >
    > Sub2 V
    > End Sub
    >
    > Sub2(X as MultipleVarsType)
    > X.a = X.a / 38
    > End Sub
    >
    > On Wed, 26 Jan 2005 14:16:51 -0600, "mike allen" <[email protected]>
    > wrote:
    >
    >>i have one sub that calls another and apparently have run out of room for
    >>variables. my code is similar to this one, but with many more variables
    >>w/in
    >>sub2:
    >>sub1()
    >> a=1
    >> b=2
    >> c=3
    >> d=4
    >> call sub2(a,b,c,d,e,f)
    >> range("a1") = e
    >> range("a2") = f
    >>end sub
    >>
    >>sub2(a,b,c,d,e,f)
    >> e = a + b + c
    >> f = a*b*c/d
    >>end sub
    >>
    >>this works great, but i have been adding many variables from sub1 that are
    >>needed to complete sub2 and apparently have run out of space. i have, i
    >>think, 60 variables when it was working, but adding 1 more caused it to
    >>malfunction. surely vba doesn't limit you to 60 variables. any thoughts?
    >>thanks, mike allen
    >>

    >




+ 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