|
-
Jan 21st, 2002, 02:10 AM
#6
Here's the code.
REM **Put in the Form1 code
REM **This can handle any size numbers.
REM **You must have three textboxes (text1, text2 and text3)
REM ** When you add, text1 and text2 will be added and the answer will be in text3
REM **Also two Command buttons are needed (Command1 and Command2)
REM **Command1 = add button, command2 = clears all text boxes
Private Sub Command1_Click()
str1 = LTrim(RTrim((Text1.Text)))
str2 = LTrim(RTrim((Text2.Text)))
If Len(str2) > Len(str1) Then
tempstr = str2
str2 = str1
str1 = tempstr
End If
'If Len(str1) > 100 Then
'MsgBox ("Too Big!!!")
'GoTo bigger
'End If
first = str1
second = str2
' *********************
len1 = Len(first)
len2 = Len(second)
temp2 = len1 - len2
ReDim Digits(2, len1 + 1)
ReDim add(len1 + 1)
Digits(1, len1 + 1) = 0
Digits(2, len1 + 1) = 0
For a = 1 To len1
Digits(1, a) = Val(Mid$(first, a, 1))
Next a
For a = 1 To len2
Digits(2, a + temp2) = Val(Mid$(second, a, 1))
Next a
For adds = len1 + 1 To 2 Step -1
add(adds) = (Digits(1, adds - 1) + Digits(2, adds - 1) + buff) Mod 10
buff = Int((Digits(1, adds - 1) + Digits(2, adds - 1) + buff) / 10)
Next adds
If buff = 1 Then add(1) = 1
' *********************
Text3.Text = ""
For la = 1 To len1 + 1
If Not (la = 1 And add(la) = 0) Then Text3.Text = Text3.Text + LTrim(RTrim(Str(add(la))))
Next la
bigger:
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
REM ***Put in Module1
Public add(), carry() As Integer
Public Digits() As Integer
Public len1, len2, temp1, temp2 As Integer
Public str1, str2, tempstr, first, second As String
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|