Home AMX User Forum AMX General Discussion

Going through a string as an array - what did i do?

For (i=1;i<=LENGTH_STRING(data.text);i++)
	    {
		If (debug) SEND_STRING 0,"'PARSING! step:',ITOA(i),' is ',data.text[i],'.'"
		strStatus = data.text[i]
		intStatus = ATOI(strStatus)
		strZone = ITOA(i)



Okay, my debug line prints what I expect, as data.text is simply a long string of numbers (coming back from a security system). So data.text = '222200004444' etc...

It prints the debug as step:1 is 4. That seems fine and dandy.

Why can't I convert that to an int with ATOI? I tried ATOI(data.text) and the code above, same error no matter what I do, not a compile error but a runtime error on the ATOI routine.

I know it is late, but am I doing something really wrong?

Curt

Comments

  • Joe HebertJoe Hebert Posts: 2,159
    TrikinCurt wrote: »
    Why can't I convert that to an int with ATOI? I tried ATOI(data.text) and the code above, same error no matter what I do, not a compile error but a runtime error on the ATOI routine.
    Try changing this:
    ATOI(data.text)

    To this
    ATOI(?data.text?)

    ATOI() requires a string and Netlinx (right or wrong) does not interpret one character as a string. The double quotes forces it into a string and satisfies ATOI(). I?ve been told to always use double quotes with ATOI() to avoid any possible ambiguity.
  • TrikinCurtTrikinCurt Posts: 158
    Thanks so much! Makes sense why the debug print worked since it was in double quotes!

    All better, thanks again,

    Curt
    Joe Hebert wrote: »
    Try changing this:
    ATOI(data.text)

    To this
    ATOI(?data.text?)

    ATOI() requires a string and Netlinx (right or wrong) does not interpret one character as a string. The double quotes forces it into a string and satisfies ATOI(). I?ve been told to always use double quotes with ATOI() to avoid any possible ambiguity.
Sign In or Register to comment.