求一道VB编程题,高手请进....谢谢!!!

2024-11-05 10:42:47
推荐回答(2个)
回答1:

Private Sub Command1_Click()
'第一种算法,全部循环了一遍,所以速度慢
Dim sTmp As String
Dim sResult1 As String
Dim sResult2 As String
Dim iLen As Integer
Dim i As Integer
If Not IsNumeric(Me.Text1.Text) Then
MsgBox "请输入一个数字"
Exit Sub
End If
iLen = Len(Me.Text1.Text)
sResult1 = 10 ^ iLen
For i = 1 To iLen
sTmp = Left(Me.Text1.Text, i - 1) & Right(Me.Text1.Text, iLen - i)
If CLng(sTmp) < CLng(sResult1) Then
sResult1 = sTmp
sResult2 = Mid(Me.Text1.Text, i, 1)
End If
Next
MsgBox "去除该数字: " & sResult2 & " 得到的结果最小,结果是 " & sResult1
End Sub

Private Sub Command2_Click()
'第二种算法,速度快,输入的数字位数越多,效果越明显
Dim sTmp1 As String
Dim sTmp2 As String
Dim iLen As Integer
Dim i As Integer
iLen = Len(Me.Text1.Text)
For i = 1 To iLen
sTmp1 = Mid(Me.Text1.Text, i, 1)
sTmp2 = Mid(Me.Text1.Text, i + 1, 1)
If sTmp2 = "" Then sTmp2 = -1
If CInt(sTmp1) > CInt(sTmp2) Then
MsgBox "去除该数字: " & sTmp1 & " 得到的结果最小,结果是 " & Left(Me.Text1.Text, i - 1) & Right(Me.Text1.Text, iLen - i)
Exit Sub
End If
Next
End Sub

回答2:

没有必要短时间内重复提问