五笔打字通主页
VB程序题:窗体上建立一个简单组合框,在组合框的文本框输入数字字符,按回车键后加入到组合框的列表框内,如图E.8(下图)所示;单击“交换”按钮,将列表框中最小值项目和第0个项目交换;最大值与最后项目交换,如图E.9所示。(wb86.com)
解题,代码如下:
Sub Combo1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57, 13, 8 '只允许数字键和回车键,删除键
Case Else
KeyAscii = 0
End Select
If KeyAscii = 13 Then
Combo1.AddItem Combo1.Text
Combo1.Text = ""
End If
End Sub
Private Sub Command1_Click()
Dim min%, max%
min = Val(Combo1.List(0))
max = Val(Combo1.List(0))
imin = 0
imax = 0
For i = 1 To Combo1.ListCount - 1
If Val(Combo1.List(i)) > max Then
imax = i
max = Combo1.List(i)
ElseIf Val(Combo1.List(i)) < min Then
imin = i
min = Combo1.List(i)
End If
Next i
t = Combo1.List(0)
Combo1.List(0) = Combo1.List(imin)
Combo1.List(imin) = t
t = Combo1.List(Combo1.ListCount - 1)
Combo1.List(Combo1.ListCount - 1) = Combo1.List(imax)
Combo1.List(imax) = t
End Sub
图E.9:
Visual Basic程序设计教程(第3版) (龚沛曾等编)课后实验源码
来源:济亨网
本文链接:https://wb98.com/post/86.html