VB小程序制作

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

VB程序设计
实验目的
1)掌握VB多重窗体程序的概念。

2)掌握多重窗体程序的设计方法。

3)复习各种控件的使用方法。

实验内容
采用多窗体技术编写程序,分别在不同的窗体上实现不同功能。

实验步骤
实验步骤如下:
1)建立启动窗体界面与设置对象属性。

选择“新建”工程,进入窗体设计器,在窗体中添加命令按钮组Command1(0)~Command1(5),并修改属性如图8-1左所示。

系统默认窗体Form1为启动窗体。

2)添加窗体。

选择“工程”菜单,打开“添加窗体”对话框。

按“打开”按钮,添加3个标准窗体Form2~Form4。

添加标准模块。

选择“工程”菜单,打开“添加模块”对话框。

按“打开”按钮,添加1个标准模块Module1。

图8-1 程序界面设计
3)建立子窗体界面与设置对象属性。

界面如图8-1所示,设置属性如表所示。

表8-1 Form1属性设置
对象属性属性值说明
Form1 Name Form1 启动窗体
Caption Form1
Command1(0)Caption Who are you?
Command1(1)Caption game
Command1(2)Caption writeboard
Command1(3)Caption calculator
Command1(4)Caption byebye
Picture1 autoredraw false
Label1 caption Let's start a wonderful
journey
表8-2 Form2属性设置
对象属性属性值说明
Form2 Name Form2 输入个人资料窗口
Caption Form2
Label11 Caption name
Label12 Caption gender
Label13 Caption Is that a girl?
Fream1 Caption hobbies
command caption okey
Caption
Option1 Caption female
Value True 默认被选中Option2 Caption male
Value True 默认被选中Check1 Caption WoW
Check2 Caption League of Legends
Check3 Caption Dungeon and Fighter
Check4 Caption QQspeed
Check5 Caption films
Check6 Caption movie
表8-3 Form3属性设置
对象属性属性值说明
Form3 Name Form3
Caption Form3
Command1 Caption happiness
Command2 Caption begin
Command3 Caption love
Command4 Caption beauty
Command5 Caption laugh
Label1 caption scroes
Label2 Caption 0
Timer1 interval 500
Timer2 interval 71
表8-4 Form4属性设置
对象属性属性值说明
Form4 Name Form4
Caption Form4
Label caption
Label2 Caption 路漫漫其修远兮
Label3 Caption 吾将上下而求索
TextBox text
Picture1 picture
Caption 返回
表8-5 Form5属性设置
对象属性属性值说明
Form Name Form5
Caption Form5
Command1(0~9) caption 1~9,0
Command1(10) caption .
Command2(0~4) caption +-*/=
Label2 Caption 路漫漫其修远兮
Label3 Caption 吾将上下而求索
TextBox text
表8-6 Form6属性设置
对象属性属性值说明Form4 Name Form6
Caption Form6
Label caption welcome to use this
system again !!
Label2 Caption thank you !
Picture1 picture
Timer1~12 interval 1
Timer13 interval 1000
4)编写代码。

