您现在的位置:中国下载站学院中心网络编程Visual Basic教程Visual Basic基础教程 → 文章列表

Visual Basic上机考试综合应用题选讲

作者:佚名  来源:不详  发布时间:2007-4-13 13:54:36   

减小字体 增大字体

 
 
一、 素数判断与计算、输出题,并把计算与存盘部分补充完整!

Private Function isprime(a As Integer) As Boolean
 Dim flag As Boolean
 flag = True
 b% = 2
 Do While b% <= Int(a / 2) And flag
  If Int(a / b%) = a / b% Then
   flag = False
  Else
   b% = b% + 1
  End If
 Loop
 isprime = flag
End Function
+++++++以下黑体字部分是程序中没有的,需要自己被充+++++++
Private Sub C1_Click()
 Dim i As Integer
 i = 18000
 Do
  i = i - 1
 Loop Until isprime(i)
 Text1.Text = i
End Sub
Private Sub C2_Click()
 Open "out5.txt" For Output As #1
 Print #1, Text1.Text
 Close #1
End Sub

  二、判断口令题,关键是一些循环语句及选择结构的综合应用:

Private Sub C1_Click()
 If Text1.Text = "123456" Then
  Text1.Text = "口令正确"
  Text1.PasswordChar = ""
 Else
  Text2.Text = Text2.Text - 1
  If Text2.Text > 0 Then
   MsgBox "第" & (3 - Text2.Text) & "次口令错误,请重新输入"
  Else
   MsgBox "3次输入错误,请退出"
   Text1.Enabled = False
  End If
 End If
End Sub

  三、图片转换题:

Private Sub Timer1_Timer()
 a = a + 1
 If a > 6 Then
  a = 1
 End If
 Select Case a
  Case 1
   P1.Picture = LoadPicture("黄灯.ico")
  Case 2, 3
   P1.Picture = LoadPicture("红灯.ico")
  Case 4, 5, 6
   P1.Picture = LoadPicture("绿灯.ico")
   If b Then Timer2.Enabled = b
 End Select
End Sub
Private Sub Timer2_Timer()
 If (a < 4) And (P2.Left > P1.Left And P2.Left < P1.Left + P1.Width) Or P2.Left <= 100 Then
  Timer2.Enabled = False
 Else
  P2.Move P2.Left - 10, P2.Top, P2.Width, P2.Height
 End If
End Sub

  四、数据计算与行列式综合应用题:

Option Base 1
Dim Arr1(20) As Integer
Dim Arr2(20) As Integer
Dim Sum As Integer
Sub ReadData1()
 Open App.Path & "\" & "datain1.txt" For Input As #1
 For i = 1 To 20
  Input #1, Arr1(i)
 Next i
 Close #1
End Sub
Sub ReadData2()
 Open App.Path & "\" & "datain2.txt" For Input As #1
 For i = 1 To 20
  Input #1, Arr2(i)
 Next i
 Close #1
End Sub
Sub WriteData(Filename As String, Num As Integer)
 Open App.Path & "\" & Filename For Output As #1
 Print #1, Num
 Close #1
End Sub
Private Sub C1_Click()
 ReadData1
 ReadData2
End Sub
Private Sub C2_Click()
 Dim arr3(20) As Integer
 Sum = 0
 For i = 1 To 20
  arr3(i) = Arr1(i) \ Arr2(i)
  Sum = Sum + arr3(i)
 Next
 Print Sum
End Sub
Private Sub C3_Click()
 WriteData "dataout.txt", Sum
End Sub

  五、倒计数器

Private Sub C1_Click(Index As Integer)
 Select Case Index
  Case 1
   Timer1.Enabled = False
  Case 0
   Timer1.Enabled = True
 End Select
End Sub
Private Sub Form_Load()
End Sub
Private Sub Timer1_Timer()
 Text1.Text = Text1.Text + 1
End Sub

  六、文本框的使用

Private Sub C1_Click()
 Open App.Path & "\out7.txt" For Output As #2
 Print #2, Text1.Text
 Close #2
End Sub
Private Sub Form_Load()
 Open App.Path & "\in7.txt" For Input As #1
 Do While Not EOF(1)
  Input #1, mystring
  Text1.Text = Text1.Text + mystring
 Loop
 Close #1
 Text1.Text = "计算机等级考试" + Text1.Text
End Sub

  七、求某类数的和等:

Private Function fun(a As Integer) As Integer
 s% = 0
 For i% = 500 To 600
  If Int(i% / a) = i% / a Then
   s% = s% + i%
  End If
 Next
 fun = s%
End Function
Private Sub C1_Click()
 If Op1.Value Then
  Text1 = fun(7)
 End If
 If Op2.Value Then Text1 = fun(3)
End Sub
Private Sub Form_Unload(Cancel As Integer)
 Open "out7.txt" For Output As #1
 Print #1, Op1.Value, Op2.Value, Text1.Text
 Close #1
End Sub

  八、文本框的使用

Private Sub C1_Click()
 Open App.Path & "\in7.txt" For Input As #1
 Do While Not EOF(1)
  Input #1, mystring
  Text1.Text = mystring
 Loop
 Close #1
End Sub
Private Sub C2_Click()
 Text1.Text = UCase(Text1.Text)
End Sub
Private Sub C3_Click()
 Open App.Path & "\out7.txt" For Output As #2
 Print #2, Text1.Text
 Close #2
End Sub

  九、文本框应用第二例:

  第一部分,窗体程序部分:
Dim a(100) As Integer
Private Sub Cmd1_Click()
 Open App.Path & "\in.txt" For Input As #1
 Text1.Text = ""
 For i = 1 To 100
  Input #1, a(i)
  Text1.Text = Text1.Text & a(i) & Space(1)
 Next i
 Close #1
End Sub
Private Sub Cmd2_Click()
 Text1.Text = ""
 s = 0
 For i = 1 To 100
  If a(i) Mod 2 <> 0 Then
   Text1.Text = Text1.Text & a(i) & Space(1)
   s = s + a(i)
  End If
 Next
 putdata s
End Sub

  第二部分,模块程序部分:(如没有,需要自行添加一个标准模块
Sub putdata(ByVal a As Integer)
 Dim sFile As String
 sFile = "\out.txt"
 Open App.Path & sFile For Output As #1
 Print #1, a;
 Close #1
End Sub

  十、分苹果题:

在百度中搜索更多Visual Basic上机考试综合应用题选讲相关网页 转贴于:中国下载站

  • 上一篇文章:用VB6在托盘程序中加入应用程序图标
  • 下一篇文章:VB编程破解Windows屏幕保护密码
  • 阅读统计:[]
  • 中国下载站】【设为主页】【收藏本页】【打印本文】【回到顶部】【关闭此页

    相关文章
    文章评论(评论内容只代表网友观点,与本站立场无关!)

    用户名: 查看更多评论

    分 值:100分 85分 70分 55分 40分 25分 10分 0分

    内 容:

             (注“”为必填内容。) 验证码: 验证码,看不清楚?请点击刷新验证码


    设为首页 - 关于我们 - 广告服务 - 网站地图 - 加入收藏 - 网站声明 - 网站帮助 - 友情链接

    • Copyright (C) 2006-2008 www.cndownz.com All Rights Reserved.
      中国下载站 版权所有. 粤ICP备05141802号. 对本站有任何建议、意见或投诉,请来信:cndownzcom@yahoo.com.cn.
      喜欢中国下载站(cndownz.com),请把中国下载站(cndownz.com)告诉你QQ上的5位好友,多谢支持!