Hello, im making a calculator for a school project with visual basic using microsoft visual studio 2010.
I´m using a textbox and a label to calculate my results but I´d rather have everything in 1 textbox, or richtextbox. I searched on the internet and I found I could use microsoft script control 1.0 to avoid complications. But because I never learnt how to script in visual basic it´s pretty hard for me so i wondered if you guys could help me out.
Here´s my code so far:
Public Class Form1
Private Sub Button0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button0.Click
TextBox1.Text += "0"
End Sub
Private Sub Buttondot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttondot.Click
Dim dot As Boolean = False
If TextBox1.Text.IndexOf(".") >= 0 Then dot = True
If dot = False Then TextBox1.Text += "."
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text += "1"
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text += "2"
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
TextBox1.Text += "3"
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
TextBox1.Text += "4"
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
TextBox1.Text += "5"
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
TextBox1.Text += "6"
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
TextBox1.Text += "7"
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
TextBox1.Text += "8"
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
TextBox1.Text += "9"
End Sub
Private Sub Buttondivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttondivide.Click
Label1.Text = Val(TextBox1.Text)
Label2.Text = "/"
TextBox1.Text = ""
End Sub
Private Sub Buttonmultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonmultiply.Click
Label1.Text = Val(TextBox1.Text)
Label2.Text = "×"
TextBox1.Text = ""
End Sub
Private Sub Buttonminus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonminus.Click
Label1.Text = Val(TextBox1.Text)
Label2.Text = "-"
TextBox1.Text = ""
End Sub
Private Sub Buttonplus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonplus.Click
Label1.Text = Val(TextBox1.Text)
Label2.Text = "+"
TextBox1.Text = ""
End Sub
Private Sub Buttonequals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonequals.Click
Dim dot As Boolean = False
If Label1.Text.IndexOf(".") >= 0 Then dot = True
If Label2.Text = "/" Then
TextBox1.Text = Val(Label1.Text) / Val(TextBox1.Text)
End If
If Label2.Text = "×" Then
TextBox1.Text = Val(Label1.Text) * Val(TextBox1.Text)
End If
If Label2.Text = "-" Then
TextBox1.Text = Val(Label1.Text) - Val(TextBox1.Text)
End If
If Label2.Text = "+" Then
TextBox1.Text = Val(Label1.Text) + Val(TextBox1.Text)
End If
Label1.Text = ""
Label2.Text = ""
End Sub
Private Sub ButtonClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonClear.Click
TextBox1.Text = ""
Label1.Text = ""
Label2.Text = ""
End Sub
End Class
Thanks in advance!
Btw: my dot for fractions is not working very well either.