Private Sub Form_Activate() Open App.Path & "\in.txt" For Input As #1 ans = "" Input #1, x Do While x > 1 y = x Mod 16 If y > 9 Then Select Case y Case 10 ans = "A" & ans Case 11 ans = "B" & ans Case 12 ans = "C" & ans Case 13 ans = "D" & ans Case 14 ans = "E" & ans Case 15 ans = "F" & ans End Select Else ans = y & ans End If x = x / 16 Loop Close #1 Open App.Path & "\out.txt" For Output As #2 Print #2, ans Close End Sub
Private Sub Form_Activate() Dim xx(9) As String Open App.Path & "\in.txt" For Input As #1 Input #1, ans Close #1 anst = "ABCDEF" x = 1 Do While ans <> 0 xx(x) = ans Mod 16 ans = ans \ 16 x = x + 1 Loop x = x - 1 Open App.Path & "\out.txt" For Output As #1 For i = x To 1 Step -1 If xx(i) > 9 Then xx(i) = Mid(anst, (xx(i) Mod 10) + 1, 1) Print #1, xx(i); Else Print #1, xx(i); End If Next i Close #1 End Sub
ㄚ揚好, 提問1,這一段程式,「 x = 1 Do While ans <> 0 xx(x) = ans Mod 16 ans = ans \ 16 x = x + 1 Loop x = x - 1 」 中如果不想要最後的那一行 x = x - 1 可以怎麼改呢? 提問2,你的xx(9)定義的是string,可是你在 If xx(i) > 9 Then 又拿它來和數字比較,是不好的方式。 提問3,你應該可以將上下兩段程式合在一起,就不用陣列來暫存結果了,也不會出現要是數字大一些,不小心超過9個16進位的話的問題。 anyway, 好的開始,繼續堅持哦。 熊掌
Open App.Path & "\in.txt" For Input As #1 Input #1, x Close #1
Open App.Path & "\out.txt" For Output As #2 If x Mod 16 = 0 Then Print #2, x / 16 * 10 Else Do While x > 0 a = x Mod 16 b = Mid(txt, a, 1) & b x = x \ 16 Loop Print #2, b End If Close #2
Dim num(9) As Integer Public Sub Form_Load() Me.Hide Open App.Path & "/in.txt" For Input As #1 Open App.Path & "/out.txt" For Output As #2 Input #1, x St = "ABCDEF" Do Until x = 0 a = x Mod 16 x = x \ 16 If a > 9 Then ans = Mid(St, (a Mod 10) + 1, 1) & ans Else ans = a & ans End If Loop Print #2, ans Close #2 Close #1 End End Sub
Private Sub Form_Activate()
回覆刪除Open App.Path & "\in.txt" For Input As #1
ans = ""
Input #1, x
Do While x > 1
y = x Mod 16
If y > 9 Then
Select Case y
Case 10
ans = "A" & ans
Case 11
ans = "B" & ans
Case 12
ans = "C" & ans
Case 13
ans = "D" & ans
Case 14
ans = "E" & ans
Case 15
ans = "F" & ans
End Select
Else
ans = y & ans
End If
x = x / 16
Loop
Close #1
Open App.Path & "\out.txt" For Output As #2
Print #2, ans
Close
End Sub
高仔,
回覆刪除do while x > 1
loop
-->
do
loop while x >=1
x = x / 16
-->
x = x \ 16
注意1:一些特殊的數值,像0或是1
注意2:前測迴圈和後測迴圈的區別。
熊掌
Private Sub Form_Activate()
回覆刪除Dim xx(9) As String
Open App.Path & "\in.txt" For Input As #1
Input #1, ans
Close #1
anst = "ABCDEF"
x = 1
Do While ans <> 0
xx(x) = ans Mod 16
ans = ans \ 16
x = x + 1
Loop
x = x - 1
Open App.Path & "\out.txt" For Output As #1
For i = x To 1 Step -1
If xx(i) > 9 Then
xx(i) = Mid(anst, (xx(i) Mod 10) + 1, 1)
Print #1, xx(i);
Else
Print #1, xx(i);
End If
Next i
Close #1
End Sub
ㄚ揚好,
回覆刪除提問1,這一段程式,「
x = 1
Do While ans <> 0
xx(x) = ans Mod 16
ans = ans \ 16
x = x + 1
Loop
x = x - 1
」
中如果不想要最後的那一行
x = x - 1
可以怎麼改呢?
提問2,你的xx(9)定義的是string,可是你在
If xx(i) > 9 Then
又拿它來和數字比較,是不好的方式。
提問3,你應該可以將上下兩段程式合在一起,就不用陣列來暫存結果了,也不會出現要是數字大一些,不小心超過9個16進位的話的問題。
anyway, 好的開始,繼續堅持哦。
熊掌
作者已經移除這則留言。
回覆刪除Private Sub Form_Load()
回覆刪除txt = "123456789ABCDEF"
Open App.Path & "\in.txt" For Input As #1
Input #1, x
Close #1
Open App.Path & "\out.txt" For Output As #2
If x Mod 16 = 0 Then
Print #2, x / 16 * 10
Else
Do While x > 0
a = x Mod 16
b = Mid(txt, a, 1) & b
x = x \ 16
Loop
Print #2, b
End If
Close #2
End Sub
阿瑋好,
回覆刪除你用了一個很好的方式,
txt="123456789abcdef"
值得其它隊友學習,
只是你這個程式還有錯誤吧?
輸入是256的話?
試著改改看,記得改後再post上來,反正這兒應該可以放很長的內容的吧。
哦,另外,原則上,我手邊是沒有vb程式可以用,我用的是apple系統,這些程式都是用看的,如果隊員們發現我"看"錯了,也要記得說哦。
Dim num(9) As Integer
回覆刪除Public Sub Form_Load()
Me.Hide
Open App.Path & "/in.txt" For Input As #1
Open App.Path & "/out.txt" For Output As #2
Input #1, x
St = "ABCDEF"
Do Until x = 0
a = x Mod 16
x = x \ 16
If a > 9 Then
ans = Mid(St, (a Mod 10) + 1, 1) & ans
Else
ans = a & ans
End If
Loop
Print #2, ans
Close #2
Close #1
End
End Sub
3分27秒