Author Topic: SELECT and result from a function  (Read 1230 times)

MrTAToad

  • Guest
SELECT and result from a function
« on: 2011-Jan-04 »
I've found that, for some reason, when using the result of a function as the value in a SELECT statement, the result is sometimes ignored.
 
For example :

Code: (glbasic) [Select]
SELECT setup.doOptions(userOptions)
case 0
case 1
case 2
ENDSELECT

will always call the CASE 0 no matter what the return value is.  Using a variable to store the result of the function call solves the problem, but can be inefficient.

And I had a case of the dreaded X problem today too for some reason...

Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 930
  • KodeSource
    • View Profile
    • KodeSource
Re: SELECT and result from a function
« Reply #1 on: 2011-Jan-04 »
And I assume since it 'will always call the CASE 0', it ONLY calls CASE 0?

I wonder if it could be the return type of the 'doOptions()' routine?  Is it '%'?
[Edit] And you said 'the result is sometimes ignored', does that mean sometimes using a function does work?
« Last Edit: 2011-Jan-04 by Slydog »
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

MrTAToad

  • Guest
Re: SELECT and result from a function
« Reply #2 on: 2011-Jan-05 »
By ignored, I think SELECT thinks that a value of 0 should be used instead of the value returned by the function.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10739
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: SELECT and result from a function
« Reply #3 on: 2011-Jan-05 »
the function call will be repeated for each case :S
Please use a constant here. I think I have to fix that one day.

Offline hardyx

  • Community Developer
  • Dr. Type
  • ******
  • Posts: 496
    • View Profile
Re: SELECT and result from a function
« Reply #4 on: 2011-Jan-05 »
In this case is more efficient to save the funcion result in a variable.   =D