简单的vb编程

来源:百度知道 编辑:UC知道 时间:2024/05/16 00:03:05
编写程序:单击窗体实现从键盘上输入任意一个十进制整数转换成二进制整数,并在窗体上输出.要求十进制整数转换成二进制整数用一个过程或函数来实现.

Public Function DecimalToBinary(DecimalValue As Long) As String

Dim result As String
Dim ExtraDigitsNeeded As Integer

DecimalValue = Abs(DecimalValue)

Do
result = CStr(DecimalValue Mod 2) & result
DecimalValue = DecimalValue \ 2
Loop While DecimalValue > 0

DecimalToBinary = result

End Function

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
a = InputBox("请输入数字")
MsgBox DecimalToBinary(5)

End Sub

程序启动后,单击窗体就可以了