
例:第一次输入3,代表你想要的二进制有3位,然后弹出一个输入框,输入0,再弹出一个输入框,输入0,最后一个输入框,输入1,最后显示“100等于4”
最后显示不了~!~请高手帮忙
Private Sub NumberConvertion()
Dim strBits As String
Dim n As Long
Dim strResponse As String
Dim strBinNum As String
Dim i As Long
Dim j As Long
strBits = InputBox("Please type in the desired number of bits (a positive integer) in the binary number", "Number of bits")
If Not IsNumeric(strBits) Then
MsgBox "Please provide a number!"
ElseIf CLng(strBits) <= 0 Then
MsgBox "Please provide a positive number!"
ElseIf CDbl(strBits) Like "*.*[1-9]" Then
MsgBox "Please provide an integer!"
End If
For n = 1 To CLng(strBits)
strResponse = InputBox("Please type in '0' or '1' for bit " & n & " of the binary number." & vbNewLine & _
"Please type in 'STOP' if you want to exit.")
If strResponse = "STOP" Then
Exit For
ElseIf Not CLng(strResponse) = 0 Then
If Not CLng(strResponse) = 1 Then
MsgBox "Please type in either '0' or '1'!"
End If
Else
i = i + CLng(strResponse) * (10 ^ (n - 1))
End If
Next n
MsgBox i