好文档 - 专业文书写作范文服务资料分享网站

(完整版)浙江省高校计算机等级考试复习资料——二级VB语言(答案)

天下 分享 时间: 加入收藏 我要投稿 点赞

4. 新建一个工程,完成“判断质数”应用程序的设计。具体要求如下: 参考答案:

Private Sub Command1_Click() Dim n As Integer, i As Integer n = Text1.Text For i = 2 To Sqr(n)

If n Mod i = 0 Then Exit For Next i

If i > Sqr(n) Then

Label2.Caption = Label2.Caption + \是质数\ Else

Label2.Caption = Label2.Caption + \不是质数\ End If End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0

MsgBox(\输入的不是数字, 无法计算\ End If End Sub

5. 新建一个工程,完成“计算平均成绩”应用程序的设计。具体要求如下: 参考答案:

Private Sub Text1_Change()

Text4.Text = Str((Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text)) / 3) End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0

n = MsgBox(\输入的不是数字, 无法计算\ End If End Sub

Private Sub Text2_Change()

Text4.Text = Str((Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text)) / 3) End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer) If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0

n = MsgBox(\输入的不是数字, 无法计算\ End If End Sub

Private Sub Text3_Change()

Text4.Text = Str((Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text)) / 3) End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer) If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0

n = MsgBox(\输入的不是数字, 无法计算\ End If End Sub

Private Sub Text4_Change() Text4.Locked = True End Sub

6. 新建一个工程,完成“收款计算”程序的设计。具体要求如下: 参考答案:

Private Sub Command1_Click() Text1.Text = \Text2.Text = \Text3.Text = \Text1.setfocus End Sub

Private Sub Command2_Click()

Text3.Text = Str(Val(Text1.Text) * Val(Text2.Text)) End Sub

7. 新建一个工程,完成“编辑”程序的设计。具体要求如下: 参考答案:

Private Sub Command1_Click() '将文本框选中的内容复制到剪粘板中 Clipboard.SetText Text1.SelText End Sub

Private Sub Command2_Click()

Clipboard.SetText Text1.SelText Text1.SelText = \End Sub

Private Sub Command3_Click()

Text1.SelText = Clipboard.GetText() '将要粘贴的内容复制到光标所在处 End Sub

Private Sub Command4_Click() '删除 Text1.seltext=”” End Sub

Private Sub Form_Load() Form1.Caption = \编辑\ Form1.BorderStyle = 1 Command1.Caption = \复制\ Command2.Caption = \剪切\ Command3.Caption = \粘贴\ Command4.Caption = \删除\End Sub

8. 新建一个工程,完成“密码检验”程序的设计。具体要求如下: 参考答案:

Private Sub Command1_Click() End End Sub

Private Sub Form_Load() Label2.Visible = False Label2.AutoSize = True Text1.PasswordChar = \End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer) Static times As Integer '统计第几次输入密码 ' 按回车键后进行密码检验 If KeyAscii = 13 Then

If Text1.Text = \ Label2.Caption = \欢迎光临!\ Label2.Visible = True Else

If times < 2 Then

Label2.Caption = \密码不符,请再输入一遍!\ Label2.Visible = True Text1.Text = \ Else

Label2.Caption = \非法用户,请退出程序!\ Text1.Text = \

Text1.Enabled = False End If End If

times = times + 1 End If End Sub

9. 新建一个工程,完成应用程序的设计。具体要求如下: 参考答案:

Private Sub Command1_Click()

If Text1.Text = Text2.Text And Text1.Text = \If Text3.Text = Text4.Text And Text3.Text <> \MsgBox (\密码修改成功\Else

MsgBox (\请重新输入新密码\End If Else

MsgBox (\请重新输入用户名或密码\End If End Sub

Private Sub Command2_Click() End End Sub

Private Sub Form_Load() Text1.TabIndex = 0 Text2.TabIndex = 1 Text3.TabIndex = 2 Text4.TabIndex = 3

Command1.TabIndex = 4 Command2.TabIndex = 5 End Sub

10. 新建一个工程,完成应用程序的设计。具体要求如下: 参考答案:

Private Sub Command1_Click() Dim ss As String

For i = 1 To Len(aa(Text1.Text)) ss = aa(Text1.Text) Print Mid(ss, i, 1) Next i

Command1.Enabled = False

End Sub

Private Sub Command2_Click() End End Sub

Function aa(ss As String) As String Dim x() As Integer Dim temp As Integer ReDim x(Len(ss)) For i = 1 To Len(ss) x(i) = Asc(Mid(ss, i, 1)) Next i

For i = 1 To Len(ss) For j = 1 To Len(ss) If x(i) < x(j) Then temp = x(i) x(i) = x(j) x(j) = temp End If Next j Next i

For i = 1 To Len(ss) aa = aa & Chr(x(i)) Next i

End Function

11. 新建一个工程,完成“替换”程序的设计。具体要求如下: 参考答案:

Private Sub command1_Click() ' 查找替换文本 Dim i%, len1%, len2% Dim findstr As String findstr = Text2.Text

findstrlen = Len(findstr) ' 待查文本长度 text1len = Len(Text1.Text) ' 文本长度 For i = 1 To text1len

If InStr(Text1.Text, findstr) Then start = InStr(Text1.Text, findstr) Text1.SetFocus

Text1.SelStart = start - 1 Text1.SelLength = findstrlen

Text1.SelText = Text3.Text ' 替换文本 End If Next i End Sub

(完整版)浙江省高校计算机等级考试复习资料——二级VB语言(答案)

4.新建一个工程,完成“判断质数”应用程序的设计。具体要求如下:参考答案:PrivateSubCommand1_Click()DimnAsInteger,iAsIntegern=Text1.TextFori=2ToSqr(n)IfnModi=0ThenExitForNext
推荐度:
点击下载文档文档为doc格式
4jk4h6dwqg5s23r4b01m9s4tl8lgrm00e4h
领取福利

微信扫码领取福利

微信扫码分享