Page 1 of 1

How to operate with variables and conditions?

Posted: Thu Oct 08, 2020 10:27 pm
by atibati
Sometimes it's needed to change variable that is number to variable that is string. And sometimes any variable to boolean.

I've tried this construction

Code: Select all

if
   ·  Core.ToBoolean
         ·  result
   ·  [ifTrue]
   ·  [ifFalse]
, but it appears with execution failed when the variable result is not empty string.
- i need something to convert strings into false when it's empty string or void, but into true, when it's not empty string.

Re: How to operate with variables and conditions?

Posted: Fri Oct 09, 2020 5:59 pm
by webmaster
Core.ToBoolean just parses a "true" or "false" value into a boolean, so it won't work with empty strings. But you can write your own function using String.IsMatch and the negation operator. The following will return false when the string is empty and true when not:

Code: Select all

function (text)
   not
      ·  String.IsMatch
            ·  "^$"
            ·  text
And this will return false when the string is empty or whitespace, and true when not:

Code: Select all

function (text)
   not
      ·  String.IsMatch
            ·  "^\\s*$"
            ·  text
If you put any of those functions in a global (say you call it StringHasValue), you can then use it like:

Code: Select all

if
   ·  StringHasValue
         ·  result
   ·  [ifTrue]
   ·  [ifFalse]

Re: How to operate with variables and conditions?

Posted: Sat Oct 10, 2020 1:23 am
by atibati
Thank you. Work fine. But spend around 3 hours on finding and fixing a bug associated with this code. Also edited one of premades - chenged Sequence.First to Sequence.FirstOrDefault, and now it works fine.

Would be happy to be able add variables into code directly and print variables like function Alert in javascript (btw, i'm not js programer), for faster debug.