Source language: Translate to:

Math expressions in control commands

NeoBook tips, tricks, code samples and more...

Moderator: Neosoft Support

Math expressions in control commands

Postby reinier maliepaard » Fri Jul 08, 2016 6:53 am

Hello,

You probably know the use of math expressions in Neobook's SetVar:

Code: Select all
SetVar "[z]" "10"
SetVar "[z]" "[z]+1"

However, math expressions can used in e.g. the control commands If, IfEx, While, WhileEx and Loop also, resulting in shorter code. I did not find a post on this topic. So I made some examples for you and hope you'll find these helpful.

Best regards,
Reinier

Code: Select all
...................................................................
.Examples of math expressions in Neobook's SetVar and
.control commands If, IfEx, While, WhileEx and Loop
...................................................................
SetVar "[x]" "3"
SetVar "[y]" "2"
SetVar "[z]" "1"
...................................................................
...................................................................
While "[z]" "<" "3"
 AlertBox "Result 1" "Value of variable z: [z]"
 SetVar "[z]" "[z]+1"
EndWhile
......................................................................
If "[x]+[y]" ">" "[z]"
 AlertBox "Result 2" "[x]+[y] > [z] is TRUE"
Else
 AlertBox "Result 2" "[x]+[y] > [z] is FALSE"
EndIf
......................................................................
IfEx "[x]+[y] > [z] AND [x]-[y] = [z]"
 AlertBox "Result 3" "[x]+[y] > [z] AND [x]-[y] = [z] is TRUE"
Else
 AlertBox "Result 3" "[x]+[y] > [z] AND [x]-[y] = [z] is FALSE"
EndIf
......................................................................
WhileEx "[x]^2 > 0 AND [x]*[y] > 0"
  AlertBox "Result 4" "Value of variable x and y: [x] and [y]"
  SetVar "[x]" "[x]-1"
  SetVar "[y]" "[y]-1"
EndWhile
......................................................................
.initialize [y] again because of the last example
SetVar "[y]" "2"
......................................................................
If "Sqrt([y])" "<" "[z]"
 AlertBox "Result 5" "Sqrt([y]) < [z] is TRUE"
Else
 AlertBox "Result 5" "Sqrt([y]) < [z] is FALSE"
EndIf
......................................................................
.solving an equation for a > 0
Loop "1" "Sqr([y]+[z])" "[a]"
 If "[a]*[a]-3*[a]-3" "=" "[a]-3"
  AlertBox "Result 6" "a*a-3a-3 = a-3 is TRUE for value [a]"
  ExitLoop
 EndIf
EndLoop
......................................................................
......................................................................
. Try it yourself and use Neobook's math operators and functions:
. +  -  *  /  ^
. Abs
. Sin  Cos  Atan,
. Sqr  Sqrt  Round Trunc
reinier maliepaard
 
Posts: 30
Joined: Sat Jan 17, 2009 2:53 pm

Re: Math expressions in control commands

Postby Neosoft Support » Fri Jul 08, 2016 5:46 pm

I think you're right that not everyone is aware of this. Thank you for posting it.
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5603
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Re: Math expressions in control commands

Postby Wrangler » Sun Jul 10, 2016 10:00 am

Thanks, Reinier!
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1507
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA


Return to NeoBook Knowledgebase

Who is online

Users browsing this forum: No registered users and 1 guest