急!急!急!急!快考试了但是vb一点不会,有几个题目请专家给作一下,来者有分
题目1
输入6个学生的数学成绩,按不及格、60-70、71-99、100统计各个分数段的人数
题目2
机票优惠,某航空公司规定在7-9月份,如果订票数超过20张,则票价优惠15%;如果超过10张,则票价优惠5%;在1——5月份和11月份,如果订票数超过20张,则票价优惠25%,如果超过10张,则票价优惠15%。从输入对话框中输入票价、订票数及月份,用文本框显示出所需金额
题目3
从文本矿中输入你的三位号码,如果是“358”,在标签矿中输出一等奖信息;如果前两位是“35”,输出二等奖信息;如果前一为是”3“,输出三等奖信息;其余输出谢谢参与信息
问题点数:100、回复次数:19Top
1 楼ljhdi( )回复于 2005-06-04 12:04:46 得分 0
这种分不好拿啊Top
2 楼Zezese(蓝酷云)回复于 2005-06-04 12:10:40 得分 0
自己去看书
书上有的Top
3 楼iranjn(潘多拉)回复于 2005-06-04 12:13:06 得分 0
没时间了,也没有环境。帮帮忙吧Top
4 楼greentest(铜都铜业QQ:331338630)回复于 2005-06-04 12:18:05 得分 0
我来答你的第三个问题:
在窗体上新建一个文本框(text1),命令按钮(command1),在command1的click事件里输入以下代码:
if text1.text=358 then
msgbox("一等奖")
else if text1.text=35 then
msgbox("二等奖")
else if text1.text=3 then
msgbox("三等奖")
else
msgbox("谢谢参与")
end if
这是最基本的结构,如果要用字符比较方法就比较复杂些,也不难,没什么时间,就不写了Top
5 楼greentest(铜都铜业QQ:331338630)回复于 2005-06-04 12:19:36 得分 0
刚才理解错了,还是要用字符比较,嘿嘿,不好意思Top
6 楼iranjn(潘多拉)回复于 2005-06-04 12:45:41 得分 0
顶上去Top
7 楼gamestory(无叶菜)回复于 2005-06-04 13:11:01 得分 20
1、先用6个Text控件输入数学分数
Private Sub Command1_Click()
Dim nNo(5) As Integer
Dim nFS(5) As Integer
nFS(0) = Val(Text1.Text)
nFS(1) = Val(Text2.Text)
nFS(2) = Val(Text3.Text)
nFS(3) = Val(Text4.Text)
nFS(4) = Val(Text5.Text)
nFS(5) = Val(Text6.Text)
For i = 0 To 5
Select Case nFS(i)
Case 0 To 59
nNo(0) = nNo(0) + 1
Case 60 To 70
nNo(1) = nNo(1) + 1
Case 71 To 99
nNo(2) = nNo(2) + 1
Case 100
nNo(3) = nNo(3) + 1
Case Else
nNo(4) = nNo(4) + 1
End Select
Next i
MsgBox "不及格人数:" & Str(nNo(0)) & Chr(10) & _
"60-70:" & Str(nNo(1)) & Chr(10) & _
"71-99:" & Str(nNo(2)) & Chr(10) & _
"100:" & Str(nNo(3)) & Chr(10) & _
"错误分数:" & Str(nNo(4))
End SubTop
8 楼xinghesnake(星河)回复于 2005-06-04 13:16:11 得分 0
顶!Top
9 楼iranjn(潘多拉)回复于 2005-06-04 13:32:17 得分 0
.................Top
10 楼wea1978(川)回复于 2005-06-04 13:40:38 得分 0
第三个问题:
在窗体上新建一个文本框(text1),命令按钮(command1),在command1的click事件里输入以下代码:
if mid(trim(text1.text),1,3)=358 then
msgbox("一等奖")
elseif mid(trim(text1.text),1,2)=35 then
msgbox("二等奖")
elseif mid(trim(text1.text),1,1)=3 then
msgbox("三等奖")
else
msgbox("谢谢参与")
end ifTop
11 楼hzh_net(_风云_)回复于 2005-06-04 15:00:12 得分 30
题目2
机票优惠,某航空公司规定在7-9月份,如果订票数超过20张,则票价优惠15%;如果超过10张,则票价优惠5%;在1——5月份和11月份,如果订票数超过20张,则票价优惠25%,如果超过10张,则票价优惠15%。从输入对话框中输入票价、订票数及月份,用文本框显示出所需金额
Private Sub Command1_Click()
If Text3.Text > 12 Or Text3.Text < 1 Then
MsgBox "你输入的月份有误,请重新输入!", vbExclamation + vbOKOnly, "系统提示"
Text3.SetFocus
Exit Sub
End If
If Text3.Text >= 7 And Text3.Text <= 9 Then
If Val(Text2.Text) >= 20 Then
Text4.Text = Val(Text1.Text) * 0.85 * Val(Text2.Text)
Else
If Val(Text2.Text) >= 10 Then
Text4.Text = Val(Text1.Text) * 0.95 * Val(Text2.Text)
Else
If Val(Text2.Text) < 10 And Val(Text2.Text) >= 0 Then
Text4.Text = Val(Text1.Text) * 1 * Val(Text2.Text)
End If
End If
End If
Else
If Text3.Text >= 1 And Text3.Text <= 5 Or Text3.Text = 11 Then
If Val(Text2.Text) >= 20 Then
Text4.Text = Val(Text1.Text) * 0.75 * Val(Text2.Text)
Else
If Val(Text2.Text) >= 10 Then
Text4.Text = Val(Text1.Text) * 0.85 * Val(Text2.Text)
Else
If Val(Text2.Text) < 10 And Val(Text2.Text) >= 0 Then
Text4.Text = Val(Text1.Text) * 1 * Val(Text2.Text)
End If
End If
End If
Else
Text4.Text = Val(Text1.Text) * 1 * Val(Text2.Text)
End If
End If
End Sub
Private Sub Text1_Change()
If Text1.Text <> "" Then
If IsNumeric(Text1.Text) = False Then
Text1.Text = ""
Exit Sub
End If
End If
End Sub
Private Sub Text1_GotFocus()
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub
Private Sub Text2_Change()
If Text2.Text <> "" Then
If IsNumeric(Text2.Text) = False Then
Text2.Text = ""
Exit Sub
End If
End If
End Sub
Private Sub Text2_GotFocus()
Text2.SelStart = 0
Text2.SelLength = Len(Text2.Text)
End Sub
Private Sub Text3_Change()
If Text3.Text <> "" Then
If IsNumeric(Text3.Text) = False Then
Text3.Text = ""
Exit Sub
End If
If Text3.Text > 12 Or Text3.Text < 1 Then
MsgBox "你输入的月份有误,请重新输入!", vbExclamation + vbOKOnly, "系统提示"
Text3.SetFocus
Exit Sub
End If
End If
End Sub
Private Sub Text3_GotFocus()
Text3.SelStart = 0
Text3.SelLength = Len(Text3.Text)
Text3.MaxLength = 2
End Sub
----------------------------
其中
Text1 票价
Text2 订票数
Text3 月份
Text4 所需金额
Top
12 楼guixian310(夏至矽)回复于 2005-06-04 15:18:46 得分 30
第一题:
Dim a(6) As Integer '成绩输入数组
Dim b(6) As Integer '成绩取十位数组
Dim c(4) As Integer '成绩分组数组
Private Sub Form_Load()
For i = 0 To 5
a(i) = InputBox("请输入成绩", "成绩输入")
If a(i) > 100 Or a(i) < 0 Then
MsgBox "输入有误,请重新输入"
i = i - 1
End If
Next i
For j = 0 To 5
b(j) = Int(a(j) / 10)
Next j
For k = 0 To 5
Select Case b(k)
Case 0 To 5
c(0) = c(0) + 1
Case 6
c(1) = c(1) + 1
Case 7 To 9
c(2) = c(2) + 1
Case 10
c(3) = c(3) + 1
End Select
Next k
MsgBox "不及格人数:" & c(0) & Chr(10) & "60-70:" & c(1) & Chr(10) & _
"71-99:" & c(2) & Chr(10) & "100:" & c(3)
End Sub
第二题:
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer
Private Sub Form_Load()
a = InputBox("请输入机票单价")
b = InputBox("请输入订票数")
c = InputBox("请输入月份")
Select Case c
Case 7 To 9
If b > 20 Then
d = b * a * 0.85
ElseIf b > 10 Then
d = b * a * 0.95
End If
Case 1 To 5 And 11
If b > 20 Then
d = b * a * 0.75
ElseIf b > 10 Then
d = b * a * 0.85
End If
Case Else
d = b * a
End Select
Text1.Text = d
End Sub
第三题:
Private Sub Command1_Click()
If Trim(Text1.Text) = "358" Then
MsgBox ("一等奖")
ElseIf Mid(Trim(Text1.Text), 1, 2) = "35" Then
MsgBox ("二等奖")
ElseIf Left(Trim(Text1.Text), 1) = "3" Then
MsgBox ("三等奖")
Else
MsgBox ("谢谢参与")
End If
End Sub
回答完毕!
鼓掌!
谢谢!
Top
13 楼guixian310(夏至矽)回复于 2005-06-04 15:20:44 得分 0
看看我上面那位,让你知道什么是代码冗余!!!!!!Top
14 楼hzh_net(_风云_)回复于 2005-06-04 15:37:13 得分 0
to guixian310(夏至矽)
-----------------
你的
Select Case c
Case 7 To 9
If b > 20 Then
d = b * a * 0.85
ElseIf b > 10 Then
d = b * a * 0.95
End If
Case 1 To 5 And 11
If b > 20 Then
d = b * a * 0.75
ElseIf b > 10 Then
d = b * a * 0.85
End If
Case Else
d = b * a
End Select
中有错误啊
呵呵
如输入100,21,2 按你的代码=2100
而实际上是100*21*0.75=1575
哈哈
你精简了又有什么用?运行结果不准确?Top
15 楼bizshow(If (我想玩) then (我会死的很难看))回复于 2005-06-04 15:49:41 得分 20
我的代码更简短!
===================================
题目1:
在FORM上创建6个TEXT框名为STUDENT()
一个BUTTON名为StartTJ
代码:
---------------
Private Sub StartTJ_Click()
For i = 0 To 5
Select Case Student(i).Text
Case Is < 60
S1 = S1 + 1
Case 60 To 70
S2 = S2 + 1
Case 71 To 99
S3 = S3 + 1
Case 100
S4 = S4 + 1
End Select
Next
MsgBox "不及格(" & S1 & ") 60-70(" & S2 & ") 71-99(" & S3 & ") 100(" & S4 & ")"
End Sub
======================
题目2:
FORM上创建一个文本框TEXT1
代码:
--------------------
Private Sub Form_Load()
tmp = InputBox("请输入 票价、订票数及月份 ,用逗号隔开")
t1 = InStr(1, tmp, ",")
t2 = InStr(t1 + 1, tmp, ",")
tmp1 = Mid(tmp, 1, t1 - 1)
tmp2 = Mid(tmp, t1 + 1, t2 - t1 - 1)
tmp3 = Mid(tmp, t2 + 1)
total = tmp1 * tmp2
Select Case tmp3
Case 7 To 9
If tmp2 > 20 Then total = total - (total * 0.15)
If tmp2 > 10 And tmp2 <= 20 Then total = total - (total * 0.05)
Case 1 To 5, 11
If tmp2 > 20 Then total = total - (total * 0.25)
If tmp2 > 10 And tmp2 <= 20 Then total = total - (total * 0.15)
End Select
text1 = total
End Sub
============================
题目3:
创建TEXT1,LABEL1,Command1
代码:
-----------------------------
Private Sub Command1_Click()
Label1 = "谢谢参与"
If Left(Text1, 1) = 3 Then Label1 = "三等奖"
If Left(Text1, 2) = 35 Then Label1 = "二等奖"
If Text1 = 358 Then Label1 = "一等奖"
End Sub
==============================
回答完毕.
谢谢观看.Top
16 楼tkl1980()回复于 2005-06-04 15:51:36 得分 0
呵呵,只是小错误,难道你看不出问题在于Case 1 To 5 And 11上吗,改成Case 1 To 5 OR 11即可
全码如下:
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer
Private Sub Form_Load()
a = InputBox("请输入机票单价")
b = InputBox("请输入订票数")
c = InputBox("请输入月份")
Select Case c
Case 7 To 9
If b > 20 Then
d = b * a * 0.85
ElseIf b > 10 Then
d = b * a * 0.95
End If
Case 1 To 5 Or 11
If b > 20 Then
d = b * a * 0.75
ElseIf b > 10 Then
d = b * a * 0.85
End If
Case Else
d = b * a
End Select
Text1.Text = d
End Sub
呵呵,我觉得你是给外面的公司写代码写多了,程序长而全面,考虑情况充足,确实不错,可这是考试啊,抓住考点即可Top
17 楼vanyard(K)回复于 2005-06-04 15:52:18 得分 0
to guixian310(夏至矽)
应该把 Case 1 To 5 And 11 改成
Case 1 To 5 Or 11
这样就可以得到正确的数据了:)
不过你的代码的确比较精简~我要向你学习~Top
18 楼tkl1980()回复于 2005-06-04 15:54:31 得分 0
哈哈,(布丁心情) 的果然更简短!!!!Top
19 楼tkl1980()回复于 2005-06-04 15:57:21 得分 0
vanyard(K)呵呵,谢谢~~Top




