我的工控
不积跬步,无以至千里,不积小流,无以成江海。
级别: 略有小成
精华主题: 0
发帖数量: 115 个
工控威望: 287 点
下载积分: 424 分
在线时间: 53(小时)
注册时间: 2010-12-20
最后登录: 2024-09-14
查看我的工控的 主题 / 回贴
楼主  发表于: 2010-12-21 21:23
用途:将十进制转化为二进制
输入:Dec(十进制数)
输入数据类型:Long
输出:DEC_to_BIN(二进制数)
输出数据类型:String
输入的最大数为2147483647,输出最大数为1111111111111111111111111111111(31个1)Public DEC_to_BIN(Dec As Long) As String
    DEC_to_BIN = ""
    Do While Dec > 0
        DEC_to_BIN = Dec Mod 2 & DEC_to_BIN
        Dec = Dec \ 2
    Loop
End 用途:将二进制转化为十进制
输入:Bin(二进制数)
输入数据类型:String
输出:BIN_to_DEC(十进制数)
输出数据类型:Long
输入的最大数为1111111111111111111111111111111(31个1),输出最大数为2147483647Public BIN_to_DEC(ByVal Bin As String) As Long
    Dim i As Long
    For i = 1 To Len(Bin)
        BIN_to_DEC = BIN_to_DEC * 2 + Val(Mid(Bin, i, 1))
    Next i
End 用途:将十六进制转化为二进制
输入:Hex(十六进制数)
输入数据类型:String
输出:HEX_to_BIN(二进制数)
输出数据类型:String
输入的最大数为2147483647个字符 Public HEX_to_BIN(ByVal Hex As String) As String
    Dim i As Long
    Dim B As String
    
    Hex = UCase(Hex)
    For i = 1 To Len(Hex)
        Select Case Mid(Hex, i, 1)
            Case "0": B = B & "0000"
            Case "1": B = B & "0001"
            Case "2": B = B & "0010"
            Case "3": B = B & "0011"
            Case "4": B = B & "0100"
            Case "5": B = B & "0101"
            Case "6": B = B & "0110"
            Case "7": B = B & "0111"
            Case "8": B = B & "1000"
            Case "9": B = B & "1001"
            Case "A": B = B & "1010"
            Case "B": B = B & "1011"
            Case "C": B = B & "1100"
            Case "D": B = B & "1101"
            Case "E": B = B & "1110"
            Case "F": B = B & "1111"
        End Select
    Next i
    While Left(B, 1) = "0"
        B = Right(B, Len(B) - 1)
    Wend
    HEX_to_BIN = B
End 用途:将二进制转化为十六进制
输入:Bin(二进制数)
输入数据类型:String
输出:BIN_to_HEX(十六进制数)
输出数据类型:String
输入的最大数为2147483647个字符   Public BIN_to_HEX(ByVal Bin As String) As String
    Dim i As Long
    Dim H As String
    If Len(Bin) Mod 4 <> 0 Then
        Bin = String(4 - Len(Bin) Mod 4, "0") & Bin
    End If
    
    For i = 1 To Len(Bin) Step 4
        Select Case Mid(Bin, i, 4)
            Case "0000": H = H & "0"
            Case "0001": H = H & "1"
            Case "0010": H = H & "2"
            Case "0011": H = H & "3"
            Case "0100": H = H & "4"
            Case "0101": H = H & "5"
            Case "0110": H = H & "6"
            Case "0111": H = H & "7"
            Case "1000": H = H & "8"
            Case "1001": H = H & "9"
            Case "1010": H = H & "A"
            Case "1011": H = H & "B"
            Case "1100": H = H & "C"
            Case "1101": H = H & "D"
            Case "1110": H = H & "E"
            Case "1111": H = H & "F"
        End Select
    Next i
    While Left(H, 1) = "0"
        H = Right(H, Len(H) - 1)
    Wend
    BIN_to_HEX = H
