| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 431 人关注过本帖
标题:[求助]进制转换问题求助
只看楼主 加入收藏
suzhou
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-5-28
收藏
 问题点数:0 回复次数:0 
[求助]进制转换问题求助

我要在一个仿windows的简易计算器里加上进制转换的功能,源码如下
Dim intCurJZ As Integer '保存当前进制
Dim intLSJZ As Integer '保存历史进制

Private Function Shi2QiTa(lngYuan As Long, intJZ As Integer) As String
'进制转换10->其他进制
Dim intYuShu As Integer '保存余数
Dim strJieGuo As String '保存结果
Do While lngYuan > 0
Select Case lngYuan Mod intJZ
Case 0 To 9
strJieGuo = CStr(lngYuan Mod intJZ) + strJieGuo
Case 10 To 15
strJieGuo = Chr(Asc("A") + (lngYuan Mod intJZ) - 10) + strJieGuo
End Select
lngYuan = lngYuan \ intJZ
Loop
Shi2QiTa = strJieGuo
End Function
Private Function QiTa2Shi(strYuan As String, intJZ As Integer) As Integer
'将其他进制转换成10进制
Dim lngJieGuo As Long
Dim strTemp As String '临时字符串

Do While Len(strYuan) > 0
strTemp = Left(strYuan, 1)
Select Case strTemp
Case "0" To "9"
lngJieGuo = lngJieGuo * intJZ + CInt(strTemp)
Case "a" To "f"
lngJieGuo = lngJieGuo * intJZ + 10 + Asc(strTemp) - Asc("a")
Case "A" To "F"
lngJieGuo = lngJieGuo * intJZ + 10 + Asc(strTemp) - Asc("A")
End Select
strYuan = Right(strYuan, Len(strYuan) - 1)
Loop
QiTa2Shi = lngJieGuo
End Function

Private Sub CmdSZ_Click(Index As Integer)
TxtIN.Text = TxtIN.Text + CmdSZ(Index).Caption
End Sub

Private Sub Command1_Click(Index As Integer)
MsgBox QiTa2Shi("123", 16)
MsgBox Shi2QiTa(123, 16)
End Sub

Private Sub Form_Load()
intCurJZ = 8
intLSJZ = 8
End Sub


Private Sub OptJZ_Click(Index As Integer)
Dim intCycle As Integer


Select Case Index
Case 0
Label1.Caption = "当前进制:" + "二进制"
intLSJZ = intCurJZ
intCurJZ = 2
TxtIN.Text = Shi2QiTa(QiTa2Shi(TxtIN.Text, intLSJZ), intCurJZ)
Case 1
Label1.Caption = "当前进制:" + "八进制"
intLSJZ = intCurJZ
intCurJZ = 8
TxtIN.Text = Shi2QiTa(QiTa2Shi(TxtIN.Text, intLSJZ), intCurJZ)
Case 2
Label1.Caption = "当前进制:" + "十进制"
intLSJZ = intCurJZ
intCurJZ = 10
TxtIN.Text = Shi2QiTa(QiTa2Shi(TxtIN.Text, intLSJZ), intCurJZ)
Case 3
Label1.Caption = "当前进制:" + "十六进制"
intLSJZ = intCurJZ
intCurJZ = 16
TxtIN.Text = Shi2QiTa(QiTa2Shi(TxtIN.Text, intLSJZ), intCurJZ)
End Select

'设置0-7的数字可用
For intCycle = 0 To intCurJZ - 1
CmdSZ(intCycle).Enabled = True
Next
'设置8-9的数字不可用
For intCycle = intCurJZ To 15
CmdSZ(intCycle).Enabled = False
Next

End Sub
可是一运行就出错,谁帮我看看怎么回事

搜索更多相关主题的帖子: 进制 
2006-05-29 13:22
快速回复:[求助]进制转换问题求助
数据加载中...
 
   



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

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