我的VB啊,哭~~~
我的VB进制转换程序,有警告 1 函数“DecToBin”并非在所有代码路径上都返回值。当使用结果时,可能会在运行时发生空引用异常。 各位看看如何改进啊.还有就是阶乘不会编,那位大大,给个代码把
Function DecToBin(ByVal inputdata As Double) As String
Dim Newval As Double
Dim binout, Bintemp, Bintemp1 As String
Dim i As Integer
If InStr(1, CStr(inputdata), ".") Then
MsgBox("只有整数能够被转换", vbCritical)
GoTo errhandler
End If
binout = ""
Newval = inputdata
doagain:
Newval = (Newval / 2)
If InStr(1, CStr(Newval), ".") Then
binout = binout + "1"
Newval = Format(Newval, "#0")
Newval = (Newval - 1)
If Newval < 1 Then
GoTo doneit
End If
Else
binout = binout + "0"
If Newval < 1 Then
GoTo doneit
End If
End If
GoTo doagain
doneit:
Bintemp = ""
For i = Len(binout) To 1 Step -1
Bintemp1 = Mid(binout, i, 1)
Bintemp = Bintemp + Bintemp1
Next i
binout = Bintemp
DecToBin = binout
errhandler:
End Function