新建From1(窗体),新建Command1(按钮CommandButton),代码:
Private Sub Command1_Click()
Dim strGet As String
strGet = f_Fill8("10101011")
MsgBox f_GetBit(strGet, 4, 4)
End Sub
Private Function f_Fill8(strNum As String)
f_Fill8 = Right$("00000000" & strNum, 8)
End Function
Private Function f_GetBit(strNum As String, intWhere As Integer, intLen As Integer)
' 0 1 2 3 4 5 6 7
' +----------------+
' | 1 0 1 0 1 0 1 0 |
' +----------------+
f_GetBit = Mid(strNum, intWhere + 1, intLen) '修正Mid函数
End Function
运行结果:
1011