Visual Basic程序设计期末复习(20061204)

2026/1/19 14:10:01

Next i

Print i, k End Sub

写出程序运行时单击窗体后,Form1上的输出结果。

6.

Private Sub Form_Click()

Dim i As Integer, k As Integer, c As Integer For i = 1 To 5

If i Mod 2 = 0 Then k = k + 2 Else c = c + 2 End If Next i

Print k, c

End Sub

写出程序运行时单击窗体后,Form1上的输出结果。

7.

Sub Change(ByVal x As Integer, ByVal y As Integer) Dim t As Integer t = x x = y y = t Print x, y End Sub

Private Sub Form_Click()

Dim a As Integer, b As Integer a = 10: b = 20 Change a, b Print a, b End Sub

写出程序运行时单击窗体后,Form1上的输出结果。 8.

Private Sub Form_Click() Static Sum As Integer For I = 1 To 5 Sum = Sum + I Next I

Print Sum End Sub

写出程序运行时单击窗体后,Form1上的输出结果。

9

9.

Private Sub Form_Click()

Dim c As Integer, j As Integer, k As Integer k = 0

c = 1

For j = 1 To 6 If j > 4 Then c = c + 5 Exit For Else k = k + 1 End If Next j Print c, k End Sub

写出程序运行时单击窗体后,c,k的值分别是:

10 .

Private Sub Command1_Click()

Dim s As Double Dim i As Integer s = 5 i = 1

Do While i < 9 i = i + 2 s = s + i

Loop

Text1.Text = s End Sub

文件框Text1的输出结果是:

11.

Private Sub Command1_Click() Dim X As Integer, Y As Integer X = 0: Y = 1 For i = 1 To 3 For j = 1 To i Y = Y * j Next j X = X + Y Next i Print X End Sub

10

写出程序运行时单击命令按钮后,窗体Form1上的输出结果。

12.

Function F(a As Integer) Dim b As Integer Static c As Integer b = b + 2 c = c + 2

F = a + b + c End Function

Private Sub Command1_Click() Dim a As Integer a = 6

For i = 1 To 3 Print F(a)

Next i End Sub

写出程序运行时,单击命令按钮在窗体上的输出结果。

13.

Private Sub Form_Click() Dim A(1 To 4) As String Dim c As Integer Dim j As Integer A(1) = \ A(2) = \ A(3) = \ A(3) = \ c = 1

For j = 1 To 4 c = c + Val(A(j)) Next j Print c End Sub

写出程序运行时单击窗体后,窗体Form1上的结果:

四、完善程序题

1.假设用Access创建了一个名为“学生.MDB”的数据库,并在其中创建了一张名为“学生基本情况”的数据表,表中存放了学生的基本信息,如图1所示。

11

现在要求利用VB编写一个数据库查询程序,程序的运行界面如图2所示,基本逻辑是:首先文本框(Text1)中输入希望查询的学生学号,然后点击“查询”按钮(Command1),如果数据库中存在该学号,则分别在Text2、Text3、Text4中显示学号、姓名、籍贯信息,否则提示用户“记录不存在”并使Text1获得焦点,要求用户重新输入。当点击退出按钮(Command2)时关闭本窗体。

图1用Access创建的学生基本情况数据表

图2 查询程序运行界面

程序如下,请补充完整。 Private ADOcn As Connection

Private Sub Form_Load() [1]

[2] \学生.MDB\End Sub

Private Sub Command1_Click() Dim strSQL As String

Dim ADOrs As [3] Recordset

ADOrs.ActiveConnection = [4] strSQL = \学生基本情况 Where 学号=\ [5]

If [6] Then

12


Visual Basic程序设计期末复习(20061204).doc 将本文的Word文档下载到电脑
搜索更多关于: Visual Basic程序设计期末复习(20061204) 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219