编写“启动”窗体form1(Form1)中代码:
Option Explicit
Dim i As Integer, ur1 As String, N As Integer
Private Sub Command1_Click(Index As Integer)
N = Index
Select Case N
Case 0
Case 1
Case 2
Case 3
Case 5
End Select
End Sub
Private Sub Form_Activate()
= True
End Sub
Private Sub Form_Load()
= - / 2
= - / 2
Picture2 = LoadPicture("C:\Users\LQR\Desktop\VB.\")
= True
, 0, 0, 3000, 3000, , , , , vbSrcCopy
End Sub
Private Sub Timer1_Timer()
On Error GoTo Err
ur1 = "C:\Users\LQR\Desktop\VB.\" & i & ".gif"
= LoadPicture(ur1)
i = i + 1
= True
, 0, 0, 3000, 3000, , , , , vbSrcCopy
Exit Sub
Err:
i = 1
End Sub
编写“输入个人资料”窗体form2(Form2)中的代码:
Private Sub Command1_Click()
If = "" Then
a = InputBox("You forget to input your name?", "Attention!", "Your name!")
If a = "" Or a = "Your name!" Then Exit Sub
= a
Else:
End If
End Sub
Private Sub Form_Load()
= - / 2
= - / 2
Picture1 = LoadPicture("C:\Users\LQR\Desktop\VB.\")
= True
, 0, 0, 3750, 4900, , , , , vbSrcCopy
End Sub
编写“GAME”窗体form3(Form3)中的代码:
Dim a As Integer, i As Integer, ur1 As String
Private Sub Command1_Click()
If = RGB(225, 0, 0) Then
Label2 = Val + 1
End If
End Sub
Private Sub Command2_Click()
= True
End Sub
Private Sub Command3_Click()
If = RGB(225, 0, 0) Then
Label2 = Val + 1
End If
End Sub
Private Sub Command4_Click()
If = RGB(225, 0, 0) Then
Label2 = Val + 1
End If
End Sub
Private Sub Command5_Click()
If = RGB(225, 0, 0) Then
Label2 = Val + 1
End If
End Sub
Private Sub cw_Click()
Label2 = ""
End Sub
Private Sub Timer2_Timer()
On Error GoTo Err
ur1 = "C:\Users\LQR\Desktop\新建文件夹.\" & i & ".jpg"
= LoadPicture(ur1)
i = i + 1
= True
, 0, 0, 12135, 8295, , , , , vbSrcCopy
Exit Sub
Err:
i = 45
End Sub
Private Sub Form_Load()
= - / 2
= - / 2
Picture1 = LoadPicture("C:\Users\LQR\Desktop\新建文件夹.\") = True
, 0, 0, 12135, 8295, , , , , vbSrcCopy
End Sub
Private Sub Timer1_Timer()
Static x As Integer
a = Int(Rnd() * 4)
Select Case a
Case 0
= RGB(225, 0, 0)
= RGB(15, 0, 0)
= RGB(15, 0, 0)
= RGB(15, 0, 0)
Case 1
= RGB(225, 0, 0)
= RGB(15, 0, 0)
= RGB(15, 0, 0)
= RGB(15, 0, 0)
Case 2
= RGB(225, 0, 0)
= RGB(15, 0, 0)
= RGB(15, 0, 0)
= RGB(15, 0, 0)
Case 3
= RGB(225, 0, 0)
= RGB(15, 0, 0)
= RGB(15, 0, 0)
= RGB(15, 0, 0)
End Select
If x < 50 Then
x = x + 1
Else
= False
= RGB(15, 0, 0)
= RGB(15, 0, 0)
= RGB(15, 0, 0)
= RGB(15, 0, 0)
x = 0
End If
End Sub
Private Sub tui_Click()
End Sub
Private Sub wf_Click()
MsgBox "rules:" & Chr(13) & "Hit the different the fixed time, more hits, more scores!!", vbOKOnly, "Rule"
End Sub
编写“writeboard”窗体form4(Form4)中的代码:
Private Sub N_Click()
= ""
End Sub
Private Sub O_Click()
= "所有文件(*.*)|*.*|文本文件(*.TXT)|*.txt"
= 1
=
End Sub
Private Sub S_Click()
=
End Sub
Private Sub T_Click()
End Sub
Private Sub Text1_Change()
=
End Sub
Private Sub Y_Click()
=
Private Sub Z_Click()
= 3 Or 256
With Text1
.FontName =
.FontSize =
.FontStrikethru =
.FontBold =
.FontItalic =
.FontUnderline =
.ForeColor =
End With
End Sub
Private Sub Form_Load()
= - / 2
= - / 2
Picture1 = LoadPicture("C:\Users\LQR\Desktop\VB.\")
= True
, 0, 0, 1500, 2500, , , , , vbSrcCopy
End Sub
编写“calculator”窗体form5(Form5)中的代码:
Dim v As Boolean
Dim S As Integer
Dim x As Double
Dim Y As Double
Private Sub Command1_Click(Index As Integer)
If = "T" Then
If Index = 10 Then
= "0"
Else
= Command1(Index).Caption
End If
= ""
Else
= & Command1(Index).Caption
End If
End Sub
Private Sub Command2_Click(Index As Integer)
= "T"
If v Then
v = Not v
Else
Y = Val
Select Case S
Case 0
= x + Y
Case 1
= x - Y
Case 2
= x * Y
Case 3
If Y <> 0 Then
= x / Y
Else
MsgBox "傻了?不能以0为除数啊!", vbOKOnly, "提示"
= x
v = False
End If
Case 4
Y = 0
v = False
End Select
x = Val
End If
S = Index
End Sub
Private Sub Form_Load()
= - / 2
= - / 2
End Sub
Private Sub tui_Click()
End Sub
Private Sub xin_Click()
= ""
End Sub
编写结束窗体form6(Form6)中的代码:
Option Explicit
Dim x As Integer, Y As Integer, a As Integer, m As Long, N As Long
Private Sub Form_Activate()
= True
= True
= True
= True
= True
= True
End Sub
Private Sub Form_Load()
= - / 2
= - / 2
Picture1 = LoadPicture("C:\Users\LQR\Desktop\VB.\") = True
, 0, 0, 2250, 2250, , , , , vbSrcCopy
Picture2 = LoadPicture("C:\Users\LQR\Desktop\VB.\") = True
, 0, 0, 2250, 2250, , , , , vbSrcCopy
Picture3 = LoadPicture("C:\Users\LQR\Desktop\VB.\") = True
, 0, 0, 2250, 2250, , , , , vbSrcCopy
End Sub
Private Sub Timer1_Timer()
If + >= Then
= True
= False
Else
= + 50
End If
End Sub
Private Sub Timer2_Timer()
If <= 0 Then
= True
= False
Else
= - 50
End If
End Sub
Private Sub Timer3_Timer() If + > 6700 Then
= True
= False
Else
= + 50
End If
End Sub
Private Sub Timer4_Timer() If < 0 Then
= True
= False
Else
= - 50
End If
End Sub
Private Sub Timer5_Timer() If + >= Then
= True
= False
Else
= + 50
End If
End Sub
Private Sub Timer6_Timer() If <= 0 Then
= True
= False
Else
= - 50
End If
End Sub
Private Sub Timer7_Timer() If + > 6700 Then
= True
= False
Else
= + 50
End If
End Sub
Private Sub Timer8_Timer() If < 0 Then
= True
= False
Else
= - 50
End If
End Sub
Private Sub Timer9_Timer() If + >= Then
= True
= False
Else
= + 50
End If
End Sub
Private Sub Timer10_Timer() If <= 0 Then
= True
= False
Else
= - 50
End If
End Sub
Private Sub Timer11_Timer() If + > 6700 Then
= True
= False
Else
= + 50
End If
End Sub
Private Sub Timer12_Timer() If < 0 Then
= True
= False
Else
= - 50
End If
End Sub
Private Sub Timer13_Timer()
If a < 11 Then
a = a + 1
Else
End
End If
End Sub
5)运行窗体。

启动程序后,屏幕出现启动窗体,单击按钮,显示相应窗体,可以执行相应的命令,如图10-2所示。

图10-2 多重窗体程序。

相关文档
最新文档