設計一個程式界面,有兩個表單的應用程式。用戶在Form表單(輸入表單)的“請輸入排序數個數”文本框輸入有效數,按回車鍵后,在該表單的“Picture1”圖片框中輸出排序前的數,單擊“排序”按鈕,啟動Form2表單,呼叫冒泡排序子程序Sort并把排序結果在Form2(輸出結果)表單的“Picture1”圖片框中輸出,在Form2(輸出結果)表單的“請輸入要查找的數”文本框內輸入要查找的數后,單擊“查找”按鈕,呼叫查找函式程序(Search),查找結果在“查找結果”文本框顯示,單擊“結束”按鈕結束應用程式的運行。
求大神賜教啊
第一個代碼是宣告函式
Public Sub sort(a() As Integer)
Dim n As Integer
Dim t As Integer
n = UBound(a())
For i = 1 To n - 1
For j = i + 1 To n
If a(i) > a(j) Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next j
Next i
End Sub
第二個是form1中picture1輸出 ,我想把輸出改成每15個一行,如何更改呢
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim a()
Dim i As Integer
Dim n As Integer
Dim s As String
Dim count As Integer
n = Val(Text1.Text)
If n > 0 Then
ReDim a(n - 1)
For i = 0 To n - 1
Randomize
a(i) = Int(Rnd * 101)
s = s & a(i) & " "
Next i
If KeyAscii = 13 Then
Picture1.Print s
End If
End If
End Sub
還有就是,如何呼叫第二個視窗,實作command1后排序后的數字在form2中picture1上輸出呢
我是小白,剛剛接觸vb還望大家多指教
最好能有全套代碼
uj5u.com熱心網友回復:
參考下面代碼:(你要查找的目的是什么?)Private Sub Command1_Click()
''一個表單 + 一個按鈕 + 2個picturebox + 一個textbox + 一個listbox
''產生隨機資料并輸出排序后的結果
Dim k As Integer
k = CInt(Val(Text1.Text))
If k > 0 And k < 31 Then
Dim i As Integer, w1 As String, w2 As String, n As Integer
''List1.Sorted = True''在設計界面操作(用它來排序)
List1.Clear
For i = 1 To k
n = Int(Rnd * 101)
w1 = w1 & w2 & CStr(n)
List1.AddItem Format$(n, "000")
w2 = " "
If i Mod 15 = 0 Then w1 = w1 & vbCrLf: w2 = ""
Next
Pic1.Print w1 ''在pic1中輸出排序前得到的字串
''在pic2中輸出排序后的資料
w1 = "": w2 = ""
For i = 0 To List1.ListCount - 1
w1 = w1 & w2 & CStr(CInt(List1.List(i)))
w2 = " "
If (i + 1) Mod 15 = 0 Then w1 = w1 & vbCrLf: w2 = ""
Next
Pic2.Print w1 ''在pic2中輸出排序前得到的字串
'''如果非要用2個表單,參照下面
'''Form2.Show
'''Form2.Pic1.Print w1
Else
MsgBox "請在文本框中輸入1~30的數字"
End If
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/109556.html
標籤:VB基礎類
上一篇:vb 程式運行提示ADO needs to be installed to use Databinding
下一篇:跌跌撞撞中走過的VB網路編程之路
