VB做 键盘输入一个数(任意实数),利用分段函数计算y=x2+3(x>0),y=-5x+x2(x
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/15 20:44:53
VB做 键盘输入一个数(任意实数),利用分段函数计算y=x2+3(x>0),y=-5x+x2(x
VB做 键盘输入一个数(任意实数),利用分段函数计算y=x2+3(x>0),y=-5x+x2(x
VB做 键盘输入一个数(任意实数),利用分段函数计算y=x2+3(x>0),y=-5x+x2(x
Private Sub Command1_Click()
i = Val(InputBox("input a number"))
If i 0 Then
y = x * 2 3
Else
y = -5 * x x * 2
End If
Print y
End Sub
Private Sub Form_Load()
Dim x,y As Double
x = InputBox("请输入实数","输入")
If x 0 Then
y = x ^ 2 3
Else
y = -5 * x x ^ 2
End If
MsgBox y
End Sub
Private Sub Command1_Click()
x = Val(InputBox("请输入一个实数","提示"))
If x 0 Then y = x ^ 2 3
If x = 0 Then y = -5 * x x ^ 2
Print "x = " x; " y = " y
End Sub
其实标题说是用分段函数,最佳就是用Select Case 语句
Sub GetValByAnyNumeric()
Dim X,Y As Double
X = Val(InputBox("请输入一个实数","提示","0"))
Select Case X
Case Is 0
Y = X ^ 2 3
Case Is = 0
Y = -5 * X X ^ 2
End Select
MsgBox "X = " X vbCrLf "Y = " Y
End Sub