⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 baselib.bas

📁 vb与三菱PLC的通信例子 对初学者很有用的
💻 BAS
字号:
Attribute VB_Name = "Module1"

Function hex2_to_bin8$(hex_2digit$)
bin_bit$ = ""
hex_digit$ = "00" + hex_2digit$
alen% = Len(hex_digit$)
hex_2digit$ = Right$(hex_digit$, 2)
For j% = 0 To 1
 X$ = Mid$(hex_2digit$, j% + 1, 1)
Select Case X$
 Case "0":     ax$ = "0000"
 Case "1":     ax$ = "0001"
 Case "2":     ax$ = "0010"
 Case "3":     ax$ = "0011"
 Case "4":     ax$ = "0100"
 Case "5":     ax$ = "0101"
 Case "6":     ax$ = "0110"
 Case "7":     ax$ = "0111"
 Case "8":     ax$ = "1000"
 Case "9":     ax$ = "1001"
 Case "A":     ax$ = "1010"
 Case "B":     ax$ = "1011"
 Case "C":     ax$ = "1100"
 Case "D":     ax$ = "1101"
 Case "E":     ax$ = "1110"
 Case "F":     ax$ = "1111"
 Case Else: hex2_to_bin8$ = "INPUT ERROR": GoTo hex2_to_bin8_end
 End Select
 bin_bit$ = bin_bit$ + ax$
Next j%
hex2_to_bin8$ = bin_bit$
hex2_to_bin8_end:
End Function


Function bin8_to_hex2$(binary_data$)
hex_byte$ = ""
binary_data$ = "00000000" + binary_data$
alen% = Len(binary_data$)
binary_data$ = Right$(binary_data$, 8)
For j% = 0 To 1
 X$ = Mid$(binary_data$, 4 * j% + 1, 4)
Select Case X$
 Case "0000":     ax$ = "0"
 Case "0001":     ax$ = "1"
 Case "0010":     ax$ = "2"
 Case "0011":     ax$ = "3"
 Case "0100":     ax$ = "4"
 Case "0101":     ax$ = "5"
 Case "0110":     ax$ = "6"
 Case "0111":     ax$ = "7"
 Case "1000":     ax$ = "8"
 Case "1001":     ax$ = "9"
 Case "1010":     ax$ = "A"
 Case "1011":     ax$ = "B"
 Case "1100":     ax$ = "C"
 Case "1101":     ax$ = "D"
 Case "1110":     ax$ = "E"
 Case "1111":     ax$ = "F"
 Case Else: bin8_to_hex2$ = "INPUT ERROR": GoTo bin8_to_hex2_end
 End Select
 hex_byte$ = hex_byte$ + ax$
Next j%
bin8_to_hex2$ = hex_byte$
bin8_to_hex2_end:
End Function

Function bin8_to_dec%(binary_data$)
  hex2$ = bin8_to_hex2(binary_data$)
  dec_value% = hex2_to_dec(hex2$)
  bin8_to_dec% = dec_value%
End Function

Function hex2_to_dec%(hex_2digit$)
Value% = 0
hex_digit$ = "00" + hex_2digit$
alen% = Len(hex_digit$)
hex_2digit$ = Right$(hex_digit$, 2)
For j% = 0 To 1
 X$ = Mid$(hex_2digit$, 2 - j%, 1)
Select Case X$
 Case "0" To "9": dec% = CInt(X$)
 Case "A": dec% = 10
 Case "B": dec% = 11
 Case "C": dec% = 12
 Case "D": dec% = 13
 Case "E": dec% = 14
 Case "F": dec% = 15
 Case Else: hex2_to_dec% = 0: GoTo hex2_to_dec_end
 End Select
 Value% = Value% + dec% * (16 ^ j%)
Next j%
hex2_to_dec% = Value%
hex2_to_dec_end:
End Function

Public Function bin16_to_dec&(bin_data$)
  hex4$ = bin16_to_hex4(bin_data$)
  dec_value& = hex4_to_dec(hex4$)
  bin16_to_dec& = dec_value&
End Function

Public Function bin16_to_hex4$(bin_data$)
hex_byte$ = ""
bin_data$ = "0000000000000000" + bin_data$
alen% = Len(bin_data$)
bin_data$ = Right$(bin_data$, 16)
'Form1.text1.Text = bin_data$
For j% = 0 To 3
 X$ = Mid$(bin_data$, 4 * j% + 1, 4)
Select Case X$
 Case "0000":     ax$ = "0"
 Case "0001":     ax$ = "1"
 Case "0010":     ax$ = "2"
 Case "0011":     ax$ = "3"
 Case "0100":     ax$ = "4"
 Case "0101":     ax$ = "5"
 Case "0110":     ax$ = "6"
 Case "0111":     ax$ = "7"
 Case "1000":     ax$ = "8"
 Case "1001":     ax$ = "9"
 Case "1010":     ax$ = "A"
 Case "1011":     ax$ = "B"
 Case "1100":     ax$ = "C"
 Case "1101":     ax$ = "D"
 Case "1110":     ax$ = "E"
 Case "1111":     ax$ = "F"
 End Select
 hex_byte$ = hex_byte$ + ax$
Next j%
bin16_to_hex4$ = hex_byte$
End Function

Public Sub delay(delay_N%)
' ┑

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -