|
|
|
Option Explicit
'2進数を10進数に変換
Public Function ExBinToDeci(bin As String) As Long
Dim length As Integer
Dim i As Integer
Dim ltemp As Long
Dim stemp As String
ltemp = 0
length = Len(bin)
For i = 1 To length
'1文字取り出し
stemp = Mid$(bin, i, 1)
If stemp = "1" Then
ltemp = ltemp + CLng(2 ^ (length - i))
ElseIf stemp <> "0" Then
MsgBox "引数が2進数ではありません。"
ExBinToDeci = -1
Exit Function
End If
Next i
ExBinToDeci = ltemp
End Function
Private Sub CommandButton1_Click()
Range("B7") = ExBinToDeci("00001111")
End Sub
|
|