End 用途:将十六进制转化为十进制
输入:Hex(十六进制数)
输入数据类型:String
输出:HEX_to_DEC(十进制数)
输出数据类型:Long
输入的最大数为7FFFFFFF,输出的最大数为2147483647Public HEX_to_DEC(ByVal Hex As String) As Long
    Dim i As Long
    Dim B As Long
    
    Hex = UCase(Hex)
    For i = 1 To Len(Hex)
        Select Case Mid(Hex, Len(Hex) - i + 1, 1)
            Case "0": B = B + 16 ^ (i - 1) * 0
            Case "1": B = B + 16 ^ (i - 1) * 1
            Case "2": B = B + 16 ^ (i - 1) * 2
            Case "3": B = B + 16 ^ (i - 1) * 3
            Case "4": B = B + 16 ^ (i - 1) * 4
            Case "5": B = B + 16 ^ (i - 1) * 5
            Case "6": B = B + 16 ^ (i - 1) * 6
            Case "7": B = B + 16 ^ (i - 1) * 7
            Case "8": B = B + 16 ^ (i - 1) * 8
            Case "9": B = B + 16 ^ (i - 1) * 9
            Case "A": B = B + 16 ^ (i - 1) * 10
            Case "B": B = B + 16 ^ (i - 1) * 11
            Case "C": B = B + 16 ^ (i - 1) * 12
            Case "D": B = B + 16 ^ (i - 1) * 13
            Case "E": B = B + 16 ^ (i - 1) * 14
            Case "F": B = B + 16 ^ (i - 1) * 15
        End Select
    Next i
    HEX_to_DEC = B
End 用途:将十进制转化为十六进制
输入:Dec(十进制数)
输入数据类型:Long
输出:DEC_to_HEX(十六进制数)
输出数据类型:String
输入的最大数为2147483647,输出最大数为7FFFFFFFPublic DEC_to_HEX(Dec As Long) As String
    Dim a As String
    DEC_to_HEX = ""
    Do While Dec > 0
        a = CStr(Dec Mod 16)
        Select Case a
            Case "10": a = "A"
            Case "11": a = "B"
            Case "12": a = "C"
            Case "13": a = "D"
            Case "14": a = "E"
            Case "15": a = "F"
        End Select
        DEC_to_HEX = a & DEC_to_HEX
        Dec = Dec \ 16
    Loop
End 用途:将十进制转化为八进制
输入:Dec(十进制数)
输入数据类型:Long
输出:DEC_to_OCT(八进制数)
输出数据类型:String
输入的最大数为2147483647,输出最大数为17777777777   Public DEC_to_OCT(Dec As Long) As String
    DEC_to_OCT = ""
    Do While Dec > 0
        DEC_to_OCT = Dec Mod 8 & DEC_to_OCT
        Dec = Dec \ 8
    Loop
End 用途:将八进制转化为十进制
输入:Oct(八进制数)
输入数据类型:String
输出:OCT_to_DEC(十进制数)
输出数据类型:Long
输入的最大数为17777777777,输出的最大数为2147483647Public OCT_to_DEC(ByVal Oct As String) As Long
    Dim i As Long
    Dim B As Long
    
    For i = 1 To Len(Oct)
        Select Case Mid(Oct, Len(Oct) - i + 1, 1)
            Case "0": B = B + 8 ^ (i - 1) * 0
            Case "1": B = B + 8 ^ (i - 1) * 1
            Case "2": B = B + 8 ^ (i - 1) * 2
            Case "3": B = B + 8 ^ (i - 1) * 3
            Case "4": B = B + 8 ^ (i - 1) * 4
            Case "5": B = B + 8 ^ (i - 1) * 5
            Case "6": B = B + 8 ^ (i - 1) * 6
            Case "7": B = B + 8 ^ (i - 1) * 7
        End Select
    Next i
    OCT_to_DEC = B
End 用途:将二进制转化为八进制
输入:Bin(二进制数)
输入数据类型:String
输出:BIN_to_OCT(八进制数)
输出数据类型:String
输入的最大数为2147483647个字符Public BIN_to_OCT(ByVal Bin As String) As String
    Dim i As Long
    Dim H As String
    If Len(Bin) Mod 3 <> 0 Then
        Bin = String(3 - Len(Bin) Mod 3, "0") & Bin
    End If
    
    For i = 1 To Len(Bin) Step 3
        Select Case Mid(Bin, i, 3)
            Case "000": H = H & "0"
            Case "001": H = H & "1"
            Case "010": H = H & "2"
            Case "011": H = H & "3"
            Case "100": H = H & "4"
            Case "101": H = H & "5"
            Case "110": H = H & "6"
            Case "111": H = H & "7"
        End Select
    Next i
    While Left(H, 1) = "0"
        H = Right(H, Len(H) - 1)
    Wend
    BIN_to_OCT = H
