Author Topic: Function return Function name ?  (Read 1680 times)

0 Members and 1 Guest are viewing this topic.

Aurel

  • Guest
Function return Function name ?
« on: May 18, 2017, 06:49:06 AM »
Hi Charles

In my translation of JimKsmall basic i forund that in PowerBasic
he use function name as Returned value
do i can leave this way ?
i know that FUNCTION = 1 in O2 work
also as RETURN variable
as exemple i show you this:

Code: [Select]
FUNCTION LookUp(S AS STRING) AS INT
      Dim  Counter AS INT
      Dim  MyStr AS STRING
      MyStr=S
      Counter=1
      MyStr=UCASE(MyStr)
      LookUP=SB_UNKNCOM  'DEFAULT VALUE
      While MID(Table[Counter].Command,1,1) <> "*"  And Counter < SB_NUM_CMDS
         If TRIM(Table[Counter].Command) = TRIM(MyStr) THEN
           LookUp = Table[Counter].Tok
           Counter = SB_NUM_CMDS
         End If
         Counter++ '+1
      Wend
End FUNCTION

is that ok ..because looks to me that function not respond  ???

or i must do something like that:
Code: [Select]
FUNCTION LookUp(S AS STRING) AS INT
      Dim  Counter AS INT
      Dim  MyStr AS STRING
      MyStr=S
      Counter=1
      MyStr=UCASE(MyStr)
      FUNCTION = SB_UNKNCOM  'DEFAULT VALUE
      While MID(Table[Counter].Command,1,1) <> "*"  And Counter < SB_NUM_CMDS
         If TRIM(Table[Counter].Command) = TRIM(MyStr) THEN
           FUNCTION = Table[Counter].Tok
           Counter = SB_NUM_CMDS
         End If
         Counter=Counter+1
      Wend
End FUNCTION

Charles Pegge

  • Guest
Re: Function return Function name ?
« Reply #1 on: May 18, 2017, 07:33:07 AM »
Your second example looks correct. But I will see whether o2 can be persuaded to adopt the first style of function value return.

Charles Pegge

  • Guest
Re: Function return Function name ?
« Reply #2 on: May 18, 2017, 09:55:38 AM »
Yes, we can do it for functions, but not methods. I will post the update tomorrow.

Code: [Select]
function mul3(v as float) as float
mul3=v*3
end function

print mul3 14   '42

Aurel

  • Guest
Re: Function return Function name ?
« Reply #3 on: May 18, 2017, 10:46:19 AM »
Hi Charles
that is fine
I still use old A041 version which work fine for me ..
so new update will be A043 right?