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 


Need a simple help with C# calculation

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

Joined: 25 Jun 2008
Posts: 109

PostPosted: Tue May 29, 2012 9:54 pm    Post subject: Need a simple help with C# calculation Reply with quote

I have created a simple textbox1 and a button.

Can someone help me on how to code it so when button is pressed; textbox1 will divide by 10 then convert the total into hex on the same textbox? This event will only happen when the button is pressed.

I know how to convert it to hex already, but just not the calculation part.

_________________
Back to top
View user's profile Send private message MSN Messenger
DanielG
Expert Cheater
Reputation: 1

Joined: 13 May 2009
Posts: 130
Location: The Netherlands

PostPosted: Wed May 30, 2012 6:50 am    Post subject: This post has 1 review(s) Reply with quote

Code:
        private void button1_Click(object sender, EventArgs e)
        {
            int number = 0;   // set up a variable
            number = int.Parse(textBox1.Text);   // parse the text to an int
            number = number / 10;   // divide by 10
            textBox1.Text = number.ToString();   // assign number to textbox (change to hex first if desired)
        }


Something like this?
Back to top
View user's profile Send private message
asianking
Expert Cheater
Reputation: 0

Joined: 25 Jun 2008
Posts: 109

PostPosted: Wed May 30, 2012 8:53 am    Post subject: Reply with quote

Thanks Daniel, it worked great.
_________________


Last edited by asianking on Wed May 30, 2012 11:45 am; edited 2 times in total
Back to top
View user's profile Send private message MSN Messenger
DanielG
Expert Cheater
Reputation: 1

Joined: 13 May 2009
Posts: 130
Location: The Netherlands

PostPosted: Wed May 30, 2012 11:43 am    Post subject: Reply with quote

Change the last line:
Code:
textBox1.Text = "0" + number.ToString();


If I were you I'd read some "how to program" tutorials. Appending something to a string is quite basic.
Back to top
View user's profile Send private message
asianking
Expert Cheater
Reputation: 0

Joined: 25 Jun 2008
Posts: 109

PostPosted: Wed May 30, 2012 11:47 am    Post subject: Reply with quote

I see... I didn't think about + would do the trick. On VB, I would just need the quotation and &. I would think they're samiliar, but I guess I was wrong.

Thanks, very useful!

_________________
Back to top
View user's profile Send private message MSN Messenger
Pingo
Grandmaster Cheater
Reputation: 8

Joined: 12 Jul 2007
Posts: 571

PostPosted: Thu May 31, 2012 2:33 am    Post subject: Reply with quote

Another way and slightly cleaner method.

Code:
        static string Output(string Input)
        {
            int tmp;
            return int.TryParse(Input, out tmp) ? (tmp / 10).ToString("X") : Input;
        }


Usage
Code:
        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = Output(textBox1.Text);
        }

_________________
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