'text1 text2 command1 command2
Dim i As Integer
Private Sub Command1_Click() '十进制转二进制
Dim IntI As Single
Dim str As String
IntI = Text1.Text '得到文本
Do While IntI <> 1 '如果不等于1就执行
str = CStr(IntI Mod 2) + str '除2取余数
IntI = Int(IntI / 2) '除2取整数
Loop
str = CStr(IntI) + str '接上取后一个
Text2.Text = str '结果
End Sub
Private Sub Command2_Click() '二进制转十进制
Dim str As Single
For i = 0 To Len(Text2.Text) - 1 '测长度
'取第N位数*2的N次方相加
str = str + Mid(Text2.Text, Len(Text2.Text) - i, 1) * (2 ^ i)
Next
Text1.Text = str '结果
End Sub
Dim i As Integer
Private Sub Command1_Click() '十进制转二进制
Dim IntI As Single
Dim str As String
IntI = Text1.Text '得到文本
Do While IntI <> 1 '如果不等于1就执行
str = CStr(IntI Mod 2) + str '除2取余数
IntI = Int(IntI / 2) '除2取整数
Loop
str = CStr(IntI) + str '接上取后一个
Text2.Text = str '结果
End Sub
Private Sub Command2_Click() '二进制转十进制
Dim str As Single
For i = 0 To Len(Text2.Text) - 1 '测长度
'取第N位数*2的N次方相加
str = str + Mid(Text2.Text, Len(Text2.Text) - i, 1) * (2 ^ i)
Next
Text1.Text = str '结果
End Sub
![](https://imgsa.baidu.com/%CE%DE%C1%C4%CB%A3%CB%A3%BF%E1/pic/item/69f73c45e4edd629cffca3ec.jpg)