Shop OBEX P1 Docs P2 Docs Learn Events
Can subroutines pass parmeters in PBasic? — Parallax Forums

Can subroutines pass parmeters in PBasic?

beatsbeats Posts: 17
edited 2008-11-04 00:59 in BASIC Stamp
I know its usually the other way around, but I need to convert some SX/B code into BS2.

As you know, in SX/B language you are aloud to pass parameters to the subroutines when you declare them and when you call them later on. I am wondering if PBasic/Basic Stamp2 can do this? If so, how can you pass the parameters when you call GOSUB?

Thanks,
Tony

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-03 20:45
    There's no provision for parameter passing to subroutines in PBasic. The only way to pass parameters is to share variables. In other words, you have to set some variables (like a, b, c, ...) prior to the GOSUB with assignment statements, then use these variables in the subroutine. Since you can put several statements on a single line, this can help clarity like:
    a = 1 : b = x + 5 : GOSUB 500
  • $WMc%$WMc% Posts: 1,884
    edited 2008-11-04 00:59
    Mr.Green

    I liked the way you addressed passing paramters via shared variables,This is a very clever approach. I've been asked for some help w/ passing Math instructions from a MEMKey to a BS2p40,and displaying them in A debug window, this would act like a calculator...It seemed pretty simple at first,But as I started to write some code ,It became really complicated.? Would the method You showed in the post above handle the MATH, By this I mean the Actual math Func.s " + "," - "," / ",ETC....I know the keypad code needs to be converted to a usable #...It was the Math "symbol" part that got Me confused....I don't want to be off topic, I feel its related...Is there another approach????
Sign In or Register to comment.