16652.html

来自「VB技巧问答10000例,是一个教程」· HTML 代码 · 共 23 行

HTML
23
字号
<html>
  <head>
    <title>Re: 排序?</title>
  </head>
  <body bgcolor="#FFFFFF" vlink="#808080">
    <center>
      <h1>Re: 排序?</h1>
    </center>
<hr size=7 width=75%>

<hr size=7 width=75%><p>
Posted by <a href="mailto:luo570@ms31.hinet.net">小琳</a> on August 04, 1999 at 20:56:59:<p>
In Reply to: <a href="16586.html">排序?</a> posted by 阿钦 on August 03, 1999 at 22:58:01:<p>
: 请问各位高手,我要如用VB使Richtextbox内之字串自动排序,有小至大或大至小都可以,像下面这样子可以作到吗?<br>: 12345<br>: 23456<br>: 54689<br>: 75990<br>: 以字串最小的往下一直排!谢谢<p>:::对于您的问题,小女子利用一些时间来为您解决,但是<br>小女子的程式只能使用整数型态的数字资料而己,小女子<br>首先将这些资料全部放在阵列里,然后利用阵列里的资料<br>来做排序,程式如下:<br>Option Explicit<br>Dim record As Integer<br>Private Sub Command1_Click()<br>    Dim i As Integer<br>    Dim temp() As Integer, j As Integer<br>    Dim k As Integer<br>    <br>    record = record - 1<br>    ReDim temp(record)<br>    j = 0<br>    i = InStr(1, RichTextBox1.Text, Chr(10))<br>    k = 1<br>    Do While i <> 0<br>       temp(j) = Mid(RichTextBox1.Text, k, i - k)<br>       j = j + 1<br>       k = i + 1<br>       i = i + 1<br>       i = InStr(i, RichTextBox1.Text, Chr(10))<br>    Loop<br>    For i = 0 To UBound(temp)<br>        For j = i + 1 To UBound(temp)<br>            If temp(i) > temp(j) Then<br>                k = temp(i)<br>                temp(i) = temp(j)<br>                temp(j) = k<br>            End If<br>        Next j<br>    Next i<br>    For i = 0 To UBound(temp)<br>        Form1.Print temp(i)<br>    Next i<br>        <br>End Sub<p>Private Sub Form_Load()<br>    record = 0<br>End Sub<p>Private Sub RichTextBox1_KeyPress(KeyAscii As Integer)<br>    If KeyAscii = 13 Then<br>        record = record + 1<br>    End If<br>End Sub<br>
<br>
<br><hr size=7 width=75%><p>
<a name="followups">Follow Ups:</a><br>
<ul><!--insert: 16652-->
</ul><!--end: 16652-->
<br><hr size=7 width=75%><p>

</body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?