Obtaining text from text field

Currently i am developing a palm programme. i am trying to capture the user input then convert it to int or float and do some calculation with it.Anyone can help
Who is Participating?
The problem is that you are using FplDiv which takes a FloatType - this is a structure NOT a simple type - as the type for both the dividend and the divisor.  That explains your error message.  You will get this error because you are dividing by 100 (implicitly an integer).

   Convert a long integer to a floating-point number.

   FloatType FplLongToFloat (Long x)

   x A long integer.

   Returns the floating-point number.

   Divide two floating-point numbers (result = dividend/divisor).

   FloatType FplDiv (FloatType dividend, FloatType divisor)

   dividend Floating-point dividend.
   divisor Floating-point divisor.

   Returns the normalized floating-point result of the division.

Under Palm OS 2.0 and later, most applications will want to use the
arithmetic symbols instead. See the “Floating-Point” section in the
Palm OS Programmer’s Companion.

Try this ...

FloatType varFloat2;  
FloatType varFloatDivisor100;
FloatType varFloatResult;

field2 = FrmGetObjectPtr(frmP, wIDField2);
pText2 = FldGetTextPtr(field2);

varFloat2 = FplAToF(pText2);
varFloatDivisor100 = FplLongToFloat((Long) 100);
varFloatResult = FplDiv(varFloat2, varFloatDivisor100);

Keep in mind the following from the Reference PDF file ...

Palm OS 1.0 provided 16-bit floating point arithmetic. Instead of
using standard mathematical symbols, you called functions like
FplAdd, FplSub, and so on.

Palm OS 2.0 and later implements floating point arithmetic
differently than Palm OS 1.0 did. The floating-point library in OS
versions 2.0 and later provides 32-bit and 64-bit floating point

Using Floating Point Arithmetic
To take advantage of the floating-point library, applications can now
use the mathematical symbols + – * /instead of using functions like
FplAdd, FplSub, etc.
When compiling the application, you have to link in the floating
point library under certain circumstances. Choose from one of these

 Simulator application or application for 1.0 device — link in
the floating point library explicitly.
This library adds approximately 8KB to the size of your prc
file. The library provides 32-bit and 64-bit floating-point
arithmetic. The original Palm OS Fpl functions provided
only 16-bit floating-point arithmetic. Linking in the library
explicitly won’t cause problems when you compile for a 2.0

 2.0 or later Palm OS device—It’s not necessary to link in the
The compiler generates trap calls to equivalent floating-point
functionality in the system ROM.
There are control panel settings in the IDE which let you select the
appropriate floating-point model.
Floating-point functionality is identical in either method.
Using 1.0 Floating-Point Functionality
The original Fpl calls (documented in the chapter “Float Manager”
in the Palm OS SDK Reference) are still available. They may be useful
for applications that don’t need high precision, don’t want to incur
the size penalty of the float library, and want to run on 1.0 devices
only. To get 1.0 behavior, use the 1.0 calls (FplAdd, etc.) and don’t
link in the library.

FYI, as an aside ...

If you are going to have values around that you want to have to hundredths place - two decimal digits, it is often cheaper computationally to deal with the number as a whole number at the granualarity of hundredths and then do something like:

// Integer division
int WholePart = Number / 100;
int Hundredths = Number % 100;

The same would apply to longs and unsigned longs.

For example if you were calculaating an order form you could use whole numbers as I described using unsigned longs instead of floats, as long as you didn't have to deal with numbers greater than 42 million or so.

Floating Point numbers for currency is generally overkill.

CodecAuthor Commented:
Help Desperate.....
do you want to do it in C++
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

CodecAuthor Commented:
i am using a software call Codewarrior using C++ language...i wonder it will work if i use in MS C++
have you looked at the atol and atoi functions ??
CodecAuthor Commented:
Codewarrior do not support atol or atoi
instead FplAtoi...i tried this but cannot.....it gimme compilation errors saying cannot "struct"to"int"....
Can you post the code that gave the error, and the prototype for "Atoi", and maybe we can help....

You definitely want to use the library's Atoi function, instead of writing your own.
You should post this in the Palm Programming section or join the Palm developer list - instructions are on the Palm developer site - and post your question there.

