Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:41 08 Mar 2026 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : val(x$)......

Author Message
DigitalDreams
Regular Member

Joined: 03/05/2025
Location: United Kingdom
Posts: 53
Posted: 05:41pm 07 Mar 2026
Copy link to clipboard 
Print this post

Having trouble with this command.

If x$="57+93+117"

Val(x$) returns 57 !?

Am I asking too much of val(x$) ?
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1400
Posted: 05:50pm 07 Mar 2026
Copy link to clipboard 
Print this post

  DigitalDreams said  Having trouble with this command.

If x$="57+93+117"

Val(x$) returns 57 !?

Am I asking too much of val(x$) ?

yes
  Quote  Returns the numerical value of the ‘string$’. If 'string$' is an invalid number the function will return zero.
This function will recognise the &H prefix for a hexadecimal number, &O
for octal and &B for binary
So it converts the numerical value within a string into a number. But it does not calculate any formulas that are within the string.
'no comment
 
bfwolf
Senior Member

Joined: 03/01/2025
Location: Germany
Posts: 178
Posted: 05:58pm 07 Mar 2026
Copy link to clipboard 
Print this post

  DigitalDreams said  Am I asking too much of val(x$) ?


Yes, you're asking too much of `VAL(s$)`. This function (as it exists in the BASIC dialect) simply tries to find a number within a string and returns the value after the first match. It doesn't evaluate any expressions!

Try `EVAL(s$)`, which is fortunately available in MMBasic!

Will evaluate 'string$' as if it is a BASIC expression and return the result.
'string$' can be a constant, a variable or a string expression. The expression can
use any operators, functions, variables, subroutines, etc that are known at the
time of execution. The returned value will be an integer, float or string
depending on the result of the evaluation.
For example: S$ = "COS(RAD(30)) * 100" : PRINT EVAL(S$)
Will display: 86.6025
 
DigitalDreams
Regular Member

Joined: 03/05/2025
Location: United Kingdom
Posts: 53
Posted: 06:25pm 07 Mar 2026
Copy link to clipboard 
Print this post

  bfwolf said  
  DigitalDreams said  Am I asking too much of val(x$) ?


Yes, you're asking too much of `VAL(s$)`. This function (as it exists in the BASIC dialect) simply tries to find a number within a string and returns the value after the first match. It doesn't evaluate any expressions!

Try `EVAL(s$)`, which is fortunately available in MMBasic!


Thanks !, that's the ticket. I'm about to print a truncated version of the latest user manual so none to hand...
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026