vb编程!!
在窗体上建立一个简单组合框,在组合框的文本区输入数字字符,按回车键后加入到组合框的列表区内(非数字则不加入),然后清空文本区,如图6-2(a)所示;单击“交换”按钮后,可将组合框列表区中最小值项目和第0个项目交换;最大值项目与最后项交换, 如图6-2(b)所示。窗体中所有控件字体默认大小。
补充:我需要是调用函数做的!
追问:调用函数的怎么做啊?
答案:我帮你做了一个图6-2(a)的例子。即按交换后将最小值跟第0项交换。代码如下:
Option Explicit
Dim myX()
Dim n As Long
Dim myMin
Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
List1.AddItem Combo1.Text
n = n + 1
ReDim Preserve myX(n)
myX(n - 1) = Combo1.Text
If n = 1 Then myMin = Val(Combo1.Text)
If Val(Combo1.Text) < myMin Then
myMin = Val(Combo1.Text)
End If
Combo1.Text = ""
End If
End Sub
Private Sub Command1_Click()
Dim x0
Dim i As Long
Dim myStr As String
myStr = Join(myX, ",")
If LenB(myStr) > 0 Then
x0 = myX(0)
myX(0) = myMin
Debug.Print x0, myMin, UBound(myX)
For i = 1 To UBound(myX) - 1
If Val(myX(i)) = Val(myMin) Then
myX(i) = x0
Exit For
End If
Next i
List1.Clear
For i = 0 To UBound(myX) - 1
List1.AddItem myX(i)
Next i
End If
End Sub
Private Sub Form_Load()
Combo1.Text = ""
n = 0
List1.Clear
myMin = 0
End Sub
上一个:VB编程请教
下一个:vb编程题