Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Question about C#

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
sotaukko
Cheater
Reputation: 0

Joined: 23 Oct 2007
Posts: 32

PostPosted: Wed Apr 16, 2008 1:42 pm    Post subject: Question about C# Reply with quote

This is my question: I have label1 with number 1, label2 with number 1 and label3 in my form. The thing i want to do is that label3 shows how much is label1.text + label2.text so label3 should show 2 becouse the text of label1 is 1 and text of label 2 is 1. I tried google but didn't found answer. I also tried microsofts developer center but didn't found answer.

P.S

i tried:

Code:
int i = label1.text
int s = label2.text

label3.text = i+s


but i got error that type string cannot be converted to type int Sad
Back to top
View user's profile Send private message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Wed Apr 16, 2008 1:59 pm    Post subject: Reply with quote

As far as i know, labels store their values in a string format, and since you want integer to add the two numbers together, you will need to convert the labels, dont know how you do this in C#...
Back to top
View user's profile Send private message
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

PostPosted: Wed Apr 16, 2008 2:10 pm    Post subject: Reply with quote

There are several ways in getting the number from text. Here is an example
Code:

int i = int.Parse(label1.Text);
int s = int.Parse(label2.Text);
int total = i + s;

label3.Text = total.ToString();


You could also use Convert.ToInt32().
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Wed Apr 16, 2008 2:11 pm    Post subject: Reply with quote

Ok, I'm assuming that what you want to do is take the number of characters in labels 1 and 2, and show that in label 3.

Code:

int length = label1.Text.Length + label2.Text.Length;

label3.Text = length.ToString();

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Estx
Expert Cheater
Reputation: 0

Joined: 04 Mar 2008
Posts: 172

PostPosted: Wed Apr 16, 2008 8:41 pm    Post subject: Reply with quote

What killersamurai said was correct (samuri25404, he wants to add the values from label1 and label2, not the length - I could be wrong though).

Unless you're going to use the variables again, do this instead:
Code:
label3.Text = (int.Parse(label1.Text) + int.Parse(label2.Text)).ToString();
Back to top
View user's profile Send private message
ssaccount
Master Cheater
Reputation: 0

Joined: 29 Aug 2007
Posts: 391
Location: Finland

PostPosted: Wed Apr 16, 2008 11:55 pm    Post subject: Reply with quote

those works for me so they have to work for you Very Happy
_________________
Programming in C++
(Or at least trying to Very Happy)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites