string conversion isn't working.

Started by John on 29-Apr-2014/2:41:03-7:00
Hi I'm sure there must be something easy that I am missing here but I can't get a test for to-string conversion to work when all the other conversion from integer to time are working. Here is the text:R E B O L [] fldblk:[vi to-integer vn to-string vdc to-decimal vdt to-date vtm to-time vmn to-money] errchk: func [fldblk errblk ][ -i: 0 -foreach [fld tp] fldblk [ --;print errblk --;print i --f: get fld --print rejoin [tp " " f/text] --if error? try [do rejoin [tp " " f/text]] [i: i + 1 errblk/:i/1: fld errblk/:i/2: "Failed to convert"] -] ] view gui: layout[ -vi: field -vn: field -vdc: field -vdt: field -vtm: field -vmn: field - -button "val" [ --errblk: array [6 2] copy [] --errchk fldblk errblk --either errblk/1/1 == none [ ---alert "Good Entry" --][ ---alert reform ["Errors " errblk/1/2] ---print to-string errblk/1/1 ---focus get errblk/1/1 ---print errblk ---return --] -] ]
The vn field has a to-string conversion but when a string is entered the test gives an error. Why is that?
In fact the conversion works when I enter a number into the vn field.
After looking at it further, it seems that if i put something like "sss" in the vn field that when it goes to "do rejoin [tp " " fld]" that it gets a script error . If i literally try this in console mode do rejoin [to-string " " "sss"] it produces the script error saying sss has no value whereas it doesn't say this for to-integer " " "10".
In fact to continue the above example if i say do rejoin [to-string " " "10"] that works but put "sss" in place of the 10 and it doesn't work in converting a string. apparently it thinks "sss" is a variable.
When you 'do an integer value, the result evaluates just as if you've typed the integer into the console. Likewise, when you 'do a random string of characters, it's just as if you'd typed those characters into the console. So, if the 'sss word isn't defined, you get the expected error: >> 10 == 10 >> sss ** Script Error: sss has no value ** Near: sss >> do 10 == 10 >> do "sss" ** Script Error: sss has no value ** Near: sss By default, any set of characters typed into a field can be treated as a string. What case are you intending to test for by validating a string data type?
That is a good point Nick. I don't have any real case that I was intending to test for by converting a string into a string. But I was curious why it was so darn difficult to do it. :). Maybe I should just skip doing an empty validation since anything goes in that field.
However, an expedient solution might be to put some null action in the position of the to-conversion value. vi to-integer vn magicnullaction vdc etc.. Got a suggestion?
You should really take a look at 'parse. All the validation possibilities are handled more effectively with it.
As it stands, you can just leave "vn to-string" out of your fldblk.

Reply