| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2599 人关注过本帖
标题:[讨论]大家讨论一下这个程序
只看楼主 加入收藏
边城浪子
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2004-4-9
收藏
 问题点数:0 回复次数:3 
[讨论]大家讨论一下这个程序
Function hextobin(hexstr As String) As String ' 由 十六进制串 得到 二进制串 Dim strbin As String For i = 1 To Len(hexstr) Select Case UCase(Mid(hexstr, i, 1)) Case "0" strbin = strbin & "0000" Case "1" strbin = strbin & "0001" Case "2" strbin = strbin & "0010" Case "3" strbin = strbin & "0011" Case "4" strbin = strbin & "0100" Case "5" strbin = strbin & "0101" Case "6" strbin = strbin & "0110" Case "7" strbin = strbin & "0111" Case "8" strbin = strbin & "1000" Case "9" strbin = strbin & "1001" Case "A" strbin = strbin & "1010" Case "B" strbin = strbin & "1011" Case "C" strbin = strbin & "1100" Case "D" strbin = strbin & "1101" Case "E" strbin = strbin & "1110" Case "F" strbin = strbin & "1111" Case Else MsgBox "输入的数据有误!!!" hextobin = "0" Exit Function End Select Next i hextobin = strbin End Function Private Sub Command1_Click() Dim strbin As String ' 二进制串 Dim stroct As String ' 八进制串 Dim strhex As String ' 十六进制串 Dim strdec As String '十进制串 Dim i As Integer, temp As Long, strtemp As String, numtype As String numtype = sel.Text strbin = Trim(num.Text) deal_line: Select Case numtype Case "十进制" temp = Val(num.Text) ' 直接得到十进制串 For i = 1 To Len(temp) strtemp = Mid(CStr(temp), i, 1) If strtemp > "9" Or strtemp < "0" Then MsgBox "不是十进制数据!!!输入有误!!!" Exit Sub End If Next i Case "二进制" temp = 0 For i = Len(strbin) To 1 Step -1 strtemp = Mid(strbin, i, 1) If strtemp = "1" Then temp = temp + 2 ^ (Len(strbin) - i) Else If strtemp <> "0" Then MsgBox "不是二进制数据!!!输入错误!!!" Exit Sub End If End If Next i Case "八进制" stroct = Trim(num.Text) temp = 0 For i = Len(stroct) To 1 Step -1 strtemp = Mid(stroct, i, 1) If strtemp >= "0" And strtemp <= "7" Then temp = temp + Val(strtemp) * 8 ^ (Len(stroct) - i) Else MsgBox "不是八进制数据!!!输入错误!!!" Exit Sub End If Next i Case "十六进制" strhex = Trim(num.Text) strbin = hextobin(strhex) numtype = "二进制" GoTo deal_line End Select strdec = CStr(temp) strhex = UCase(Hex(strdec)) stroct = Oct(strdec) strbin = hextobin(strhex) Labresult.Caption = "结果如下:" & Chr(10) & Chr(13) & _ String(10, " ") & "二进制: " & strbin & Chr(10) & Chr(13) & _ String(10, " ") & "八进制: " & stroct & Chr(10) & Chr(13) & _ String(10, " ") & "十进制: " & strdec & Chr(10) & Chr(13) & _ String(10, " ") & "十六进制: " & strhex End Sub Private Sub Labresult_Click() End Sub Private Sub num_Change() If num.Text = "" Then num.Text = "0" End If End Sub
搜索更多相关主题的帖子: 十六进制 二进制 
2004-04-14 19:15
攀岩
Rank: 1
等 级:新手上路
帖 子:56
专家分:0
注 册:2004-3-30
收藏
得分:0 

不错,程序还挺实用的,不知你有何不理解之处,请说


努力努力再努力,败了也不后悔
2004-04-14 22:38
pigpigpig
Rank: 1
等 级:新手上路
帖 子:51
专家分:0
注 册:2004-4-18
收藏
得分:0 

If strtemp > "9" Or strtemp "0" Then MsgBox "不是二进制数据!!!输入错误!!!" Exit Sub End If

少了一个“<”


没有做不到的,只有想不到的!
2004-04-18 10:24
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
收藏
得分:0 
讨论什么问题呀?

天津网站建设 http://www./
2004-04-18 11:51
快速回复:[讨论]大家讨论一下这个程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.042943 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved