Post: My first ever program [C#]
04-29-2011, 03:51 AM #1
Blackstorm
Veni. Vidi. Vici.
(adsbygoogle = window.adsbygoogle || []).push({}); Here's my first ever program for C#. I made it the same day I BARELY started C#.

I think I did good! I know this sounds weird but I got most of my experience from MW2 GSC scripting.. Even though C# differs every now and then vastly with functions, etc. from MW2 GSC.

Well, I'm uploading my whole source, I created a basic calculator.

Tell me what you think, what I can improve, and how I did on it! =D

Constructional criticism IS accepted. Here's my main code:

    
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
int i;
string textStr1, textStr2;
string val = "abcdefghijklmnopqrstuvwxyz/*+=!@#$%^&(){}][';><,";
textStr1 = textBox1.Text;
textStr2 = textBox2.Text;
bool invalidVal;
invalidVal = false;
if (textStr1.Length == 0) invalidVal = true;
if (textStr2.Length == 0) invalidVal = true;
for (i = 0; i < textStr1.Length; i++)
{
foreach (char ch in val)
{
if (textStr1[i] == Char.ToLower(ch))
{
invalidVal = true;
break;
}
}
}
for (i = 0; i < textStr2.Length; i++)
{
foreach (char ch in val)
{
if (textStr2[i] == Char.ToLower(ch))
{
invalidVal = true;
break;
}
}
}
if (invalidVal == false)
{
progressBar1.Maximum = 100000;
progressBar1.Minimum = 0;
progressBar1.Value = 0;
while (progressBar1.Value < progressBar1.Maximum) progressBar1.Value += 10;
float a = Convert.ToSingle(textBox1.Text);
float b = Convert.ToSingle(textBox2.Text);
if (comboBox1.SelectedItem == "+") textBox3.Text = Convert.ToString(a + b);
else if (comboBox1.SelectedItem == "-") textBox3.Text = Convert.ToString(a - b);
else if (comboBox1.SelectedItem == "/") textBox3.Text = Convert.ToString(a / b);
else if (comboBox1.SelectedItem == "*") textBox3.Text = Convert.ToString(a * b);
else if (comboBox1.SelectedItem == "^")
{
float num = a;
for (int x = 1; x < b; x++) num = num * a;
textBox3.Text = Convert.ToString(num);
}
string textStr3 = textBox3.Text;
}
else if (invalidVal == true) System.Windows.Forms.MessageBox.Show("Invalid Characters, or blank spaces have been inputted.");
}

private void redToolStripMenuItem_Click(object sender, EventArgs e)
{
this.BackColor = System.Drawing.Color.Red;
}

private void purpleToolStripMenuItem_Click(object sender, EventArgs e)
{
this.BackColor = System.Drawing.Color.Purple;
}

private void yellowToolStripMenuItem_Click(object sender, EventArgs e)
{
this.BackColor = System.Drawing.Color.Yellow;
}

private void orangeToolStripMenuItem_Click(object sender, EventArgs e)
{
this.BackColor = System.Drawing.Color.Orange;
}
}
}


Here's my source if you wanna see the actual program! The UPDATED program was built in bin\Release.

Enjoy! =D

Source Code: You must login or register to view this content.

Actual Program (*.exe): You must login or register to view this content.

Virus scan: You must login or register to view this content.

The following 4 users say thank you to Blackstorm for this useful post:

helpmeoprah, Kakashii, kiwimoosical, Sigma
04-29-2011, 03:55 AM #2
Zeebra
Do a barrel roll!
Originally posted by Blackstorm View Post
Here's my first ever program for C#. I made it the same day I BARELY started C#.

I think I did good! I know this sounds weird but I got most of my experience from MW2 GSC scripting.. Even though C# differs every now and then vastly with functions, etc. from MW2 GSC.

Well, I'm uploading my whole source, I created a basic calculator.

Tell me what you think, what I can improve, and how I did on it! =D

