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. Advertising

  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. Advertising

  3. steve

    steve Guest

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

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. Nathan Sokalski

    Subprocedure for Oracle's SET DEFINE OFF command

    Nathan Sokalski, Nov 10, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    8,129
    =?Utf-8?B?U2ltb24=?=
    Nov 11, 2005
  2. Ben
    Replies:
    2
    Views:
    954
  3. Richard Molgner

    VHDL subprocedure call

    Richard Molgner, Jan 18, 2011, in forum: VHDL
    Replies:
    4
    Views:
    1,357
    Paul Uiterlinden
    Jan 18, 2011
  4. Lawrence D'Oliveiro

    Death To Sub-Sub-Sub-Directories!

    Lawrence D'Oliveiro, May 5, 2011, in forum: Java
    Replies:
    92
    Views:
    2,166
    Lawrence D'Oliveiro
    May 20, 2011
  5. ccc31807
    Replies:
    10
    Views:
    567
    Charlton Wilbur
    Mar 6, 2012
Loading...

Share This Page