VB编写程序,计算分段函数

2024-12-31 12:19:49
推荐回答(4个)
回答1:

在窗体上放一个命令按钮,将代码复制到窗体里,程序运行单击一次命令按钮可输入一次n的值
代码如下:

Private Sub Command1_Click()
Dim n, y As Single
n = InputBox(" 请输入N的值")
Select Case n
Case Is < 0
y = 2 * n + 5
Case 0
y = 0
Case Is > 0
y = 3 * n - 1
End Select
MsgBox "Y=" & y
End Sub

回答2:

看我的一行
Private Sub Command1_Click()
Dim n, y As Single
n = InputBox(" 请输入N的值")
y = Iif(x<0,2 * n + 5,Iif(x = 0,0,3 * n - 1))
MsgBox "Y=" & y
End Sub

回答3:

这位仁兄是个新手吧!别着急,慢慢来!加油!
dim
n,
y
as
integer
if
n
<
0
then
y
=
3
*
n
+
2
elseif
n
=
0
then
y
=
0
elseif
n
>
0
then
y
=
2
*
n
-
1
end
if

回答4:

Dim x As Integer
If x < 0 Then

ElseIf x >= 0 And x < 10 Then

ElseIf x >= 10 And x < 30 Then

ElseIf x >= 30 And x < 50 Then

Else

End If