VB代码。。。
想用VB做一个10进制与2进制互相转换的工具。。
希望大家可以帮忙。。。
就是有2个输入窗口左边输入数字点下边按钮出现2进制的表达在右边
在右边的窗口输入2进制点击下面的按钮左边出现10进制的。。
谢谢!
参考答案:Private Sub Command1_Click()
if txt_d.text=\"\" and txt_b.text<>\"\" then
txt_d.text= b2d(txt_b.text)
else
if txt_b.text=\"\" and txt_d.text<>\"\" then
txt_b.text= d2b(cint(txt_d.text))
else
msgbox \"请重新输入\"
txt_b.text=“”
txt_d.text=\"\"
end if
end if
End Sub
Public Function d2b(ByVal dec As Long) As String
Do
d2b = dec Mod 2 & d2b
dec = dec \\ 2
Loop While dec
End Function
Public Function b2d(ByVal bin As String) As Integer
Dim i As Long
For i = 1 To Len(bin)
b2d = b2d * 2 + Val(Mid(bin, i, 1))
Next i
End Function