vb问题,错哪儿,正确咋弄?

来源:百度知道 编辑:UC知道 时间:2024/05/22 12:43:01
Dim x As Single
x = InputBox("输入x", "计算分段函数的值")
If x <= 0 Then text1.Text = Str(0)
Else
If 0 < x < 1 Then text1.Text = Str(x ^ 0.5)
Else
If 1 <= x <= 3 Then text1.Text = Str(x ^ 2)
Else
text1.Text = Str(x + 3)
End Sub
第一个回答,没用啊1

Dim x As Single
x = Val(InputBox("输入x", "计算分段函数的值"))
If x < 0 Then Text1.Text = Str(0)
If x > 0 And x < 1 Then Text1.Text = Str(x ^ 0.5)
If x >= 1 And x <= 3 Then Text1.Text = Str(x ^ 2)
If x > 3 Then Text1.Text = Str(x + 3)

不能用0<x<1这种格式,它只计算前两个数即0<x
0<10<1=true
0>10>1=false
而且我觉得没必要用if elseif ...endif,因为你前边已经把实数x<=3的范围都包括了,换成这种会更直观

If x <= 0 Then
text1.Text = Str(0)
ElseIf x < 1 Then
text1.Text = Str(x ^ 0.5)
ElseIf x <= 3 Then
text1.Text = Str(x ^ 2)
Else
text1.Text = Str(x + 3)
End if

Dim x As Single
x = str(InputBox("输入x", "计算分段函数的)值")
If x <= 0 Then text1.Text = Str(0)
ElseIf x>0 and x<1 then
text1.Text = Str(x ^ 0.5)
ElseIf
x>=1 and x <= 3 Then
text1.Text = Str(x ^ 2)
Else
text1.Text = Str