当前位置:文档之家› Vb上机实验答案

Vb上机实验答案

第一题
1.制作如图所示窗体界面。

(用真实的姓名、班级及学号)
2.使时间每隔1秒刷新一次
3.单击“最大值”命令按钮时,算出通过键盘输入的5个数的最大

4.在列表框中输入20、22、24、26、28
Private Sub Command1_Click()
Dim a(1 To 5) As Integer
For i = 1 To 5
a(i) = InputBox("please input a number")
Next i
mmax = a(1)
For i = 1 To 5
If a(i) > mmax Then
mmax = a(i)
End If
Next i
MsgBox mmax
End Sub
Private Sub Timer1_Timer()
Label2.Caption = Time
End Sub
第二题
1.两个文本框里输入两个数字从而确定一个范围。

2.单击“计算”按钮求出这个范围中能被3或5整除的数的平方和,
结果显示在label3中。

bel3的背景色每隔1.5秒蓝红交替。

Private Sub Command1_Click()
Dim a As Integer
Dim b As Integer
a = Text1.Text
b = Text2.Text
s = 0
For i = a To b
If a Mod 3 = 0 Or b Mod 5 = 0 Then
Label3.Caption = Label3.Caption & i & ","
s = s + i * i
End If
Next i
Label3.Caption = s
End Sub
Private Sub Timer1_Timer()
If Label3.BackColor = vbRed Then
Label3.BackColor = vbBlue
Else
Label3.BackColor = vbRed
End If
End Sub
第三题
1、单击按钮,在文本框中显示1到终值的所有整数的平方和
2、单击生成列表按钮,在列表框中显示1到终值之间的所有整数
Private Sub Command1_Click()
Dim a As Integer
a = Text1.Text
s = o
For i = 1 To a
s = s + i * i
Next i
Text2.Text = s
End Sub
Private Sub Command2_Click()
Dim a As Integer
a = Text1.Text
For i = 1 To a
List1.AddItem i
Next i
End Sub
第四题
1、“大家好”的背景颜色红蓝黄交替,单击“停止”按钮时停止
颜色变化
2、在文本框中写入任意数字,单击“生成列表”按钮,将1到文
本框中输入数字之间所有能被3整除得数在列表框中显示
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Command3_Click()
Dim a As Integer
a = Text1.Text
For i = 1 To a
If i Mod 3 = 0 Then
List1.AddItem i
End If
Next i
End Sub
Private Sub Timer1_Timer()
If Label1.ForeColor = vbRed Then
Label1.ForeColor = vbBlue
ElseIf Label1.ForeColor = vbBlue Then
Label1.ForeColor = vbYellow
Else: Label1.ForeColor = vbRed
End If
End Sub
第五题
1、“大家好”电子滚动平当单击按钮“开始”时从左向右滚动,
当滚动到屏幕最右端的时候,从新回到最左端开始滚动;单击“停止”按钮时停止滚动
2、在文本框中写入任意内容,单击“添加”按钮可以将文本框中
的内容加入到列表框中
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Command3_Click()
List1.AddItem Text1.Text
End Sub
Private Sub Timer1_Timer()
Label1.Left = Label1.Left + 100
If Label1.Left > Form1.Width - Label1.Width Then
Label1.Left = 0
End If
End Sub
第六题
1、标签中写入“大家好”,每秒钟“大家好”和“哈哈”交替出
现(即,第一秒出现“大家好”。

第二秒出现“哈哈”依次交替)
2、提示:使用计时器控件完成交替出现
3、两个文本框中任意输入数字,当单击“显示”按钮,在标签2
中显示数值大的数,如果输入的数值相同,在标签2中显示“数值相等”。

Private Sub Command1_Click()
If Text1.Text > Text2.Text Then
Label2.Caption = Text1.Text
Else
If Text1.Text = Text2.Text Then
Label2.Caption = "数值相等"
Else
Label2.Caption = Text2.Text
End If
End If
End Sub
Private Sub Timer1_Timer()
If Label1.Caption = "大家好" Then
Label1.Caption = "哈哈"
Else
Label1.Caption = "大家好"。

相关主题