You cannot use standard functions like atoi() and the non-standard itoa() on a palm development platform - you must use their (Palm's) API equivolents.

Did you  download the Palm SDK documents for the version of the Palm OS ROM you are developing for?

CodecAuthor Commented:
i did d/l it but...it give me all kind of error...like  i said the error....cannot convert "struct" to "int"...do u know what is this?
Have you tried "casting",
CodecAuthor Commented:
how to cast can u show me?
Here is Microsoft's Description.Type-Cast Conversions
You can use type casts to explicitly convert types.


cast-expression :

unary expression
( type-name ) cast-expression

type-name :

specifier-qualifier-list abstract-declarator opt

The type-name is a type and cast-expression is a value to be converted to that type. An expression with a type cast is not an l-value. The cast-expression is converted as though it had been assigned to a variable of type type-name. The conversion rules for assignments (outlined in Assignment Conversions) apply to type casts as well. Table 4.5 shows the types that can be cast to any given type.

Table 4.5   Legal Type Casts

Destination Types Potential Sources
Integral types Any integer type or floating-point type, or pointer to an object
Floating-point Any arithmetic type
A pointer to an object, or (void *) Any integer type, (void *), a pointer to an object, or a function pointer
Function pointer Any integral type, a pointer to an object, or a function pointer
A structure, union, or array  None
Void type Any type

Any identifier can be cast to void type. However, if the type specified in a type-cast expression is not void, then the identifier being cast to that type cannot be a void expression. Any expression can be cast to void, but an expression of type void cannot be cast to any other type. For example, a function with void return type cannot have its return cast to another type.

Note that a void * expression has a type pointer to void, not type void. If an object is cast to void type, the resulting expression cannot be assigned to any item. Similarly, a type-cast object is not an acceptable l-value, so no assignment can be made to a type-cast object.

Microsoft Specific —>

A type cast can be an l-value expression as long as the size of the identifier does not change. For information on l-value expressions, see L-Value and R-Value Expressions.

END Microsoft Specific

You can convert an expression to type void with a cast, but the resulting expression can be used only where a value is not required. An object pointer converted to void * and back to the original type will return to its original value.

Firstly, you shouldn't need to do any casting at all to do what you want.  

Second, you have to be careful with your decision to use C++ to develop for the Palm OS environment - there are many restrictions that you might encounter depending on the type of application you are building.  There are good reasons why, for now at least, that C is the language of choice for the Palm platform.  To be clear - the Palm environment is NOT anything like developing a regular PC application.  It is more like developing an embedded application for a specialized processor/OS combination - it just happens to have UI.

Third, you should download the SDK files for the versions of the Palm Pilot OS ROMs (e.g. 2.0, 3.0, 3.1, 3.2, etc) as you have to watch out for OS changes that might affect your development efforts - though there shouldn't be be an effect for the problem you are inquiring about.

If you haven't done this already, downlaod the SDK documentation for the Palm OS ROM you will be developing for - they are available in PDF format from the Palm Developers web site.

I would recommend that you use the downloaded SDKs from Palm rather than what was installed with Code Warrior as Palm is the authoritative source for the SDK and Metrowerks is a cross-platform compiler vendor.

Here are some of the relevant functions to help you a little bit.

   Return a pointer to the text string of a field, or NULL.

   CharPtr FldGetTextPtr (FieldPtr fld)

   fld Pointer to a field object (FieldType Structure).

   Returns a pointer to t text string of a field; NULL is a possible value.

See Also
   FldSetTextPtr, FldGetTextHandle


    Convert a zero-terminated ASCII string to a floating-point number.
    The string must be in the format : [-]x[.]yyyyyyyy[e[-]zz]

    FloatType FplAToF (char* s)

    s Pointer to the ASCII string.

    Returns the floating-point number.

    The mantissa of the number is limited to 32 bits.


    Convert a string to an integer.

    Int StrAToI (CharPtr str)

    str String to convert.

   Returns the integer.

    Use this function instead of the standard atoi routine.

Note that CharPtr is a typedef in common.h defined as:

typedef char * CharPtr;

So that char * and CharPtr are one and the same.

If you are going to need help getting Field pointers (FldPtr) and such, then you really need to get the docs downloaded and start reading.  You can also buy Neil Rhodes' book from O'Reilly or download it or read it online at the Palm developers web site.

The Palm developers web site is:


I suggest you follow wylliker's advice.
CodecAuthor Commented:
i am capturing user input ...i have this compilation error...cannot convert "float" to "Struct"error is
                   /*cal1 = */FplDiv(num1,100);

                   wIDField2 = FrmGetObjectIndex(frmP,

                   field2 = FrmGetObjectPtr(frmP, wIDField2);
                   pText2 = FldGetTextPtr(field2);

                   if (FldGetTextLength(field2)>0)
                   //pText2 = (CharPtr)MemHandleLock(hText2);

                   num1 = StrAToI(pText1);
                   num2 = StrAToI(pText2);
                   /*cal1 = */FplDiv(num1,100);

but if  i change it to FplAToF..it gimme the same errors
"wylliker" may be able to help you with this code. I'll defer to that person.
CodecAuthor Commented:
it kind of funny i did read the part about the Palm OS 2 but when i run the codes in POSE..it tell..me i am performing a floating point operation sort of stuff...
CodecAuthor Commented:
after changing all the codes ...to what u have taught me...
it gimme this error..illegal operand..
at every if statement e.g..if (cal3 < 18.5)

if (cal3 < 18.5)
            err1 = FrmAlert(Report1Alert);
      else if (cal3 >=18.5 & cal3 <= 24.9)
            err2 =       FrmAlert(Report2Alert);
      else if (cal3 > 25.0 & cal3 <= 29.9)
            err3 =       FrmAlert(Report3Alert);
      else if (cal3 >= 30.0)
            err4 =       FrmAlert(Report4Alert);
CodecAuthor Commented:
Your advice is very impressive and persuasive...last of all..Thanx a million
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.