内容发布更新时间 : 2024/12/26 12:25:10星期一 下面是文章的全部内容请认真阅读。
1选择
Option Explicit Dim c As Integer Function cha(a As Integer, b As Integer) _ As Integer cha = a - b End Function Function su(n As Integer) As Boolean Dim i As Integer Dim k As Integer k = Sqr(n) For i = 2 To k
If n Mod i = 0 Then Exit For End If Next i
If i > k Then su = True Else
su = False End If
End Function
Private Sub Ch_Click(Index As Integer) If Ch(Index).Value = 1 Then c = c + 1 Else
c = c - 1 End If
If c > 4 Then
MsgBox \多了\ Ch(Index).Value = 0 End If End Sub
Private Sub Command1_Click() Dim i As Integer Dim s As String s = \守门员:\For i = 0 To 4
If Op(i).Value = True Then s = s & Op(i).Caption
End If Next i
s = s & Chr(13) & \队员:\For i = 0 To 8
If Ch(i).Value = 1 Then
s = s & Ch(i).Caption & \ \ End If Next i
If c = 4 Then MsgBox s Else
MsgBox \少了\End If
'Printer.Print s End Sub
2列表框
Option Explicit
Private Sub Command1_Click() Dim s As String Dim i As Integer Dim cf As Boolean
If L1.ListIndex > -1 Then s = L1.List(L1.ListIndex) For i = 0 To L2.ListCount - 1 If s = L2.List(i) Then cf = True Exit For End If Next i
If cf = False Then L2.AddItem s End If
'L1.RemoveItem L1.ListIndex End If End Sub
Private Sub Command2_Click() Dim i As Integer
For i = 0 To L1.ListCount - 1 L2.AddItem L1.List(i)
Next i L1.Clear End Sub
3组合框
Option Explicit
Private Sub Command1_Click() Dim i As Integer
Dim cf As Boolean
For i = 0 To C.ListCount - 1 If C.Text = C.List(i) Then cf = True Exit For End If Next i
If cf = False Then C.AddItem C.Text End If End Sub
4列表框与组合框 Option Explicit
Private Sub Command1_Click() Dim i As Integer
For i = 0 To L1.ListCount - 1 If L1.Selected(i) Then
L2.AddItem L1.List(i) End If Next
For i = L1.ListCount - 1 To 0 If L1.Selected(i) Then L1.RemoveItem i End If Next
End Sub
5滚动条
Option Explicit
Private Sub Form_Load() T.Text = \End Sub
Private Sub H_Change() T.Text = H.Value / 10
L.Caption = Val(T1.Text) * H.Value / 10 End Sub
Private Sub H_Scroll() T.Text = H.Value / 10
L.Caption = Val(T1.Text) * H.Value / 10 End Sud
6曲线等
Option Explicit
Private Sub Command1_Click() Me.Cls
Me.Scale (-3, 3)-(9, -3)
Dim X As Single, Y As Single Const pi = 3.1415926
For X = 0 To pi * 2 Step 0.001 Y = Sin(X)
Me.PSet (X, Y), vbRed Next X
For Y = 2 To -2 Step -0.001 Me.PSet (0, Y), vbBlue Next Y
Me.Line (-2, 0)-(8, 0), vbBlue For X = -1 To 7
Me.Line (X, 0)-(X, 0.1), vbBlue Me.CurrentX = X - 0.2 Me.CurrentY = -0.1 If X <> 0 Then Print X Next X
Me.CurrentX = -0.5 Me.CurrentY = 0.2 Print \
Me.Line (8, 0)-(7.8, 0.1), vbBlue
Me.Line (8, 0)-(7.8, -0.1), vbBlue End Sub
Private Sub Command2_Click() Me.Cls
Me.Scale (-10, 13)-(19, -13) Line (-6, 0)-(15, 0) Line (0, 10)-(0, -10)
Line (-5, 3)-Step(6, -2), , B End Sub
Private Sub Command3_Click() Me.Scale (-10, 13)-(19, -13)
Me.Circle (0, 0), 5, vbRed, -0.0000000001, -1.57 End Sub
7时间
Option Explicit
Private Sub T_Timer() Randomize
L.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255) L.Caption = Time L.Left = L.Left + 100
If L.Left >= Me.ScaleWidth Then L.Left = -L.Width End If
End Sub
8打字母
Option Explicit
Dim d As Integer, C As Integer Sub cs() Randomize
L.Left = Rnd * (Me.ScaleWidth - L.Width) L.Top = -L.Height L.Caption = zimu End Sub Private Function zimu() Randomize
Dim k As Integer