求VB编程题答案.马上就要高一信息技术会考了~
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/11/05 21:43:39
求VB编程题答案.马上就要高一信息技术会考了~
1、随机产生10个两位整数,按由小到大顺序输出.
2、求N!=1*2*3…*N,N值由键盘输入.
3、输入某人年龄,输出其所属年龄段;18岁以下(不含18)为青少年;18---60为中青年;60岁以上(含60)为老年.
4、在文本框中任意输入两个数,单击“比较”按钮后,将其中的
最大值显示在下方标签中;单击“清除”按钮清除各项数值.
1、随机产生10个两位整数,按由小到大顺序输出.
2、求N!=1*2*3…*N,N值由键盘输入.
3、输入某人年龄,输出其所属年龄段;18岁以下(不含18)为青少年;18---60为中青年;60岁以上(含60)为老年.
4、在文本框中任意输入两个数,单击“比较”按钮后,将其中的
最大值显示在下方标签中;单击“清除”按钮清除各项数值.
第二题
Private Sub Command1_Click()
Dim a As Long
Dim s As Long
Dim i As Long
If Trim(Text1.Text) = "" Then
MsgBox "请填写N的值!", vbInformation, "-提 示-"
Exit Sub
ElseIf Trim(Text1.Text) = "0" Then
MsgBox "0不参于计算!", vbInformation, "-提 示-"
Exit Sub
Else
a = CLng(Trim(Text1.Text))
s = 1
For i = 1 To a
s = s * i
Next i
Text2.Text = Str(s)
End If
End Sub
第三题:
Private Sub Command1_Click()
If Trim(Text1.Text) = "" Then
MsgBox "请输入年龄", vbInformation, "-提 示-"
Text1.SetFocus
Exit Sub
Else
Dim a As Integer
a = CInt(Text1.Text)
Select Case a
Case Is < 18
Text2.Text = "青 年"
Case Is < 60
Text2.Text = "中青年"
Case Is >= 60
Text2.Text = "老 年"
End Select
End If
End Sub
第四题:
第四题:
Private Sub Command1_Click()
If Trim(Text1.Text) = "" Or Trim(Text2.Text) = "" Then
MsgBox "请填完整"
ElseIf CLng(Text1.Text) = CLng(Text2.Text) Then
Label1.Caption = "两数相等!"
ElseIf CLng(Text1.Text) > CLng(Text2.Text) Then
Label1.Caption = Text1.Text
Else
Label1.Caption = Text2.Text
End If
End Sub
Private Sub Command2_Click()
Text1.Text = "" And Text2.Text = ""
End Sub
第一题:见图/
Private Sub Command1_Click()
Dim a As Long
Dim s As Long
Dim i As Long
If Trim(Text1.Text) = "" Then
MsgBox "请填写N的值!", vbInformation, "-提 示-"
Exit Sub
ElseIf Trim(Text1.Text) = "0" Then
MsgBox "0不参于计算!", vbInformation, "-提 示-"
Exit Sub
Else
a = CLng(Trim(Text1.Text))
s = 1
For i = 1 To a
s = s * i
Next i
Text2.Text = Str(s)
End If
End Sub
第三题:
Private Sub Command1_Click()
If Trim(Text1.Text) = "" Then
MsgBox "请输入年龄", vbInformation, "-提 示-"
Text1.SetFocus
Exit Sub
Else
Dim a As Integer
a = CInt(Text1.Text)
Select Case a
Case Is < 18
Text2.Text = "青 年"
Case Is < 60
Text2.Text = "中青年"
Case Is >= 60
Text2.Text = "老 年"
End Select
End If
End Sub
第四题:
第四题:
Private Sub Command1_Click()
If Trim(Text1.Text) = "" Or Trim(Text2.Text) = "" Then
MsgBox "请填完整"
ElseIf CLng(Text1.Text) = CLng(Text2.Text) Then
Label1.Caption = "两数相等!"
ElseIf CLng(Text1.Text) > CLng(Text2.Text) Then
Label1.Caption = Text1.Text
Else
Label1.Caption = Text2.Text
End If
End Sub
Private Sub Command2_Click()
Text1.Text = "" And Text2.Text = ""
End Sub
第一题:见图/