Re: Win32: number to text box
- Posted by Derek Parnell <ddparnell at bigpond.com> Oct 17, 2001
- 396 views
Hi Sim, ----- Original Message ----- From: "Sim" <simadan at Hotmail.com> To: "EUforum" <EUforum at topica.com> Subject: Win32: number to text box > > Hello, > Yesterday, I asked how to convert a number from a textbox (SLE) to > an atom. I followed Dan Moyer's adviced and used value(). (I'm creating > a calculator using the Win32Lib.ew.) Now that I have computed a > numerical number, I need to convert the number/atom into a string/text > and then output that string/text to a textbox (SLE). I haven't found > any library functions that can help me with the conversion. > Anyone have any ideas? > > This is part of the error message I got when I tried to multiply 5 with > 6 and then put the answer (30) in a text box (SLE): > > D:\EUPHORIA\include\Win32lib.ew:6865 in procedure setText() > type_check failure, s is 25 > pID = 7 > s = 25 > ptr = <no value> > result = <no value> > id = <no value> > lPart = <no value> > > > If s is a sequence/string, then shouldn't "s" be displayed in the > textbox when I use setText()? > > > Here is the code: > > > atom answer1, num1, num2 > > --... some other code that works > > answer1 = num1 * num2 > setText(tboxOut, answer1) > > > I tried declaring "answer1" as a sequence, but when I clicked the > button, the textbox was cleared for some odd reason. > > My appologies if you are not used to the naming conventions I've > used: I'm used to using Visual Basic and Window's naming convention. > > Thanks, > Sim The win32lib already has a getNumber() function that works like getText(), only it returns an atom (number) instead of a sequence (text). The setText() routine current insists on using a sequence as its second parameter. You must convert the number back into a sequence before you use setText(). So, using you sample code.... atom answer1, num1, num2 --... some other code that works num1 = getNumber(fld1) num2 = getNumber(fld2) answer1 = num1 * num2 -- Format the number before displaying it. setText(tboxOut, sprintf("%6.3f",answer1)) Now if you're feeling adventurous, here is a little enhancement you can place in the win32lib ... Change the parameter definition from ... global procedure setText( object pID, sequence s ) to global procedure setText( object pID, object s ) As the first executable code in the setText() routine, add these five lines... if atom(s) then s = sprintf("%g", s) elsif length(s) > 0 and sequence(s[1]) then s = sprintf(s[1], {s[2]}) end if This will allow you to this sort of stuff... setText(tboxOut, {"%6.3f",answer1} ) or if formatting is not an issue, just setText(tboxOut, answer1) It makes other stuff a bit easier too... setText(tMsgArea, {"Error: The file '%s' is too long (%d bytes)", {sFileName, iFileSize}} ) -------------