VB数值从小到大排序

VB数值从小到大排序
'在窗体上画两个输入框(Text1、Text2),一个Command1按钮,代码如下:
Option Explicit

'数值从小到大排序的函数
Public Function PPSRS(txt As String)
Dim x, y, temp As Integer
Dim arr(1 To 10) As Integer
Dim K As String
Dim i%
On Error Resume Next
'-------------先给arr赋值。。
For i = 1 To 10
arr(i) = Mid(Val(txt), i, 1)
Next i
'---------------排序
For x = 1 To 10
For y = x + 1 To 10
If arr(x) > arr(y) Then
temp = arr(y)
arr(y) = arr(x)
arr(x) = temp
End If
Next y
K = K & arr(x)
Next x
PPSRS = Mid(K, Len(K) - Len(txt) + 1, Len(txt))
End Function

Private Sub Command1_Click()
Text2.Text = PPSRS(Text1.Text)
End Sub

Private Sub Form_Load()
Text1.Text = “8634957021”
Command1.Caption = “排序”
End Sub

上一篇:VB.NET与C# 语法区别展示


下一篇:VB.Net 保存和读取设置文件(XML格式)