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 


Organizing Tips in C#

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

Joined: 26 Apr 2008
Posts: 699
Location: -->formerly yoyonerd<--

PostPosted: Sun Aug 31, 2008 7:44 pm    Post subject: Organizing Tips in C# Reply with quote

Hi there, I'm going to go straight to the point.

I started C# almost a month ago, my codes are basic

Anything I really need I just define within the first event handler I make.

I was just wondering if thats a bad habit?

Here's an example code...

Code:
private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("Invalid Value", "Error");
                return;
            }
            else if (textBox1.Text == "0")
            {
                MessageBox.Show("Invalid Value", "Error");
                return;
            }
            string box = textBox1.Text;
            int interval = Convert.ToInt32(box + "000");
            timer1.Enabled = true;
            timer1.Interval = interval;
            this.button1.Text = "Timer has started.";
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            this.button1.Text = "Start Timer";
            MessageBox.Show("Time is up!", "Time's Up");
        }


Basically, is there a way, I could put my codes to be more neat?

If you have any organizing tips, I'd greatly appreciate it.
Back to top
View user's profile Send private message AIM Address
Overload
Master Cheater
Reputation: 0

Joined: 08 Feb 2008
Posts: 293

PostPosted: Sun Aug 31, 2008 8:16 pm    Post subject: Reply with quote

you can put them in form load, initialize event, etc.
_________________
Blog

Quote:
Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that
Back to top
View user's profile Send private message MSN Messenger
samuri25404
Grandmaster Cheater
Reputation: 7

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

PostPosted: Sun Aug 31, 2008 8:38 pm    Post subject: Re: Organizing Tips in C# Reply with quote

Code:
private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("Invalid Value", "Error");
                return;
            }
            else if (textBox1.Text == "0")
            {
                MessageBox.Show("Invalid Value", "Error");
                return;
            }
            string box = textBox1.Text;
            int interval = Convert.ToInt32(box + "000");
            timer1.Enabled = true;
            timer1.Interval = interval;
            this.button1.Text = "Timer has started.";
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            this.button1.Text = "Start Timer";
            MessageBox.Show("Time is up!", "Time's Up");
        }


For starters, name your controls.

Also, I'd have done it like this:

Code:

if (txtValue.Text == String.Empty)
{
    //do something
    return;
}
int Time = int.Parse(txtValue.Text) * 1000;
if (Time < 1)
{
    //do something
    return;
}
tmrSomething.Interval = Time;
tmrSomething.Enabled = true;
btnStart.Text = "Timer started.";


Just me, though.

_________________
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
yoyonerd
Grandmaster Cheater
Reputation: 0

Joined: 26 Apr 2008
Posts: 699
Location: -->formerly yoyonerd<--

PostPosted: Mon Sep 01, 2008 12:45 am    Post subject: Reply with quote

thanks samurai, I didn't make my code exactly that, but it did give me ideas

do you by chance know anyway, i could perhaps filter any letters from being typed into the textbox?

like a filter
Back to top
View user's profile Send private message AIM Address
pkedpker
Master Cheater
Reputation: 1

Joined: 11 Oct 2006
Posts: 412

PostPosted: Mon Sep 01, 2008 5:32 pm    Post subject: Reply with quote

I don't check ever if value is valid or not when you click a button I dont even add buttons for this kind of work. But instead add a check when the text changes is what I do.. so if someone puts a number like 999

and text changed has a checker resets the value back to original default value like 100 or so.. otherwise It would modify the global timer settings or whatever it is suppose to do..

Code:


private void TextBox1_TextChanged(object sender, System.EventArgs e)
    {
//reset to defautl value goes here.. if it is too high.. or not NUMBERIC
       //blah blah new text is = TextBox1.Text;
      //change timer settings here without pressing buttons!
    }


_________________
Hacks I made for kongregate.
Kongregate Universal Badge Hack: http://forum.cheatengine.org/viewtopic.php?p=4129411
Kongreate Auto Rating/Voter hack: http://forum.cheatengine.org/viewtopic.php?t=263576
Took a test lol
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