Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Integers and ini files

Status
Not open for further replies.

fergmj

Programmer
Feb 21, 2001
276
US
I have an Edit Box on a form. The name of the Edit Box is Interval. I want a person to enter a number in the edit box and write that number to an ini file like this:

ini->WriteInteger("com 1", "Search Interval", Interval->Text);

However i get an error because the TextBox wants an ANSI String.

I have tried StrToInt and IntToStr conversions with no luck. Does anyone have any advice?

Thanks

fergmj
 
how about sprintf?
#include<stdio.h>
.....
char* x=new char[10];
sprintf(x,&quot;%d&quot;,12345);
....
delete[] x; John Fill
1c.bmp


ivfmd@mail.md
 
I use IntToStr and StrTo Int all the time. Where exactly is you problem? What is the error? Why don't they work, what happens?

James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
Try that:

ini->WriteInteger(&quot;com 1&quot;, &quot;Search Interval&quot;, StrToInt(Interval->Text));

I just wrote one of those today, it should work.
if that doesn't work, you could work around your problem:

make an int, name it int x;

when the user presses the OK button, or presses enter, or whatever they do to input the Text in Interval, type in this code:

x = StrToInt(Interval->Text);
ini->WriteInteger(&quot;com 1&quot;, &quot;Search Interval&quot;, x); Cyprus
 
Greetinx!

You should use methods of AnsiString like that:

ini->WriteInteger(&quot;com 1&quot;, &quot;Search Interval&quot;, Interval->Text.ToInt());
or
ini->WriteInteger(&quot;com 1&quot;, &quot;Search Interval&quot;, Interval->Text.ToIntDef(0));

Difference between this two methods is a exception that is thrown due to illegal integer value in AnsiString in first expample. In second example, the default value (zero in example) will be returned, it AnsiString has illegal integer value.

Happy programming!))) Happy programming!))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top