制作加法器
Private Sub Command1_Click()
Text3 = Val(Text1) + Val(Text2)
End Sub
Private Sub Command2_Click()
Text1 = ""
Text2 = ""
Text3 = ""
Text1.SetFocus
End Sub
Private Sub Form_Load()
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0
End Sub
健康称
Private Sub Command1_Click()
Dim bz As Integer
bz = Text1 - 105
If Text2 > bz * 1.1 Then
Label5.Caption = "偏胖,注意节食"
ElseIf Text2 < bz * 0.9 Then
Label5.Caption = "偏瘦,增加营养"
Else
Label5.Caption = "正常,继续保持"
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii > 57 Or KeyAscii < 48 Then KeyAscii = 0
End Sub
Private Sub Text2_Change()
If KeyAscii > 57 Or KeyAscii < 48 Then KeyAscii = 0
End Sub
反弹球
Private Sub qd_Click()
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Static a1 As Boolean
Static b1 As Boolean
If Shape1.Left >= Form1.ScaleWidth - Shape1.Width Then
a1 = True
End If
If Shape1.Left <= 0 Then
a1 = False
End If
If a1 Then
Shape1.Left = Shape1.Left - 100
Else
Shape1.Left = Shape1.Left + 100
End If
If Shape1.Top >= Form1.ScaleHeight - Shape1.Height Then
b1 = True
End If
If Shape1.Top <= 0 Then
b1 = False
End If
If b1 Then
Shape1.Top = Shape1.Top - 100
Else
Shape1.Top = Shape1.Top + 100
End If
End Sub
Private Sub tz_Click()
Timer1.Enabled = False
End Sub
密码设置
Private Sub Form_Load()
Label2.Left = (Form1.ScaleWidth - Label2.Width) \ 2
End Sub
Private Sub Label1_Click()
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Static a
If KeyAscii = 13 Then
If Text1.Text = "1234567" Then
Label2.Caption = "欢迎光临!"
Label2.ForeColor = RGB(255, 0, 0)
Text1.Enabled = False
Else
If a = 0 Then
Label2.Caption = "密码不符,请再输入一遍!"
Text1.Text = ""
Text1.SetFocus
a = a + 1
Else
Label2.Caption = "非法用户,请退出程序"
Text1.Text = ""
Text1.Enabled = False
End If
End If
End If
End Sub
List2.RemoveItem List2.ListCount - 1
End Sub
偶数迁移
Dim a(10)
Private Sub Command1_Click()
Dim i
List1.Clear
List2.Clear
Randomize
For i = 0 To 9
a(i) = Int(Rnd * 90 + 10)
List1.AddItem a(i)
Next i
End Sub
Private Sub Command2_Click()
Dim i, k
Do While i <= List1.ListCount - 1
If Val(List1.List(i)) Mod 2 = 0 Then
List2.AddItem List1.List(i)
List1.RemoveItem i
Else
i = i + 1
End If
Loop
End Sub
点餐
Private Sub Check1_Click(Index As Integer)
Text1(Index).Enabled = Check1(Index).Value
If Check1(Index) = 1 Then
Text1(Index).SetFocus
Else
Text1(Index).Text = ""
End If
End Sub
Private Sub Command1_Click()
Dim a%
a = 13 * Val(Text1(0).Text) + 18 * Val(Text1(1).Text) + 25 * Val(Text1(2).Text)
MsgBox "一共" & a & "元"
End Sub
替换
Private Sub Command1_Click()
Dim st1$, st2$, st3$, len2, len3, i
i = 1
st1 = Text1
st2 = Text2
st3 = Text3
len2 = Len(st2)
len3 = Len(st3)
k = InStr(i, st1, st2)
Do While k > 0
st1 = Left(st1, k - 1) & st3 & Mid(st1, k + len2)
k = InStr(k + len3, st1, st2)
Loop
Text1.Text = st1
End Sub
简单动画
' 在标签2的属性框中将index 设为0
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Form_Load()
Dim i
For i = 1 To 5
Load Label2(i)
Label2(i).Left = Label2(i - 1).Left + Label2(0).Width
Next i
End Sub
Private Sub Timer1_Timer()
Static k
Dim i
For i = 0 To 5
Label2(i).Visible = False
Next i
Label2(k).Visible = True
k = (k + 1) Mod 6
End Sub
设置密码
Private Sub Command1_Click()
If Text1.Text = "admin" And Text2.Text = "admin" Then
If Text3.Text = Text4.Text Then
MsgBox "修改密码成功!", , "修改密码"
End
Else
MsgBox "新密码有误,请重试", , "修改密码"
End If
Else
MsgBox "用户名或密码无效,请重试!", , "修改密码"
End If
End Sub
Private Sub Command2_Click()
End
End Sub
辨别质数
Private Sub Command1_Click()
Dim a%, i%
If Not IsNumeric(Text1) Then
MsgBox "输入的不是数字,无法计算"
Else
a = Text1
For i = 2 To Int(Sqr(a))
If a Mod 2 = 0 Then Exit For
Next i
If i > Int(Sqr(a)) Then
Label3.Caption = a & "是质数"
Else
Label3.Caption = a & "不是质数"
End If
End If
If Text1 = "1" Then Label3.Caption = a & "不是质数"
End Sub
改变圆的大小
Private Sub Form_Load()
Shape1.Left = (Form1.ScaleWidth - Shape1.Width) \ 2
Shape1.Top = (Form1.ScaleHeight - Shape1.Height) \ 2 - 800
End Sub
Private Sub HScroll1_Scroll()
Shape1.Height = HScroll1.Value
Shape1.Width = HScroll1.Value
Label2.Caption = HScroll1.Value
Form_Load
End Sub
Command1(i).Left = Command1(i - 1).Left + 800
Command1(i).Top = Command1(i - 1).Top
End If
If i = 9 Then
Command1(i).Caption = "0"
ElseIf i = 10 Then
Command1(i).Caption = "重拨"
Else
Command1(i).Caption = i + 1
End If
If i = 10 Then
Command1(i).Width = Command1(i).Width + 800
End If
Command1(i).Visible = True
Next i
Text1.ForeColor = RGB(0, 0, 255)
End Sub
Private Sub Timer1_Timer()
Static i
Dim st1 As String
st1 = Mid(s1, i + 1, 1)
i = i + 1
Text1.Text = Text1.Text & st1
If Text1.Text = s1 Then Timer1.Enabled = False: i = 0
End Sub
本文档为【VB等级考试VB二级题库上机题小结常识】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。