Can a variable declared in one sub procedure be used by another subprocedure?

Discussion in 'ASP General' started by steve, Aug 16, 2005.

  1. steve

    steve Guest

    I have Option Explicit ON by the way.

    I have declared a variable in one subprocedure which is being used by
    another subprocedure. But it doesn' seem to work. I am doing something
    similar to this (but obviously with much more code):


    <%
    Option Explicit
    Call X
    Call Z

    Sub X
    Dim Y
    Y = "Hello"
    End Sub

    Sub Z
    response.write Y
    End Sub
    %>

    Is this not possible and is there anyway (apart from breaking up the
    sub procedures) of keeping the code separated and organized in this
    fashion.
     
    steve, Aug 16, 2005
    #1
    1. Advertisements

  2. steve

    McKirahan Guest

    "steve" <> wrote in message
    news:...
    > I have Option Explicit ON by the way.
    >
    > I have declared a variable in one subprocedure which is being used by
    > another subprocedure. But it doesn' seem to work. I am doing something
    > similar to this (but obviously with much more code):
    >
    >
    > <%
    > Option Explicit
    > Call X
    > Call Z
    >
    > Sub X
    > Dim Y
    > Y = "Hello"
    > End Sub
    >
    > Sub Z
    > response.write Y
    > End Sub
    > %>
    >
    > Is this not possible and is there anyway (apart from breaking up the
    > sub procedures) of keeping the code separated and organized in this
    > fashion.
    >


    "Sub Z" doesn't know about "Y" unless you declare it globally:

    <%
    Option Explicit
    Dim Y
    Call X
    Call Z

    Sub X
    Y = "Hello"
    End Sub

    Sub Z
    response.write Y
    End Sub
    %>
     
    McKirahan, Aug 16, 2005
    #2
    1. Advertisements

  3. steve

    steve Guest

    Thank you for your prompt post. I understand how it works now. Thank
    you.
     
    steve, Aug 16, 2005
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kathy Burke
    Replies:
    3
    Views:
    596
    Kathy Burke
    Nov 24, 2003
  2. JohnZing

    declared or not declared ?

    JohnZing, Feb 5, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    1,765
    Jon Paal
    Feb 5, 2006
  3. loga123
    Replies:
    2
    Views:
    431
    loga123
    May 20, 2006
  4. diac
    Replies:
    1
    Views:
    397
    Ken Cox [Microsoft MVP]
    Oct 4, 2006
  5. Ben
    Replies:
    2
    Views:
    1,240
  6. Casey Hawthorne
    Replies:
    1
    Views:
    917
    Arne Vajhøj
    Mar 18, 2009
  7. Lawrence D'Oliveiro

    Death To Sub-Sub-Sub-Directories!

    Lawrence D'Oliveiro, May 5, 2011, in forum: Java
    Replies:
    92
    Views:
    3,070
    Lawrence D'Oliveiro
    May 20, 2011
  8. ccc31807
    Replies:
    10
    Views:
    734
    Charlton Wilbur
    Mar 6, 2012
Loading...