converting from AnsiString to integer

J

JNY

Hi,

I'm using a GUI Edit box to allow the user to enter a number. This
data is stored as an AnsiString. I need it in Integer format, but
cannot convert between the two. I found AnsiString::ToINT in the help
file, and have tried to impliment it thus:

int myValue = AnsiString::ToInt(Edit1 -> Text);

This doesn't work. Edit1 is the Edit Box, and Text, is an attribute
of said box. I am using Borland Builder5. This is the only GUI
compiler which I've used, so I'm not sure if this syntax is common to
others.

Can anyone help?

Cheers
JNY
 
V

Victor Bazarov

JNY said:
I'm using a GUI Edit box to allow the user to enter a number. This
data is stored as an AnsiString. I need it in Integer format, but
cannot convert between the two. I found AnsiString::ToINT in the help
file, and have tried to impliment it thus:

int myValue = AnsiString::ToInt(Edit1 -> Text);

This doesn't work. Edit1 is the Edit Box, and Text, is an attribute
of said box. I am using Borland Builder5. This is the only GUI
compiler which I've used, so I'm not sure if this syntax is common to
others.

No, it's not common. There is no GUI in C++, it's all platform-
and compiler-specific.
Can anyone help?

Somebody in one of borland.public.cppbuilder.* NGs certainly can.

V
 
L

Lawrence F. Permenter

A fine GUI programming capability for C++, which compiles for UNIX,
LINUX, Macintosh and windows is TROLLTECH Qt. Just Google to their web
site. It has a complete set of edit boxes and other I/O features that
you may find useful. There are commercial=$ and free versions of Qt,
depending on your needs.

LFP
 
H

Howard

JNY said:
Hi,

I'm using a GUI Edit box to allow the user to enter a number. This
data is stored as an AnsiString. I need it in Integer format, but
cannot convert between the two. I found AnsiString::ToINT in the help
file, and have tried to impliment it thus:

int myValue = AnsiString::ToInt(Edit1 -> Text);

Documentation is a good thing. :) Look up the definition of ToInt() (in
the online Help, or your manual, or on a newsgroup or website devoted to the
compiler you're using). My guess is that it takes no parameters at all, and
that it returns an int. Also, I'm guessing that the Text member of Edit1's
class is an AnsiString? If my guesses are correct (check the manual!), that
call should be

int MyValue = Edit1->Text.ToInt();

-Howard
 
D

Duane Hebert

Howard said:
Documentation is a good thing. :) Look up the definition of ToInt() (in
the online Help, or your manual, or on a newsgroup or website devoted to the
compiler you're using). My guess is that it takes no parameters at all,
and

newsgroups.borland.com
Look for groups with VCL in the title.
that it returns an int. Also, I'm guessing that the Text member of Edit1's
class is an AnsiString? If my guesses are correct (check the manual!), that
call should be

int MyValue = Edit1->Text.ToInt();

That should be wrapped with a try/catch as ToInt() throws
an EConvertError if it can't convert the string. See also
ToIntDef().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top