Nov 20 2011, 01:28 PM
How to make it possible to use different Numeric Variables in the Input process:
As we all know the only control that could be used to enter input like "Characters & Numbers & ..etc" is the Text-box, the problem is that the program cant process mathematics processes because he thinks that the Text-box is a String only, that's why you get an error when you sub 2 numbers or divide others.
..this is a Sample on how to solve the issue:
So the main idea is to convert it back to string in the end.
Here is a full "Simple Calculator" i made from scratch...
As we all know the only control that could be used to enter input like "Characters & Numbers & ..etc" is the Text-box, the problem is that the program cant process mathematics processes because he thinks that the Text-box is a String only, that's why you get an error when you sub 2 numbers or divide others.
..this is a Sample on how to solve the issue:
Code:
float doc = Convert.ToSingle(textBox1.Text) / Convert.ToSingle(textBox3.Text);
textBox4.Text = doc.ToString();
So the main idea is to convert it back to string in the end.
Here is a full "Simple Calculator" i made from scratch...
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 hhhhh
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
switch (textBox2.Text)
{
case "":
MessageBox.Show("Enter +,-,*,/ Only");
break;
default:
int x = Convert.ToInt32(textBox1.Text);
int y = Convert.ToInt32(textBox3.Text);
int z;
char t = Convert.ToChar(textBox2.Text);
switch (t)
{
case '+':
z = Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox3.Text);
textBox4.Text = z.ToString();
break;
case '-':
z = Convert.ToInt32(textBox1.Text) - Convert.ToInt32(textBox3.Text);
textBox4.Text = z.ToString();
break;
case '*':
z = Convert.ToInt32(textBox1.Text) * Convert.ToInt32(textBox3.Text);
textBox4.Text = z.ToString();
break;
case '/':
float doc = Convert.ToSingle(textBox1.Text) / Convert.ToSingle(textBox3.Text);
textBox4.Text = doc.ToString();
break;
}
break;
}
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("NeptuneHACK!");
}
}
}