Can't compare global variable with entered text?

advanced-prototyping

#1

Scratching my head on this, I have what seems like a simple check on an input field to show that if you type the wrong value in then it should show an error.

The check is “If the number entered on the field does not equal the number in the global variable, show error”

But this always evaluates as true. What’s up with that? See attached demo.

Quantity-Tester.rp (62.5 KB)

BTW the “target quantity” is a random number on page load.


#2

Short answer: change the case for the Check button to:

If text on QuantEntered does not equal “[[Number * 1]]”)
Show Error


This has to do with Axure using the same “var type” for both strings and numbers, so I think it turns out in your prototype you are comparing a number to a string (where 3 does not equal “3” --if that makes any sense) --and Axure isn’t converting the var types correctly, the way you would expect. …Or it’s something like that.

You can force Axure to treat a variable (global variable, local variable (the LVAR1 pointer), or function return) as a “true number” if you perform some math with it. I think of this as “manually converting” a string to a number. The simplest way to do this is [[LVAR1 * 1]] , or in your example with a global variable named “Number”, [[Number * 1]].

Now I’m scratching my head because I thought the fix would be to “manually convert” the text value on your Text Field (named “QuantEntered”) to a number and comparing that to the global variable, named “Number” which you set to a random number in OnPageLoad event. But that doesn’t do it. However, when I converted the global variable (using [[Number * 1]] ) it works correctly. :thinking:

I checked this out (no pun intended) on RP9 and the same behavior (bug) happens. Confusing.


#3

Another, more immediate problem is the space preceding the random number in the global variable:

image

J


#4

Ah - that space looks like it might be the issue! Unfortunately, I’ve just spent 16 hours re-writing the whole thing to do it differently :blush:

Such is life… But it’s a good learning!