VB题,高手进。。急。。

来源:百度知道 编辑:UC知道 时间:2024/05/24 13:18:52
编写一个自定义过程itostr,实现将数字483变换成字符型“483”,不使用CSTR函数和STR函数,并在窗体中放置1个命令按钮,2个文本框。。

谢谢大虾的代码。。。

Private Sub Form_Click()
Print itostr(-11)
End Sub

Public Function itostr(n As Integer) As String
s = Sgn(n)
n = n * s
Do
itostr = n Mod 10 & itostr
n = n \ 10
Loop While n <> 0
If s = -1 Then itostr = "-" & itostr
End Function

Private Function itostr(n As Long) As String
Dim str As String
Do While n > 0
str = n Mod 10 & str
n = Int(n / 10)
Loop
itostr = str
End Function

Private Sub Command1_Click()
Text2.Text = itostr(Val(Trim(Text1.Text)))
End Sub

Function itostr(N As Long) As String
itostr = N
End Function

Private Sub Form_Click()
Dim i As Long
i = 483
Print VarType(itostr(i)) 'VarType 用于求数据的类型,得到结果为8,对应的是字符型
End Sub