Page 1 of 1

cannot pass 16-digit number to function as string argument

Posted: Jan 2nd, '18, 00:58
by manyone
i was trying to pass a string of 16 digits as a string to a function but the argument is treated as a number , not as a string, so it becomes garbled.
arglen_err.jpg
converting the number string to a list argument works but i have to change the function logic accordingly,
arglen_fix.jpg
it also works if i create an artificial string by surrounding it with quotes or apostrophes, or prefixing with some special character but i have to deal with removing them in the function.

Re: cannot pass 16-digit number to function as string argument

Posted: Jan 2nd, '18, 04:43
by JohnM
Many GP input slots (such as the one in the 'return' block) accept either a number or a string. They guess the type based on what you type. If the string has the correct syntax for an integer or floating point numbers, it guesses that you intend for it to be a number. When GP guesses that the input is a number, it changes the shape of the input slot from rectangular (string) to rounded (number).

In this case, however, you want to pass a string of 16 digits, and you want GP to treat it as a string, even though it has the syntax of a (large!!) integer. There are two ways to tell GP what you mean.

First, you can use a menu to set the input slot to "string only":

Screen Shot 2018-01-01 at 8.33.09 PM.png
Screen Shot 2018-01-01 at 8.33.09 PM.png (16.17 KiB) Viewed 8140 times
Note that the slot remains rectangular, indicating that it will be treated as a string.

Second, you can use the "quotes" block from the "Words" category:

Screen Shot 2018-01-01 at 8.41.34 PM.png
The former requires one less block but isn't as obvious or easily discovered.

Re: cannot pass 16-digit number to function as string argument

Posted: Jan 2nd, '18, 05:31
by manyone
thank you! i wish i had known this sooner!