学院首页 软件应用 编程开发 创意设计 认证培训 软件论坛
ASP ASP.NET PHP JSP SQL MYSQL Java VB

您的位置:学院 >> 编程开发 >> VB >> Visual Basic上机考试综合应用题选讲


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


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


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

  十、分苹果题:


Option Explicit

Private Sub Command1_Click(Index As Integer)

 If Index = 0 Then
  If Val(Label3(0).Caption) > 1 Then
   Command1(0).Enabled = True
   Label3(0).Caption = Label3(0).Caption - 1
  Else
   If Val(Label3(0).Caption) = 1 Then
    Label3(0).Caption = Label3(0).Caption - 1
   End If
   Command1(0).Enabled = False
  End If
 Else
  If Val(Label3(1).Caption) > 1 Then
   Command1(1).Enabled = True
   Label3(1).Caption = Label3(1).Caption - 1
  Else
   If Val(Label3(1).Caption) = 1 Then
    Label3(1).Caption = Label3(1).Caption - 1
   End If
   Command1(1).Enabled = False
  End If

 End If
 If Val(Label3(0).Caption) > Val(Label3(1).Caption) Then
  picSmile(0).Visible = True
  picCry(0).Visible = False
  picCry(1).Visible = True
  picSmile(1).Visible = False
 Else
  If Val(Label3(0).Caption) < Val(Label3(1).Caption) Then
   picCry(0).Visible = True
   picSmile(0).Visible = False
   picSmile(1).Visible = True
   picCry(1).Visible = False
  Else
   picSmile(0).Visible = True
   picCry(0).Visible = False
   picSmile(1).Visible = True
   picCry(1).Visible = False
  End If
 End If

End Sub

Private Sub Command2_Click(Index As Integer)

 If Index = 0 Then
  Label3(0).Caption = Label3(0).Caption + 1
  Command1(0).Enabled = True
 Else:
  Label3(1).Caption = Label3(1).Caption + 1
  Command1(1).Enabled = True
 End If

 If Val(Label3(0).Caption) > Val(Label3(1).Caption) Then
  picSmile(0).Visible = True
  picCry(0).Visible = False
  picCry(1).Visible = True
  picSmile(1).Visible = False
 Else
  If Val(Label3(0).Caption) < Val(Label3(1).Caption) Then
   picCry(0).Visible = True
   picSmile(0).Visible = False
   picSmile(1).Visible = True
   picCry(1).Visible = False
  Else
   picSmile(0).Visible = True
   picCry(0).Visible = False
   picSmile(1).Visible = True
   picCry(1).Visible = False
  End If
 End If

End Sub

Private Sub Form_Load()

 picSmile(0).Visible = True
 picSmile(1).Visible = True
 Command1(0).Enabled = False
 Command1(1).Enabled = False

End Sub


  十一、简单综合题:


Private Sub COMEXIT_Click()
End
End Sub

Private Sub COMSTART_Click()
 Dim g As Single, N As Integer, S As Single
 myfile1 = App.Path & "\" & "grade.DAT"
 myfile2 = App.Path & "\" & "average.dat"
 Open myfile1 For Input As #1
 Open myfile2 For Output As #2
 Do While Not EOF(1)
  Input #1, g
  N = N + 1
  S = S + g
 Loop
 Close #1
 S = S / N
 Write #2, S
 Close
 COMSTART.Caption = "完成"
 COMSTART.Enabled = False
End Sub

  十二、文本加密题:


Private Sub C1_Click()
 Dim strinfo As String
 Open "in7.txt" For Input As 1
 Input #1, strinfo
 Close #1
 Text1.Text = strinfo
End Sub

Private Sub C2_Click()
 Dim strchange As String
 Dim i As Integer
 For i = 1 To Len(Text1.Text)
  strchange = strchange + Chr(Asc(Mid(Text1.Text, i, 1)) + 2)
 Next
 Text1.Text = strchange
End Sub

Private Sub C3_Click()
 Open "out7.txt" For Output As 1
 Print #1, Text1.Text
 Close #1
End Sub

  十三、数组综合应用题:


  本程序解答分二部分,一部分在窗体模块:

Option Explicit
 Dim a(1 To 100)
 Dim i As Integer
 Dim n As Integer
 Dim f As Integer
 Dim s As Long

Private Sub Cmd1_Click()
 Open App.Path & "\in.txt" For Input As #1
 For i = 1 To 100
  Input #1, n
  a(i) = n
  Text1.Text = Text1.Text & a(i) & " "
 Next i
 Close #1
End Sub

