作者xxxx33159 (尖东Roger)
看板Visual_Basic
标题[VBA ] Excel 的 VBA使用气泡排序法问题
时间Thu Apr 10 00:09:43 2008
不知道是不是在此发问
已在Excel中建立数据资料表
并要撰写一巨集使用气泡排序法重新排序
执行结果会跑出一视窗直接将结果输出
程式码如下:
Public Sub 设标题()
Cells(2, 1).Value = "原始资料"
Cells(2, 2).Value = "A"
Cells(2, 3).Value = "B"
Cells(2, 4).Value = "C"
Cells(2, 5).Value = "D"
Cells(2, 6).Value = "E"
Cells(2, 7).Value = "F"
Cells(2, 8).Value = "G"
Cells(2, 9).Value = "H"
Cells(2, 10).Value = "I"
Cells(2, 11).Value = "J"
Cells(2, 12).Value = "K"
Cells(2, 13).Value = "L"
Cells(2, 14).Value = "M"
Cells(2, 15).Value = "N"
Cells(2, 16).Value = "O"
End Sub
_________________________________________
Public Sub 编号()
For i = 4 To 16
Cells(i, 1).Value = i - 3
Next
End Sub
_________________________________________
Private Sub Command1_Click()
Dim A(15) As Integer
Dim TempVal As Integer
[A = 93: B = 92: C = 88: D = 85: E = 76: F = 87: G = 85: H = 71: I = 73: J = 96: K = 74: L = 91: M = 82: N = 83: O = 95]
TempVal = 0
Picture1.Print "阵列排序过程"
For Loop1 = 1 To 14
For Loop2 = 1 To 15 - Loop1
If A(Loop2) > A(Loop2 + 1) Then
TempVal = A(Loop2)
A(Loop2) = A(Loop2 + 1)
A(Loop2 + 1) = TempVal
End If
Next
Picture1.Print "第" & Loop1 & "回"
For loop3 = 1 To 15
Picture1.Print A(loop3)
Next
Picture1.Print
Next
End Sub
不过一直错误
不知哪里出了问题
请大大帮解
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.135.64.161
1F:→ MOONRAKER:是怎样错? 04/10 02:01