光纤信号:在VB中演示过程冒泡法排序

来源:百度文库 编辑:中科新闻网 时间:2024/05/06 11:48:26
在VB中演示过程冒泡法排序
要求把代码输入后能直接在VB环境中运行

在窗体中添加三个标签,一个按钮,一个框架在框架中添加一个文本框

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode < 48 Or KeyCode > 57 And KeyCode < 96 Or KeyCode > 150 And KeyCode <> 109 And _
KeyCode <> 189 Then Text1 = ""
End Sub

Private Sub Form_Load()
Label1(0).Visible = False
Label1(0).Alignment = 2
Label1(0).Top = 100
Label1(0).Left = 100
Label1(0).Height = 300
Label1(0).Width = 800
Label1(0).BackColor = QBColor(15)
Label1(0).FontSize = 12
Caption = "演示“起泡法”从小到大的排序过程"
Top = 0
Left = 200
Width = 2 * Label1(0).Left + 12 * (Label1(0).Width + 100)
Height = 7000
Label2.Top = 5700
Label2.Left = 500
Label2.FontSize = 12
Label2.Width = Width - 2 * Label2.Left
Label2.WordWrap = True
Label2.AutoSize = True
a = Space(4) & "数从文本输入,每输完一个数后,按回车键,数的个数可变.排序开始之前所有"
a = a & "所有的数都是白底黑字).单击“开始”按钮,开始比较(红底)数与(黄底)数"
a = a & "若(红底)数大就交换两数的位置;否则,两数仍保持原位置.位置已确定不变的数为"
Label2 = a & "(底黑字)."
Label3 = ""
Label3.FontSize = 15
Label3.Top = Label2.Top - 500
Label3.Left = 1300
Label3.AutoSize = True
Frame1.Top = Height - 2300
Frame1.Left = Width / 3
Frame1.Width = 2300
Frame1.Height = 850
Frame1.Caption = "输入-32768到32767的数"
Text1.Top = 300
Text1.Left = 500
Text1.Height = 370
Text1.Width = 1450
Text1.FontSize = 14
Text1.MaxLength = 6
Text1 = ""
Command1.Top = Frame1.Top + 200
Command1.Left = Frame1.Left + Frame1.Width + 100
Command1.Caption = "开始排序"
Command1.Enabled = False
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
Static kx As Byte, ky As Byte
If KeyAscii = 13 Then
If Text1 <> "" Then
x = Val(Text1)
If x >= -32768 And x <= 32767 Then
If n = 0 Then
Label1(0) = x: Label1(0).Visible = True
Else
Load Label1(n): Label1(n) = x
Label1(n).Visible = True
kx = kx + 1
If kx Mod 12 = 0 Then ky = ky + 1: kx = 0
Label1(n).Left = Label1(0).Left + kx * (Label1(0).Width + 100)
Label1(n).Top = Label1(0).Top + ky * (Label1(0).Height + 100)
Command1.Enabled = True
End If
Text1 = "": n = n + 1
End If
End If
End If

End Sub

上面的网站有病毒,大家要小心!!!