谁能帮我看看这个vb代码错在什么地方

来源:百度知道 编辑:UC知道 时间:2024/06/07 09:52:54
Private Sub Command1_Click()
If Text1 <= 2000 Then Text2 = 0
Else: End If
If 2000 < Text1 <= 2500 Then Text2 = (Val(Text1) - 2000) * 0.05
Else: End If
If 2500 < Text1 <= 4000 Then Text2 = (Val(Text1) - 2500) * 0.1 + 25
Else: End If
If 4000 < Text1 <= 7000 Then Text2 = (Val(Text1) - 4000) * 0.15 + 175
Else: End If
If 7000 < Text1 <= 22000 Then Text2 = (Val(Text1) - 7000) * 0.2 + 575
Else: End If
If 22000 < Text1 <= 42000 Then Text2 = (Val(Text1) - 22000) * 0.25 + 5575
Else: End If
If 42000 < Text1 <= 62000 Then Text2 = (Val(Text1) - 42000) * 0.3 + 10575
Else: End If
If 62000 < Text1 <= 82000 Then Text2 = (Val(Text1) - 62000) * 0.35 + 16575
Else: End If
If 82000 < Text1 <= 102000 Then Text2 = (Val(Text1) - 7000) * 0.4 + 23575
Else: End If
If Text1 > 102000 Then Text2 = (Val(Text1) - 102000) * 0.45 + 31575
Else: End I

首先,你的语法不对..

VB中没有 if 0<x<10 的表达方法..
这种情况只能这样表达: if x>0 and x<10 then

然后,这种多条件时,可以使用Select语句,更合理一些:
Private Sub Command1_Click()
Dim money!

money = Val(Text1) '将文本框1的字符串.转换为数值,放到变量money中

Select Case money
Case Is <= 2000 '如果小于等于2000
text2 = 0
Case Is <= 2500 '如果小于等于2500
text2 = (money - 2000) * 0.05
'...添加更多条件
'...
Case Is <= 102000
text2 = (money - 7000) * 0.4 + 23575
Case Is > 102000
text2 = (money - 102000) * 0.45 + 31575
End Select

End Sub

2000 < Text1 <= 2500格式错,应为
Val(Text1)>2000 And Val(Text1)<=250
有这样的多分支选择结构么,改下
Private Sub Command1_Click()
Dim a As Double
a = Val(Text1)
Select Case a
Case Is <= 2000
Text2 = 0
Case Is <= 2500
Text2 = (a - 2000) * 0.05
Case Is <= 4000
Text2 = (a - 2500) * 0.1 + 25
Case Is &