473,399 Members | 3,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

system::string to int with VC++

hello all, i've a problem :s

i've tried to convert a "system::string" (a textbox) to an "int" but i
have only found a function to convert system::string to char and char
to int :s :

Convert::ToInt32(PtrToStringChars(ligne23->Text));

but i get a bug :s can you help me ? (sorry for my english i'm french)

Apr 6 '06 #1
11 11838
i've tried to convert a "system::string" (a textbox) to an "int" but i
have only found a function to convert system::string to char and char
to int :s :

Convert::ToInt32(PtrToStringChars(ligne23->Text));


It should be no problem to convert a string to an int32 like this:
Convert::ToInt32(ligne23->Text);

Have you tried it, and if so, What happens when you do that? which input do
you supply, and what output value do you get?

--

Kind regards,
Bruno.
br**********************@hotmail.com
Remove only "_nos_pam"
Apr 6 '06 #2
hello all, i've a problem :s

i've tried to convert a "system::string" (a textbox) to an "int" but i
have only found a function to convert system::string to char and char
to int :s :

Convert::ToInt32(PtrToStringChars(ligne23->Text));

but i get a bug :s can you help me ? (sorry for my english i'm french)


As Bruno mentioned, the correct way is:

Convert::ToInt32(ligne23->Text);

Furthermore, you should always work with the Convert/ToString/Parse/TryParse
overload that includes a IFormatInfoProvider argument, to ensure your code
works well regarding locales/cultures. So, for example, you could do:

Convert::ToInt32(ligne23->Text, CultureInfo::InvariantCulture);
--
Tomas Restrepo
to****@mvps.org
http://www.winterdom.com/
Apr 6 '06 #3
thanks, but with this : Convert::ToInt32(ligne23->Text);

i get an error :

Windows::Forms::Control::Text::set(System::String ^)' : cannot convert
parameter 1 from 'int' to 'System::String ^'

Apr 6 '06 #4
> thanks, but with this : Convert::ToInt32(ligne23->Text);

i get an error :

Windows::Forms::Control::Text::set(System::String ^)' : cannot convert
parameter 1 from 'int' to 'System::String ^'


Could you show some of the surrounding code?
because it seems that it is not the convertsion but something else that is
wrong.
to what are you assigning the resulting converted value?

could it perhaps be something like this:
myControl->Text = Convert::ToInt32(ligne23->Text);

--

Kind regards,
Bruno.
br**********************@hotmail.com
Remove only "_nos_pam"

Apr 6 '06 #5
(i begin in VC++, its not a good code)
......
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e) {
label2->Text=textBox1->Text;
label13->Text=(ligne13->Text+ligne23->Text+textBox3->Text);
//Not good, it concatene the string
if(ligne11->Text!=""){
if(ligne13->Text==""){
label4->Text="veuillez saisir correctement votre Compta!!\nLigne
1 erronnée";
}
else{
label4->Text="bravo, tu sais ce que c qu'enregistré!!";
}
}
........
(it's a part of an accountancy program)
i need to get the ligne11 (a textBox) in int to make an addition, but,
the type of the textBox is a string, and it concatenate the values :s

system::string isn't a char, then, i can't convert it directly by
Convert::toint32(ligne13)
=> that's why, i get an error (i think :s)

Apr 6 '06 #6
(it's a part of an accountancy program)
i need to get the ligne11 (a textBox) in int to make an addition, but,
the type of the textBox is a string, and it concatenate the values :s system::string isn't a char, then, i can't convert it directly by
Convert::toint32(ligne13)
=> that's why, i get an error (i think :s)


If I understand you correctly (my french isn't that good) you want to make
the sum of some values that are typed into a textbox, and then put that into
a result textbox?

you can do that with something like this:
Int32 sum = Convert::ToInt32(textbox1->Text) +
Convert::ToInt32(textbox2->Text);
textBox3->Text = sum.ToString();

--

Kind regards,
Bruno.
br**********************@hotmail.com
Remove only "_nos_pam"
Apr 6 '06 #7
not in a textbox, in a label, but i just need to change :
mylabel->Text = sum.ToString();
lol i get another error now :p

An unhandled exception of type 'System.FormatException' occurred in
mscorlib.dll

Additional information: Input string was not in a correct format.

Apr 7 '06 #8
it's good!! thanks!! i get this error, because all textbox must be
filled!!
;)

Apr 7 '06 #9
for another code i get :

sum=Convert::ToInt32(ligne13->Text)+Convert::ToInt32(ligne23->Text)+Convert::ToInt32(textBox4->Text);
label13->Text=sum.ToString();
int sum2;
sum2=Convert::ToInt32(ligne14->Text)+Convert::ToInt32(ligne24->Text)+Convert::ToInt32(textBox5->Text);
label15->Text=sum2.ToString();
int sum3=sum-sum2;
label14=sum3.ToString;

sum and sum2 are both integer :s why i get these error ? :

cannot convert from 'overloaded-function' to
'System::Windows::Forms::Label ^'
cannot convert from 'int' to 'System::Windows::Forms::Label ^'

Apr 7 '06 #10
sorry :s the code is this :
sum=Convert::ToInt32(ligne13->Text)+Convert::ToInt32(ligne23->Text)+Convert::ToInt32(textBox4->Text);
label13->Text=sum.ToString();
int sum2;
sum2=Convert::ToInt32(ligne14->Text)+Convert::ToInt32(ligne24->Text)+Convert::ToInt32(textBox5->Text);
label15->Text=sum2.ToString();
int sum3=sum-sum2;
label14->Text=sum3.ToString;
i've Forget the "->Text" :s

Apr 7 '06 #11
All ok, i forget the () behind .ToString
(i begin in programmation :) )
Another question, how can i optimize my code? because my program is
50ko, and use more than 15sec. to appear on my screen!!
It is normal for a .Net Application?

Thanks for your help ;)

Apr 7 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Trep | last post by:
Hi there! I've been having a lot of difficult trying to figure out a way to convert a terminated char array to a system::string for use in Visual C++ .NET 2003. This is necessary because I...
5
by: Jay | last post by:
What is the difference between these two types. The both seem to have the same methods. Is there an advantage to one over the other?
15
by: Yifan | last post by:
Hi Does anybody know how to convert System::String* to char*? I searched the System::String class members and did not find any. Thanks Yifan
8
by: Tony H | last post by:
Is there a way to read an MFC serialized class containing CStrings, ints, and doubles using a CLR-based class? Specifically, to get CString into System::String? Bye the Bye, is System:: String...
7
by: Holger Grund | last post by:
What's special about System::String? For instance, why can't one write a function like using System::String; void foo( const String% ); or what's wrong with: int main() {
2
by: John Swan | last post by:
Hello. I cannot seem to find any documentation upon the STL string. I am simply trying to transfer the contents of a std::string to a System::String where I am coming into difficulties. Any...
24
by: Marcus Kwok | last post by:
Hello, I am working on cleaning up some code that I inherited and was wondering if there is anything wrong with my function. I am fairly proficient in standard C++ but I am pretty new to the .NET...
14
by: =?Utf-8?B?Sm9hY2hpbQ==?= | last post by:
I have seen the following function to convert from a System::String^ to a const wchar_t*. I would like to get a LPCTSTR and AFAIK LPCTSTR is equal to const wchar_t*. Then it should all work right?...
2
by: =?Utf-8?B?QWJoaW1hbnl1IFNpcm9oaQ==?= | last post by:
Hi, I am using Visual C++ in Visual Studio 2005 to create a Managed Wrapper around some C++ LIBS. I've created some classes that contains a pointer to the LIB classes and everthing seems to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.