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?

Commented:
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).

FplLongToFloat
Purpose
Convert a long integer to a floating-point number.

Prototype
FloatType FplLongToFloat (Long x)

Parameters
x A long integer.

Result
Returns the floating-point number.

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

Prototype
FloatType FplDiv (FloatType dividend, FloatType divisor)

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

Result
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 ...

Floating-Point
Palm OS 1.0 provided 16-bit floating point arithmetic. Instead of
using standard mathematical symbols, you called functions like

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
arithmetic.

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

 Simulator application or application for 1.0 device — link in
the floating point library explicitly.
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
library.
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

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.

0

Author Commented:
Help Desperate.....
0

Commented:
do you want to do it in C++
0

Author Commented:
i am using a software call Codewarrior using C++ language...i wonder it will work if i use in MS C++
0

Commented:
have you looked at the atol and atoi functions ??
0

Author Commented:
Codewarrior do not support atol or atoi
instead FplAtoi...i tried this but cannot.....it gimme compilation errors saying cannot "struct"to"int"....
0

Commented:
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.
0

Commented:
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?

0

Author 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?
0

Commented:
Have you tried "casting",
0

Author Commented:
how to cast can u show me?
0

Commented:
Here is Microsoft's Description.Type-Cast Conversions
You can use type casts to explicitly convert types.

Syntax

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.

0

Commented:
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.

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

Prototype
CharPtr FldGetTextPtr (FieldPtr fld)

Parameters
fld Pointer to a field object (FieldType Structure).

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

FldSetTextPtr, FldGetTextHandle

FplAToF

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

Prototype
FloatType FplAToF (char* s)

Parameters
s Pointer to the ASCII string.

Result
Returns the floating-point number.

Comment
The mantissa of the number is limited to 32 bits.

StrAToI

Purpose
Convert a string to an integer.

Prototype
Int StrAToI (CharPtr str)

Parameters
str String to convert.

Result
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:

http://www.palm.com/devzone

0

Commented:
0

Author Commented:
i am capturing user input ...i have this compilation error...cannot convert "float" to "Struct"error is
here
/*cal1 = */FplDiv(num1,100);

wIDField2 = FrmGetObjectIndex(frmP,

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

if (FldGetTextLength(field2)>0)
{
hText2=FldGetTextHandle(field2);
//pText2 = (CharPtr)MemHandleLock(hText2);
//StrCopy(pText22,pText2);

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

but if  i change it to FplAToF..it gimme the same errors
0

Commented:
"wylliker" may be able to help you with this code. I'll defer to that person.
0

Commented:
.listening
0

Author 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...
0

Author 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)
else if (cal3 >=18.5 & cal3 <= 24.9)
else if (cal3 > 25.0 & cal3 <= 29.9)
else if (cal3 >= 30.0)
0

Author Commented: