我用VB做了一个程序,是关于:输入两个任意长度的数,然后相加。输出结果!
如:3000000000000000000000000000000+3000000000000000000000000000000
然后把这个结果输出!
请大家帮我看看这个程序错在那里!谢谢大家啊!谢谢!
Private Sub Command1_Click()
Dim mystr1, mystr2, mystr As String
Dim i, j, m, n, p, na, nb, len1, len2, myint1, myint2, minintb, ta, tb, nc, x, y As Integer
a = 0
mystr1 = Trim(Text1.Text)
mystr2 = Trim(Text2.Text)
len1 = Len(mystr1)
len2 = Len(mystr2)
myint1 = InStr(mystr1, ".")
myint2 = InStr(mystr2, ".")
If myint1 = 0 Then
If myint2 <> 0 Then
mystr = Right(mystr2, len2 - myint2)
na = len1
nb = myint2 - 1
Else
na = len1
nb = len2
End If
Else
If myint2 <> 0 Then
ta = len1 - myint1
tb = len2 - myint2
If ta > tb Then
minintb = tb
Else
minintb = ta
End If
na = myint1 - 1
nb = myint2 - 1
For i = minintb To 1 Step -1
m = Val(Mid(mystr1, myint1 + i, 1)) + a
n = Val(Mid(mystr2, myint2 + i, 1))
p = m + n
a = p \ 10
b = p Mod 10
mystr = Str(b) & mystr
Next i
Else
mystr = Right(mystr1, ta)
End If
End If
mystr = "." & mystr
mystr1 = Mid(mystr1, 1, na)
mystr2 = Mid(mystr2, 1, nb)
If na > nb Then
nc = na
Else
nc = nb
End If
x = na
y = nb
For i = 1 To nc + 1
If na - i Then
m = Val(Mid(mystr1,x--,1))
m = m + a
Else
m = 0 + a
End If
If nb - i Then
n = Val(Mid(mystr2, y--, 1))
Else
n = 0
End If
p = m + n
a = p \ 10
b = p Mod 10
mystr = Str(b) & mystr
Next i
Text3.Text = mystr
End Sub
一个简单的程序