I can not figure out how to do the percentage button, if someone could show me how to do it (using the same kind of code i've already used, not to complex) that would be great
It's all done in VB6, and obviously there all actually seperated by whatever button each chunk of code works with. Sorry if it looks more confusing than it actually is !
Basically i have all the number buttons from 0 to 9, the +,  , divide, sqaure root, answer, clear and period button all working together (well the decimal button will only work to 1 decimal place
) We have to recreate the Microsoft Windows Calculator for school work, so it's gotta work very similar to that.
Here is my current code.. it's kinda long.
Quote:
Dim b As Integer
Dim c As Integer
Dim a As Integer
Dim Number As Double
Dim Number2 As Double
Dim Number3 As Double
Dim Number4 As Double
Dim Number5 As Double
Dim Number6 As Double
Dim Number7 As Double
Dim Number8 As Double
Dim Number9 As Double
Dim Number10 As Integer
Dim Number11 As Integer
Dim Number12 As Integer
Dim Number13 As Integer
Dim Number14 As Integer
Dim Number15 As Integer
Dim d As Integer
'Imports System.Math
Dim e As Integer
Dim f As Integer
Dim g As Integer
Private Sub ans_Click()
If (a = 2) Then
Number2 = Text1
Text1 = Number + Number2
ElseIf (a = 1) Then
Number4 = Text1
Text1 = Number3  Number4
ElseIf (a = 3) Then
Number6 = Text1
Text1 = Number5 * Number6
ElseIf (a = 4) Then
Number8 = Text1
Text1 = Number7 / Number8
ElseIf (e = 1) Then
Number10 = Text1
Text1 = Math.Sqr(Number10)
ElseIf (f = 1) Then
Number11 = Text1
End If
End Sub
Private Sub Command1_Click()
Number = 0
Number2 = 0
Number3 = 0
Number4 = 0
Number5 = 0
Number6 = 0
Number7 = 0
Number8 = 0
Text1 = "0."
End Sub
Private Sub Command2_Click()
If Text1 = "0." Then
Text1 = "."
Else
x = Len(Text1)
temp = Left(Text1, x + 1)
Text1 = temp + "."
End If
End Sub
Private Sub divide_Click()
a = 4
Number7 = Text1
Text1 = 0
End Sub
Private Sub eight_Click()
If Text1 = "0." Then
Text1 = "8."
ElseIf (d = 0) Then
x = Len(Text1)
temp = Left(Text1, x  1)
Text1 = temp + "8" + "."
ElseIf (d = 1) Then
x = Len(Text1)
temp = Left(Text1, x  1)
Text1 = temp + "." + "8"
d = 0
End If
End Sub
Private Sub five_Click()
If Text1 = "0." Then
Text1 = "5."
ElseIf (d = 0) Then
x = Len(Text1)
temp = Left(Text1, x  1)
Text1 = temp + "5" + "."
ElseIf (d = 1) Then
x = Len(Text1)
temp = Left(Text1, x  1)
Text1 = temp + "." + "5"
d = 0
End If
End Sub
Private Sub four_Click()
If Text1 = "0." Then
Text1 = "4."
ElseIf (d = 0) Then
x = Len(Text1)
temp = Left(Text1, x  1)
Text1 = temp + "4" + "."
ElseIf (d = 1) Then
x = Len(Text1)
temp = Left(Text1, x  1)
Text1 = temp + "." + "4"
d = 0
End If
End Sub
Private Sub minus_Click()
a = 1
Number3 = Text1
Text1 = 0
End Sub
Private Sub nine_Click()
If Text1 = "0." Then
Text1 = "9."
ElseIf (d = 0) Then
x = Len(Text1)
temp = Left(Text1, x  1)
Text1 = temp + "9" + "."
ElseIf (d = 1) Then
x = Len(Text1)
temp = Left(Text1, x  1)
Text1 = temp + "." + "9"
d = 0
End If
End Sub
Private Sub one_Click()
If Text1 = "0." Then
Text1 = "1."
ElseIf (d = 0) Then
x = Len(Text1)
temp = Left(Text1, x  1)
Text1 = temp + "1" + "."
ElseIf (d = 1) Then
x = Len(Text1)
temp = Left(Text1, x  1)
Text1 = temp + "." + "1"
d = 0
End If
End Sub
Private Sub perc_Click()
Number12 = Text1
Text1 = "0."
Number13 = Number12
End Sub
Private Sub plus_Click()
a = 2
Number = Text1
Text1 = 0
End Sub
Private Sub point_Click()
d = 1
End Sub
Private Sub seven_Click()
If Text1 = "0." Then
Text1 = "7."
ElseIf (d = 0) Then
x = Len(Text1)
temp = Left(Text1, x  1)
Text1 = temp + "7" + "."
ElseIf (d = 1) Then
x = Len(Text1)
temp = Left(Text1, x  1)
Text1 = temp + "." + "7"
d = 0
End If
End Sub
Private Sub six_Click()
If Text1 = "0." Then
Text1 = "6."
ElseIf (d = 0) Then
x = Len(Text1)
temp = Left(Text1, x  1)
Text1 = temp + "6" + "."
ElseIf (d = 1) Then
x = Len(Text1)
temp = Left(Text1, x  1)
Text1 = temp + "." + "6"
d = 0
End If
End Sub
Private Sub sqrt_Click()
e = 1
End Sub
Private Sub three_Click()
If Text1 = "0." Then
Text1 = "3."
ElseIf (d = 0) Then
x = Len(Text1)
temp = Left(Text1, x  1)
Text1 = temp + "3" + "."
ElseIf (d = 1) Then
x = Len(Text1)
temp = Left(Text1, x  1)
Text1 = temp + "." + "3"
d = 0
End If
End Sub
Private Sub times_Click()
a = 3
Number5 = Text1
Text1 = 0
End Sub
Private Sub two_Click()
If Text1 = "0." Then
Text1 = "2."
ElseIf (d = 0) Then
x = Len(Text1)
temp = Left(Text1, x  1)
Text1 = temp + "2" + "."
ElseIf (d = 1) Then
x = Len(Text1)
temp = Left(Text1, x  1)
Text1 = temp + "." + "2"
d = 0
End If
End Sub
Private Sub zero_Click()
If Text1 = "0." Then
Text1 = "0."
ElseIf (d = 0) Then
x = Len(Text1)
temp = Left(Text1, x  1)
Text1 = temp + "0" + "."
ElseIf (d = 1) Then
x = Len(Text1)
temp = Left(Text1, x  1)
Text1 = temp + "0" + "."
d = 0
End If
End Sub
