How to convert Text Strings to Numeric Values on LUA


We are using the script found below for logic validation on a Van Westendorp Analysis. The survey question is prompting a response in dollars but the code is currently reading the number responses as text strings.  Wondering if anyone knowledgable in lua might know how to write the script so the responses are read numeric. The entire code can be found below. Thanks!

— Begin init

— Set first ID to page with van westendorp questions
— Set second ID to ID of the error message text element
previouspageid = 14
errormessageid = 173

— Pulling values from the 4 Van Westendorp questions using their question IDs and getvalue
tooexpensive = getvalue(32)
expensive = getvalue(29)
toocheap = getvalue(31)
bargain = getvalue(27)

— End init
— Begin comparisons

— Check for incorrect scenarios
if toocheap >= bargain or bargain >= expensive or expensive >= tooexpensive then
–Show error message
–Send ’em back
–Passed validation, so hide error in case respondent would like to change values

— End comparisons

Lili OquotReilly answered

    You can use the LUA function tonumber(str), which will return a nil or a number.

    Lili OquotReilly answered


      Question stats

      • Active
      • Views1318 times
      • Answers1 answer
      • Followers1 follower