永发信息网

vb中怎么编写判断一个数是不是八进制数

答案:1  悬赏:60  手机版
解决时间 2021-02-09 08:42
  • 提问者网友:溺爱和你
  • 2021-02-09 00:19
vb中怎么编写判断一个数是不是八进制数
最佳答案
  • 五星知识达人网友:动情书生
  • 2021-02-09 00:56
请参考

Private Sub Command1_Click()
Text2 = ReadOctal(Text1)
End Sub

Private Sub Command2_Click()
Text1 = WriteOctal(Text2)
End Sub

Function ReadOctal(num As String)
For i = 1 To Len(num)
s = Val(Mid(num, i, 1))
If s > 7 Then MsgBox "八进制数中不能有大于7的数字!": Exit Function
ReadOctal = ReadOctal * 8 + s
Next
End Function

Function WriteOctal(num As String)
Dim a%(10), m%, i%
s = ""
m = num
i = 0
Do While m <> 0
a(i) = m Mod 2
m = m \ 2
i = i + 1
Loop
For k = i - 1 To 0 Step -1
s = s & a(k)
Next

i = Len(s) Mod 3
Select Case i
Case 1: s = "00" & s
Case 2: s = "0" & s
End Select
For i = 1 To Len(s) Step 3
s1 = Mid(s, i, 3)
s2 = 0
For j = 1 To 3
s2 = s2 * 2 + Val(Mid(s1, j, 1))
Next
WriteOctal = WriteOctal & s2
Next

End Function
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