手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>程序设计>VB>列表

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

来源:互联网 作者:west263.com 时间:2008-02-23
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

1 2 3 4 下一页

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


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

上一篇: 适合Visual Basic初学者的10个小技巧
下一篇: 用Visual Basic设计手机短信收发程序

1 2 3 4 下一页

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!