初级农业产品免税文:VB 计算总和

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 22:57:58
有8个TEXT
单击COMMAND 算出8个text的总和

但是8个TEXT中 不一定是数字
也有可能是英文 和 汉字
问题:英文不算 汉字中不及格=59 及格=60 中=70 良=80 优=90
用个方便的方法 把8个TEXT中的数字和汉字的总和显示到Label1上
方便~~~如果不方便 只要简洁一些 也可以~~ 高手帮忙啊

1:先定义1个HzDex过程
Private Function HzDex(MyIndex) As Integer
Select Case MyIndex
Case \"不及格\"
HzDex = 59
Case \"及格\"
HzDex = 60
Case \"中\"
HzDex = \"70\"
Case \"良\"
HzDex = \"80\"
Case \"优\"
HzDex = \"90\"
Case Else
HzDex = 0
End Select
If IsNumeric(MyIndex) Then
HzDex = MyIndex
End If
End Function

2:开始求和
Private Sub Command1_Click()
Dim T As Integer
T = HzDex(Text1(0).Text) + HzDex(Text1(1).Text) + HzDex(Text1(2).Text) + _
HzDex(Text1(3).Text) + HzDex(Text1(4).Text) + HzDex(Text1(5).Text) + _
HzDex(Text1(6).Text) + HzDex(Text1(7).Text)
Label1.Caption = T
End Sub

没太看懂你说的问题,英文不算分数?8个TEXT中的数字和汉字的总和什么意思?

Private Function getMark( mytxt ) as Integer
select case mytxt
case "不及格"
getMark = 59
case "及格"
getMark = 60
case "中"
getMark = 70
case "良"
getMark = 80
case "优"
getMark = 90
case else
getMark = 0
End Select
Private Sub cmdCount_Click()
Dim total as Integer
total = 0
If IsNumeric(text1.text) then
total = total + text1.text
Else
total = total + getMark(text1.text)
End If
If IsNumeric(text2.text) then
total = total + text2.text
Else
total = total + getMark(text2.text)
End If

If IsNumeric(text3.text) then
total = total + text3.text
Else
total = total + getMark(text3.text)
End If

If IsNumeric(text4.text) then
total = total + text4.text
Else
total = total + getMark(text4.text)
End If

If IsNumeric(text5.text) then
total = total + text5.text
Else
total = total + getMark(text5.text)
End If

If IsNumeric(text6.text) then
total = total + text6.text
Else
total = total + getMark(text6.text)
End If
If IsNumeric(text7.text) then
total = total + text7.text
Else
total = total + getMark(text7.text)
End If
If IsNumeric(text8.text) then
total = total + text8.text
Else
total = total + getMark(text8.text)
End If

label1.caption = "Total = " & total
End Sub
End Function

应该是这样吧。。。
试看吧!