Constructional criticism IS accepted. Here's my main code:

    
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
int i;
string textStr1, textStr2;
string val = "abcdefghijklmnopqrstuvwxyz/*+=!@#$%^&(){}][';><,";
textStr1 = textBox1.Text;
textStr2 = textBox2.Text;
bool invalidVal;
invalidVal = false;
if (textStr1.Length == 0) invalidVal = true;
if (textStr2.Length == 0) invalidVal = true;
for (i = 0; i < textStr1.Length; i++)
{
foreach (char ch in val)
{
if (textStr1[i] == Char.ToLower(ch))
{
invalidVal = true;
break;
}
}
}
for (i = 0; i < textStr2.Length; i++)
{
foreach (char ch in val)
{
if (textStr2[i] == Char.ToLower(ch))
{
invalidVal = true;
break;
}
}
}
if (invalidVal == false)
{
progressBar1.Maximum = 100000;
progressBar1.Minimum = 0;
progressBar1.Value = 0;
while (progressBar1.Value < progressBar1.Maximum) progressBar1.Value += 10;
float a = Convert.ToSingle(textBox1.Text);
float b = Convert.ToSingle(textBox2.Text);
if (comboBox1.SelectedItem == "+") textBox3.Text = Convert.ToString(a + b);
else if (comboBox1.SelectedItem == "-") textBox3.Text = Convert.ToString(a - b);
else if (comboBox1.SelectedItem == "/") textBox3.Text = Convert.ToString(a / b);
else if (comboBox1.SelectedItem == "*") textBox3.Text = Convert.ToString(a * b);
else if (comboBox1.SelectedItem == "^")
{
float num = a;
for (int x = 1; x < b; x++) num = num * a;
textBox3.Text = Convert.ToString(num);
}
string textStr3 = textBox3.Text;
}
else if (invalidVal == true) System.Windows.Forms.MessageBox.Show("Invalid Characters, or blank spaces have been inputted.");
}

private void redToolStripMenuItem_Click(object sender, EventArgs e)
{
this.BackColor = System.Drawing.Color.Red;
}

private void purpleToolStripMenuItem_Click(object sender, EventArgs e)
{
this.BackColor = System.Drawing.Color.Purple;
}

private void yellowToolStripMenuItem_Click(object sender, EventArgs e)
{
this.BackColor = System.Drawing.Color.Yellow;
}

private void orangeToolStripMenuItem_Click(object sender, EventArgs e)
{
this.BackColor = System.Drawing.Color.Orange;
}
}
}


Here's my source if you wanna see the actual program! The UPDATED program was built in bin\Release.

Enjoy! =D

Source Code: You must login or register to view this content.

Actual Program (*.exe): You must login or register to view this content.

Virus scan: You must login or register to view this content.

Good job STORM
04-29-2011, 03:56 AM #3
so ur program is calculator....cool
04-29-2011, 03:58 AM #4
Blackstorm
Veni. Vidi. Vici.
Originally posted by XxOcrazyOxX View Post
so ur program is calculator....cool


Yes, I clearly stated that in the OP.

---------- Post added at 09:58 PM ---------- Previous post was at 09:57 PM ----------

Originally posted by Hackz View Post
Good job STORM


Thanks! =D
04-29-2011, 04:05 AM #5
lol i dont know why i put 2 posts but anyways why is my signature a mw2 wallpaper with a guy when i didnt had that as my signature... did someone got into my account wtf.
04-29-2011, 05:02 AM #6
Pichu
RIP PICHU.
Nice mate. Didn't download but it seems like a good application. Happy
04-29-2011, 05:56 AM #7
Blackstorm
Veni. Vidi. Vici.
Originally posted by Papa
Nice mate. Didn't download but it seems like a good application. Happy


lol I just wanted to share my first program I ever made with the community, so they could help me improve my code. Smile
04-29-2011, 06:36 PM #8
Thanks for this
04-30-2011, 01:33 AM #9
d7w7z
Bounty hunter
Originally posted by Blackstorm View Post
Here's my first ever program for C#.

C# FTW Smile

I just started making a new program like 10 minutes ago, trying to make it with a dynamic treeview and dynamic system tray icon so I can add/remove reminders and shortcuts to other folders and .exe's Winky Winky
04-30-2011, 02:05 AM #10
i seen in the code red purple yellow and orange, so i naturally thought
flashing text ftw!
but i see it was just to change the background either way nice program!

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo