[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Obtaining text from text field

Posted on 2000-03-23
20
Medium Priority
?
257 Views
Last Modified: 2010-04-10
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
0
Comment
Question by:Codec
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 4
  • 3
  • +3
20 Comments
 

Author Comment

by:Codec
ID: 2651962
Help Desperate.....
0
 
LVL 2

Expert Comment

by:homer99
ID: 2651964
do you want to do it in C++
0
 

Author Comment

by:Codec
ID: 2652503
i am using a software call Codewarrior using C++ language...i wonder it will work if i use in MS C++
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Expert Comment

by:DarrinE
ID: 2652710
have you looked at the atol and atoi functions ??
0
 

Author Comment

by:Codec
ID: 2652845
Codewarrior do not support atol or atoi
instead FplAtoi...i tried this but cannot.....it gimme compilation errors saying cannot "struct"to"int"....
0
 
LVL 2

Expert Comment

by:abesoft
ID: 2653665
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
 
LVL 4

Expert Comment

by:wylliker
ID: 2655572
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 Comment

by:Codec
ID: 2655634
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
 

Expert Comment

by:dolphin203
ID: 2655739
Have you tried "casting",
0
 

Author Comment

by:Codec
ID: 2655807
how to cast can u show me?
0
 

Expert Comment

by:dolphin203
ID: 2656037
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
 
LVL 4

Expert Comment

by:wylliker
ID: 2657514
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.

See Also
   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.

Comments
    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
 

Expert Comment

by:dolphin203
ID: 2657703
I suggest you follow wylliker's advice.
0
 

Author Comment

by:Codec
ID: 2657898
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
 

Expert Comment

by:dolphin203
ID: 2658245
"wylliker" may be able to help you with this code. I'll defer to that person.
0
 
LVL 2

Expert Comment

by:DarrinE
ID: 2658657
.listening
0
 
LVL 4

Accepted Solution

by:
wylliker earned 300 total points
ID: 2658872
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
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
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
FplAdd, FplSub, etc.
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.
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
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
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.







0
 

Author Comment

by:Codec
ID: 2659323
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 Comment

by:Codec
ID: 2659407
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);
0
 

Author Comment

by:Codec
ID: 2659505
Your advice is very impressive and persuasive...last of all..Thanx a million
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question