Mam kalkulator do napisania http://img463.imageshack.us/img463/7838/calcvf3.jpg Pytanie polega na tym, jak zrobić, żeby po naciśnięciu klawisza "+", a potem "=" otrzymać wynik. Do reszty działań zrobię sobie analogicznie. Mój kod prezentuje się w ten sposób:
Public Class Form1
Dim l1, l2 As String
Dim ktora As Integer = 1
Dim dzialanie As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If ktora = 1 Then
l1 = l1 + "1"
TextBox1.Text = l1
Else
l2 = l2 + "1"
TextBox1.Text = l2
End If
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
If ktora = 1 Then
l1 = l1 + "0"
TextBox1.Text = l1
Else
l2 = l2 + "0"
TextBox1.Text = l2
End If
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
If ktora = 1 Then
l1 = l1 + ","
TextBox1.Text = l1
Else
l2 = l2 + ","
TextBox1.Text = l2
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If ktora = 1 Then
l1 = l1 + "2"
TextBox1.Text = l1
Else
l2 = l2 + "2"
TextBox1.Text = l2
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If ktora = 1 Then
l1 = l1 + "3"
TextBox1.Text = l1
Else
l2 = l2 + "3"
TextBox1.Text = l2
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If ktora = 1 Then
l1 = l1 + "4"
TextBox1.Text = l1
Else
l2 = l2 + "4"
TextBox1.Text = l2
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If ktora = 1 Then
l1 = l1 + "5"
TextBox1.Text = l1
Else
l2 = l2 + "5"
TextBox1.Text = l2
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If ktora = 1 Then
l1 = l1 + "6"
TextBox1.Text = l1
Else
l2 = l2 + "6"
TextBox1.Text = l2
End If
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If ktora = 1 Then
l1 = l1 + "7"
TextBox1.Text = l1
Else
l2 = l2 + "7"
TextBox1.Text = l2
End If
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
If ktora = 1 Then
l1 = l1 + "8"
TextBox1.Text = l1
Else
l2 = l2 + "8"
TextBox1.Text = l2
End If
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
If ktora = 1 Then
l1 = l1 + "9"
TextBox1.Text = l1
Else
l2 = l2 + "9"
TextBox1.Text = l2
End If
End Sub
Function silnia(ByVal n As Integer)
If n = 0 Then
Return 1
Else
Return n * silnia(n - 1)
End If
End Function
Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
TextBox1.Text = CStr(silnia(CInt(l1)))
ktora = 1
l1 = ""
l2 = ""
dzialanie = 0
End Sub
Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
Select Case dzialanie
Case 1
TextBox1.Text = CStr(CDbl(l1) * CDbl(l2))
Case 2
TextBox1.Text = CStr(CDbl(l1) + CDbl(l2))
Case 3
TextBox1.Text = CStr(CDbl(l1) - CDbl(l2))
Case 4
If (CDbl(l2) = 0) Then
TextBox1.Text = "Nie dziel przez zero"
Else
TextBox1.Text = CStr(CDbl(l1) / CDbl(l2))
End If
Case 5
TextBox1.Text = CStr(CDbl(l1) ^ CDbl(l2))
Case Else
TextBox1.Text = "Jakie działanie?"
End Select
ktora = 1
l1 = ""
l2 = ""
dzialanie = 0
End Sub
Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click
If ktora = 1 Then
l1 = ""
Else
l2 = ""
End If
TextBox1.Text = "0"
End Sub
Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click
End
End Sub
End Class