End 用途:将八进制转化为二进制
输入:Oct(八进制数)
输入数据类型:String
输出:OCT_to_BIN(二进制数)
输出数据类型:String
输入的最大数为2147483647个字符 Public OCT_to_BIN(ByVal Oct As String) As String
    Dim i As Long
    Dim B As String
    
    For i = 1 To Len(Oct)
        Select Case Mid(Oct, i, 1)
            Case "0": B = B & "000"
            Case "1": B = B & "001"
            Case "2": B = B & "010"
            Case "3": B = B & "011"
            Case "4": B = B & "100"
            Case "5": B = B & "101"
            Case "6": B = B & "110"
            Case "7": B = B & "111"
        End Select
    Next i
    While Left(B, 1) = "0"
        B = Right(B, Len(B) - 1)
    Wend
    OCT_to_BIN = B
End 用途:将八进制转化为十六进制
输入:Oct(八进制数)
输入数据类型:String
输出:OCT_to_HEX(十六进制数)
输出数据类型:String
输入的最大数为2147483647个字符Public OCT_to_HEX(ByVal Oct As String) As String
    Dim Bin As String
    Bin = OCT_to_BIN(Oct)
    OCT_to_HEX = BIN_to_HEX(Bin)
End 用途:将十六进制转化为八进制
输入:Hex(十六进制数)
输入数据类型:String
输出:HEX_to_OCT(八进制数)
输出数据类型:String
输入的最大数为2147483647个字符Public HEX_to_OCT(ByVal Hex As String) As String
    Dim Bin As String
    Hex = UCase(Hex)
    Bin = HEX_to_BIN(Hex)
    HEX_to_OCT = BIN_to_OCT(Bin)
End
VB自带函数:
十进制转八进制:Oct(num)
十六进制转八进制:oct("&H" & num)
十进制转十六进制:hex(num)
八进制转十六进制:hex("&O" & num)十六进制转换为十进制
    Dim str As String                    
    str = Text2.Text
    Text10.Text = CLng("&H" & str)
这无尽的雨丝,有没有勾起你的回忆?对你来说,也许我不再重要。但只要你能记得我,我就已经无比欣慰。知道这雨让我想起了什么吗?你的眼泪。一滴滴的,晶莹如珠,包裹着过去岁月的沙粒,在我的心头滚动。
songyanwan
级别: *
精华主题: * 篇
发帖数量: * 个
工控威望: * 点
下载积分: * 分
在线时间: (小时)
注册时间: *
最后登录: *
查看songyanwan的 主题 / 回贴
1楼  发表于: 2010-12-21 21:44
不错 啊
该把程序一块发上来
子丑寅卯9
好钢是炼出来的; 好妞是泡出来的!
级别: 网络英雄
精华主题: 0
发帖数量: 1223 个
工控威望: 6798 点
下载积分: 9012 分
在线时间: 335(小时)
注册时间: 2008-05-17
最后登录: 2024-07-10
查看子丑寅卯9的 主题 / 回贴
2楼  发表于: 2011-01-08 15:39
不错,学习了。
(沈阳)承接非标自动化设计,调试及改造;各种通信控制;伺服调试,定位同步控制及专机制造。手机&微信同步(来访注明家园):18680531562 。
徐德海
风之调零
级别: 探索解密
精华主题: 0
发帖数量: 17 个
工控威望: 114 点
下载积分: 628 分
在线时间: 42(小时)
注册时间: 2011-01-07
最后登录: 2020-12-19
查看徐德海的 主题 / 回贴
3楼  发表于: 2011-01-08 17:54
okokok
风之调菱
etdssdabb
只有学而知之,没有生而知之
级别: 家园常客
精华主题: 0
发帖数量: 359 个
工控威望: 676 点
下载积分: 7861 分
在线时间: 231(小时)
注册时间: 2010-03-16
最后登录: 2019-04-15
查看etdssdabb的 主题 / 回贴
4楼  发表于: 2011-03-21 15:26
好东西,学习。
半路出家
级别: 探索解密
精华主题: 0
发帖数量: 12 个
工控威望: 110 点
下载积分: 509 分
在线时间: 9(小时)
注册时间: 2010-10-26
最后登录: 2014-07-25
查看半路出家的 主题 / 回贴
5楼  发表于: 2011-04-30 11:20
不错
adriano880
级别: 探索解密
精华主题: 0
发帖数量: 24 个
工控威望: 129 点
下载积分: 643 分
在线时间: 22(小时)
注册时间: 2011-04-10
最后登录: 2012-11-04
查看adriano880的 主题 / 回贴
6楼  发表于: 2011-04-30 14:12
henhao
tim_liang
级别: *
精华主题: * 篇
发帖数量: * 个
工控威望: * 点
下载积分: * 分
在线时间: (小时)
注册时间: *
最后登录: *
查看tim_liang的 主题 / 回贴
7楼  发表于: 2011-05-01 08:22
谢谢提供,能写一个程序发上来吗?