(2)
实现上述功能的VB程序如下。请在划线处填入合适的代码。
Private Sub Command1_Click()
Dim a As Integer, b
As Integer, c As Integer
Dim a1 As String, b1
As String
Dim lena1 As
Integer, lenb1 As Integer, i As Integer
Dim result As String
a = Val(Text1.Text)
b = Val(Text2.Text)
If a > b Then
c = a: a = b: b =
c
End If
result =
""
a1 = DtoB(a): b1 =
DtoB(b)
lena1 = Len(a1):
lenb1 = Len(b1)
i = 1
Do While i <=
lena1
If Mid(a1, lena1 -
i + 1, 1) = Mid(b1, lenb1 - i + 1, 1) Then
result =
"0" + result
Else
result =
"1" + result
End If
i = i + 1
Loop
result =________
Text3.Text =
BtoD(result)
End Sub
Public Function DtoB(x As Integer) As String
Dim remainder As
String
DtoB = ""
Do While x > 0
remainder = CStr(x
Mod 2) '如:CStr(3
Mod 2)的值为"1"
DtoB = remainder +
DtoB
________
Loop
End Function
Public Function BtoD(x As String) As Integer
Dim i As Integer
BtoD = 0
For i = 1 To Len(x)
BtoD =________+ Val(Mid(x, i, 1))
Next i
End Function