Post Reply 
HP-71B BASIC Question
03-16-2021, 02:38 AM (This post was last modified: 03-16-2021 03:35 AM by Valentin Albillo.)
Post: #3
RE: HP-71B BASIC Question
.
Hi, Sylvain:

(03-16-2021 12:53 AM)Sylvain Cote Wrote:  I have created a program that have multiple sub-routines and I have a user defined function (UDF) that need to be called from the main body and from the sub-routines.

Not a criticism or nitpicking but you need to use the proper terminology: what you are trying to do is to call an UDF from a subprogram (CALL), not from a subroutine (GOSUB)

Calling a main-program UDF from a subprogram is not possible, they use separate environments. Your options are:
  • 1) Convert your subprograms to main-program subroutines and call them using GOSUB, not CALL. Besides, there's no parameter-passing to subroutines, you'll have to use or assing the proper values yourself to the variables used by the subroutines.
          
  • 2) Convert your main-program UDF to a subprogram, like this:

          main program UDF:        10 DEF FNB(S8)=IP(FP(S8/2^6)*2

                to

          subprogram:       100 SUB FUNB(S8,F) @ F=IP(FP(S8/2^6)*2

    and of course change all calls to the UDF to calls to the equivalent subprogram instead. As the calls are statements, they can't be used while evaluating expressions, you'll have to call the subprogram first and then use the returned value in the expressions.
          
  • 3) In your main program, define a string to hold the function definition, then pass that string to every subprogram and evaluate it using VAL, like this:

          main program:

              10 S$="IP(FP(X/2^6)*2"


          subprogram:
            
              500 SUB DECODE(S9,B9,E9,C9,L9,S$)
              510 X=S9 @ IF VAL(S$)=1 THEN ...

Neither option is ideal, each have their disadvantages but at least you won't have to repeat the UDF in the main program and all subprograms that do use it.

Regards.
V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
HP-71B BASIC Question - Sylvain Cote - 03-16-2021, 12:53 AM
RE: HP-71B BASIC Question - toml_12953 - 03-16-2021, 01:42 AM
RE: HP-71B BASIC Question - Valentin Albillo - 03-16-2021 02:38 AM
RE: HP-71B BASIC Question - J-F Garnier - 03-16-2021, 09:34 AM
RE: HP-71B BASIC Question - Sylvain Cote - 03-17-2021, 02:28 PM
RE: HP-71B BASIC Question - Sylvain Cote - 03-17-2021, 07:30 PM
RE: HP-71B BASIC Question - toml_12953 - 03-18-2021, 07:56 AM
RE: HP-71B BASIC Question - Sylvain Cote - 03-18-2021, 11:02 AM
RE: HP-71B BASIC Question - J-F Garnier - 03-19-2021, 09:01 AM
RE: HP-71B BASIC Question - Sylvain Cote - 03-19-2021, 07:07 PM
RE: HP-71B BASIC Question - J-F Garnier - 03-20-2021, 09:23 AM
RE: HP-71B BASIC Question - Sylvain Cote - 03-20-2021, 01:03 PM
RE: HP-71B BASIC Question - Sylvain Cote - 03-22-2021, 10:31 PM
RE: HP-71B BASIC Question - J-F Garnier - 03-24-2021, 10:05 AM
RE: HP-71B BASIC Question - rprosperi - 03-24-2021, 12:40 PM
RE: HP-71B BASIC Question - J-F Garnier - 03-24-2021, 04:51 PM
RE: HP-71B BASIC Question - rprosperi - 03-24-2021, 07:36 PM



User(s) browsing this thread: 1 Guest(s)