Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > 60 digit calculator, please help, code doesn't seem to want to work!!!!!!!!!!


Reply
 
Thread Tools Display Modes
  #1  
Old 04-29-2003, 12:08 PM
cherrie cherrie is offline
Newcomer
 
Join Date: Apr 2003
Posts: 1
Unhappy 60 digit calculator, please help, code doesn't seem to want to work!!!!!!!!!!


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
Reply With Quote
  #2  
Old 04-29-2003, 01:13 PM
flyingllama101 flyingllama101 is offline
Newcomer
 
Join Date: Apr 2003
Location: England
Posts: 15
Question

Hi...this might not help...but here goes...I just finished my calculator (task 3 right?) anyway, i did it really simply by using 1 dimentional arrays, an adding each digit individually, starting from the left. Then i wrote a carry-over procedure. It only took 1 evening (even if it was a long one), and the code was really simple and it worked.

You could try doing it that way...hope this gives you inspiration anyways...

good luck
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
why does my code no longer work dapul General 4 11-07-2002 06:22 PM
Why doesn't this Javascript code work in Opera browsers? g8z Web Programming 2 09-17-2002 06:20 PM
Contest: Palindromes Derek Stone Tech Discussions 152 07-10-2002 11:51 AM
Text formattting watkins General 16 04-23-2002 12:01 PM
Can't get this code to work when combined Yogi_Bear_79 General 3 09-19-2000 09:10 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->