Sub routine in sub routine error

Results 1 to 3 of 3

Thread: Sub routine in sub routine error

  1. #1
    Join Date
    Dec 1969

    Default Sub routine in sub routine error

    I can&#039;t have a sub (or function) in a sub like this:<BR><BR>sub test1<BR> response.write "test 1"<BR> sub test 2<BR> response.write "test 2"<BR> end sub<BR>end sub<BR><BR>I get a syntax error. Anyone got an idea why and if there is anything to do about it?

  2. #2
    Join Date
    Dec 1969

    Default The reason why is...

    ...that this is how VBScript is defined as a language. The answer what to do about it is to take it out of the first sub:<BR><BR>Sub test1<BR>&nsbp;&nbsp;Response.Write "test 1"<BR>End Sub<BR><BR>Sub test2<BR>&nsbp;&nbsp;Response.Write "test 2"<BR>End Sub<BR><BR>Oliver.

  3. #3
    Join Date
    Dec 1969

    Default To expand on Oliver's answer...

    There aren&#039;t many languages that *do* allow this.<BR><BR>If you think about it, it doesn&#039;t REALLY make sense.<BR><BR>You are asking to *DEFINE* the second SUB in the process of *RUNNING* the first SUB. But by definition, subroutines *MUST* exist *BEFORE* the program even *begins* to run.<BR><BR>Suppose you had code that looked like this:<BR><BR>&#060;%<BR>sub test1<BR> response.write "test 1"<BR> sub test2<BR> response.write "test 2"<BR> end sub<BR>end sub<BR><BR>test2<BR>test1<BR>%&#062;<BR><BR>Here, you are invoking test2 before test1 has had a chance to create it. Well, you would be, if that were allowed.<BR><BR>Luckily, it is not. <BR><BR>I hope you didn&#039;t think that, by putting test2 inside of test1, you were then automatically *invoking* (running) test2??? Nope. No such thing. In any language that I know of.<BR><BR>

Posting Permissions

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