|
Hey everyone! As i'm sure u all already figured i'm doin a 60 digit calculator for my coursework, I seem to be having problem though'...it either gives me loads of 0s or doesn't give any answer n it's driving me crazy! I used a 3D array, 1st for the 1st number, 2nd for the 2nd and the last for the answer...please please help! I'll add the appropriate code so u can see what i'm talkin about....Thanx! xXx
Option Explicit
Dim x, i, n, a As Integer
Dim DisplayNew, Flag, topBigger As Boolean
Dim num(2, 60) As Integer
Private Sub Addingtoarray()
x = 1
a = 61
Do Until x = Len(Display.Text)
num(0, a - x) = Mid(Display.Text, (Len(Display.Text) - x) + 1, 1)
x = x + 1
a = a + 1
Loop
End Sub
Private Sub Addingtoarray2()
x = 1
a = 61
Do Until x = Len(Display2.Text)
num(1, a - x) = Mid(Display2.Text, (Len(Display2.Text) - x) + 1, 1)
x = x + 1
a = a + 1
Loop
End Sub
Private Sub Plus_Click()
Flag = True
If Display.Text = "" And Display.Visible = True Then
sign.Text = "+"
ElseIf Display2.Text = "" And Display2.Visible = True Then
sign2.Text = "+"
End If
End Sub
Private Sub Minus_Click()
Call Addingtoarray 'Calls Addingtoarray routine
'If Then ElseIf statement to determine weather to add - sign or not
If Display.Text = "" And Display.Visible = True Then
sign.Text = "-"
ElseIf Display2.Text = "" And Display2.Visible = True Then
sign2.Text = "-"
End If
Display.Visible = False 'Makes display textbox invisible
Display2.Visible = True 'Makes display2 textbox visible
Plus.Enabled = False 'Disables the use of both operators
Minus.Enabled = False
sign.Visible = False 'Makes sign textbox invisible
sign2.Visible = True 'Makes sign2 textbox visible
End Sub
Private Sub Equals_Click()
Call Addingtoarray2 'Runs "Addingtoarray2" code
Answer.Visible = True 'Makes Answer textbox visible
Label2.Visible = True 'Makes Label2 visible
Display2.Visible = False 'Makes Display2 textbox invisible
sign2.Visible = False 'Makes sign2 invisible
If Flag = True Then 'If Then ElseIf statements to determine which routine is to be run
Call compare 'If true call compare routine
Call Add 'If true call Sdd routine
ElseIf Flag = False Then 'ElseIf condition is met then continue If statement
Call compare 'If False Call compare routine
Call Take 'If False Call Take routine
End If
Do Until x = 60 'Do until loop to display answer
Answer.Text = Answer.Text & num(2, x) 'Displays answer of calculation in textbox digit by digit
x = x + x 'Adds 1 to x
Loop 'Loops until condition is met
End Sub
Private Sub Add()
If topBigger = True Then 'If Then Else statement to determine which + routine it takes
For x = 60 To 0 Step -1 'Routine for + calculations when the top line of the array is bigger
num(2, x) = Val(num(0, x)) + Val(num(1, x)) 'Adds together the top to the bottom
If Val(num(2, x)) > 9 Then 'If Then statement checks if x is bigger than 9
num(0, x - 1) = Val(num(0, x - 1)) + 1 'Adds 1 to the next array box
num(2, x) = Mid(num(2, x), 2, 1) 'Stores the digit into the answer box
End If 'Ends the If Then statement when condition is met
Next x 'Continues the routine until condition is met
Else
For x = 60 To 0 Step -1 'Routine for + calculations when the bottom line of the array is bigger
num(2, x) = Val(num(1, x)) + Val(num(0, x)) 'Adds together the bottom to the top
If Val(num(2, x)) > 9 Then 'If Then statement checks if x is bigger than 9
num(1, x - 1) = Val(num(1, x - 1)) + 1 'Adds 1 to the next array box
num(2, x) = Mid(num(2, x), 2, 1) 'Stores the digit into the answer box
End If 'Ends the If Then statement when condition is met
Next x 'Continues the routine until condition is met
End If 'Ends the nested If Then Else statement when condition is met
End Sub
Private Sub Take()
If topBigger = True Then 'If Then Else statement to determine which - routine it takes
For x = 60 To 1 Step -1 'Routine for - calculations when the top line of the array is bigger
num(2, x) = Val(num(0, x)) - Val(num(1, x)) 'Takes away top from the bottom
If Val(num(2, x)) < 0 Then 'If Then statement checks if x is less than 0
num(2, x) = 10 + Val(num(2, x)) 'Adds 10 to the answer
num(0, x - 1) = Val(num(1, x - 1)) - 1 'Takes 1 from the next number of top line
End If 'Ends the If Then statement when condition is met
Next x 'Continues the routine until condition is met
Else
For x = 60 To 1 Step -1 'Routine for - calculations when the bottom line of the array is bigger
num(2, x) = Val(num(0, x)) - Val(num(1, x)) 'Takes away top from bottom
If Val(num(2, x)) < 0 Then 'If Then statement checks if x is less than 0
num(2, x) = 10 + Val(num(2, x)) 'Adds 10 to the answer line of the array
num(1, x - 1) = Val(num(0, x - 1)) - 1 'Takes 1 from the next number of bottom line
End If 'Ends the If Then statement when condition is met
Next x 'Continues the routine until condition is met
End If 'Ends the nested If Then Else statement when condition is met
End Sub
Private Sub compare()
'If Then ElseIf statement to determine which array row is bigger
If Display.Text > Display2.Text Then
topBigger = True 'To set topBigger status to True
ElseIf Display.Text <= Display2.Text Then
topBigger = False 'To set topBigger status to True
End If
End Sub
|