Shop OBEX P1 Docs P2 Docs Learn Events
Passing a variable to a subroutine within a subroutine question. — Parallax Forums

Passing a variable to a subroutine within a subroutine question.

T&E EngineerT&E Engineer Posts: 1,396
edited 2009-08-11 17:24 in General Discussion
I tried to pass a variable to a subroutine which is inside of another subroutine and it is not sucessfull. For example:

temp1   VAR   Byte
cs      VAR   Byte
 
Subroutine1   SUB  2
Subroutine2   SUB  1
 
PROGRAM Start
 
Main:
 
cs = 5
 
Subroutine1 3, cs
 
END
 
 
SUB Subroutine1
  temp1 = __PARAM1 
  cs = __PARAM2
  [b]Subroutine2 cs[/b]
  temp1 = temp1 + 1
  'Do something with temp1 now....
  ENDSUB
 
SUB Subroutine2 
  cs = __PARAM1
  cs = cs + 1
  'Do something with cs now....
  ENDSUB




Something like this format does not work unless even if I declare in the begining of the program: cs = 5

However, If I change it to this, it works:

temp1   VAR   Byte
cs      VAR   Byte
 
Subroutine1   SUB  1
Subroutine2   SUB  1
 
  
PROGRAM Start
 
Main:
 
Subroutine1 3
 
END
 
SUB Subroutine1
  temp1 = __PARAM1 
  [b]Subroutine2 5[/b]
  temp1 = temp1 + 1
  'Do something with temp1 now....
  ENDSUB
 
SUB Subroutine2 
  cs = __PARAM1
  cs = cs + 1
  'Do something with cs now....
  ENDSUB


·Any ideas?

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-08-11 17:20
    The first compiles without error using SX/B 2.00.30

    regards peter
  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2009-08-11 17:24
    Peter,

    Those were example ideas based on code I am trying to write. However, my main question was if it was possible to have variables passed into another subroutine and you have answered that. I will relook at my code tonight and make sure I have the latest SX 2.0.x. Thanks again for the confirmation.
Sign In or Register to comment.