VB for循环分段函数

来源:百度知道 编辑:UC知道 时间:2024/06/07 16:53:20
y= x*x-1 x<0
x*x+1 0≤x<10
x+10 10≤x<20
x+20 x≥20

Private Sub Command1_Click()
Dim x As Single, y As Single, t As String

Do
t = InputBox("请输入数值x,输入非数值表示结束:")
If IsNumeric(t) = False Then Exit Sub
x = Val(t)
Select Case x
Case Is < 0: y = x * x - 1
Case Is < 10: y = x * x + 1
Case Is < 20: y = x + 10
Case Is >= 20: y = x + 20
End Select
Print y
Loop

End Sub

select case x
case is <0
y=x*x-1
case is <10
y=x*x+1
case is <20
y=x+10
case else
y=x+20
end select