vb高手进?
Private Sub Option1_Click(Index As Integer)
Dim n As Integer, X As Integer
n = Text1.Text
Call zh(n, X)
Select Case Index
Case 0
Text2.Text = zh(n, 2)
Label2.Caption = "二进制"
Case 1
Text2.Text = zh(n, 8)
Label2.Caption = "十进制"
Case 2
Text2.Text = zh(n, 16)
Label2.Caption = "十六进制"
End Select
End Sub
Public Sub zh(n As Integer, X As Integer)
While n <> 0
If n Mod X > 10 Then
s = Chr(65 + (n Mod X - 10)) & s
Else
s = Trim(n Mod X) & s
End If
n = n \\ X
Wend
End Sub
出现下面的图片,请问怎么改,但是要仍为Sub过程。
答案:Private Sub Option1_Click(Index As Integer)
Dim n As Integer, X As Integer, result As Variant
n = Val(Text1.Text)
Select Case Index
Case 0
Call zh(n, 2, result)
'sub zh()中增加一个变量,返回结果值
Label2.Caption = "二进制"
Case 1
Call zh(n, 8, result)
'同上
Label2.Caption = "八进制"
Case 2
Call zh(n, 16, result)
'同上
Label2.Caption = "十六进制"
End Select
Text2.Text = result
End Sub
'以下将原来的过程改为函数,
Public Sub zh(n As Integer, X As Integer, s As Variant)
While n <> 0
If n Mod X > 10 Then
s = Chr(65 + (n Mod X - 10)) & s
Else
s = Trim(n Mod X) & s
End If
n = n \\ X
Wend
End Subwhere is the picture?
上一个:怎样才能学好VB程序?
下一个:用递归与非递归来编写C++汉诺塔程序