Private Sub Cmd2_Click()
 For i = 1 To 100
  If a(i) <= 700 Then s = s + a(i)
 Next i
 Call putdata("out.txt", s)
 Text1.Text = s
End Sub

  另一部分在标准模块:

Option Explicit

Sub putdata(t_FileName As String, t_Str As Variant)
 Dim sFile As String
 sFile = "\" & t_FileName
 Open App.Path & sFile For Output As #1
 Print #1, t_Str
 Close #1
End Sub

  十四、素数应用又一例:


  本程序分两部分,第一部分在窗体模块:

Private Sub Cmd1_Click()
 Dim i As Integer
 Dim temp As Long
 temp = 0

 If Opt2.Value Then
  For i = 200 To 400
   If isprime(i) Then
    temp = temp + i
   End If
  Next
 Else
  For i = 100 To 200
   If isprime(i) Then
    temp = temp + i
   End If
  Next
 End If
 Text1.Text = temp
End Sub

Private Sub Cmd2_Click()
 putdata "\out.txt", Text1.Text
End Sub

  第二部分在标准模块:

Option Explicit

Sub putdata(t_FileName As String, T_Str As Variant)
 Dim sFile As String
 sFile = "\" & t_FileName
 Open App.Path & sFile For Output As #1
 Print #1, T_Str
 Close #1
End Sub

Function isprime(t_I As Integer) As Boolean
 Dim J As Integer
 isprime = False
 For J = 2 To t_I / 2
  If t_I Mod J = 0 Then Exit For
 Next J
 If J > t_I / 2 Then isprime = True
End Function
技术文章快速查找

栏目导航
软件应用
·操作系统 ·杀毒防黑 ·应用软件
·聊天软件 ·网络软件  
Web开发
·ASP ·JavaScript ·CGI
·JSP ·VbScript ·Web服务器
·PHP ·XML  
开发语言
·VB ·VC ·ASP.NET
·Java ·C/C++ ·Delphi
数据库开发
·MySQL ·SQL/Access ·PowerBuilder
·Oracle ·DB2  
网站设计
·Flash ·Dreamweaver ·HTML/CSS
·Fireworks ·FrontPage  
平面设计
·Photoshop ·CorelDraw ·AutoCAD
·FreeHand ·Illustrator ·3DsMAX
媒体动画
·Director ·Authorware ·Maya
·视频处理    


相关软件 产品库推荐
·笔记本 ·台式机 ·服务器
·数码相机 ·手机 ·GPS
·DV摄像机 ·MP3 ·MP4
·CPU ·硬盘 ·内存
·主板 ·显卡 ·显示器
·打印机 ·投影机 ·路由器

还没人留言,抢个先,哈哈!
对"Visual Basic上机考试综合应用题选讲"的评论 - 快速回贴
内容:
  [完成后可按Ctrl+Enter发布]

百度中 Visual Basic上机考试综合应用题选讲 相关内容
Google搜索中 Visual Basic上机考试综合应用题选讲 相关内容
雅虎中 Visual Basic上机考试综合应用题选讲 相关内容
Sogou搜索中 Visual Basic上机考试综合应用题选讲 相关内容

相关软件 最新回复帖子:

·没有mysql支持时的替代方案
·一个可以发送附件及HTML格式邮件的PHP类
·AutoCAD打造精致三维鸟笼实例详解
·Photoshop自定义水晶字特效样式
·AutoCAD三维基础实例教程
·PS为黑背景长发美女照片抠图换背
·用Photoshop自制个性摩托车贴花小经验
·轻松几步将美女照片处理为手工素描
·巧用Photoshop画笔轻松绘制创意特效
·用Photoshop通道将模糊肖像照片清晰化


  相关软件 Visual Basic上机考试综合应用题选讲相关文章
VB编程破解Windows屏幕保护密码 真没想到VB也可以这样用之指针技术
在VB6中用命令行为模式控制GUI动作 真没想到VB也可以这样用之VB能做什么
VB设计Win2000下截获IP数据包程序 用VB实现实时曲线的绘制和保存
适合Visual Basic初学者的10个小技巧 用Visual Basic设计手机短信收发程序
VB图像处理之图像的亮度对比度调整 VB实现文件数据对SQL Server上传下载
用VB6.0编写磁盘格式化程序 在VB6中实现Kodak控件编程
VB图像处理之图像的色彩纠正 VB图像处理之铅笔画算法和木雕算法
VB图像处理之几个常用滤镜的实现 VB图像处理之二次线性插值的应用
VB图像处理之像素的获取和输出 VB实现图像在数据库的存储与显示
在Visual Basic 6.0 中创建Word文档 Visual Basic 深度下潜之海蛇缠绕