主题:[讨论]请问各位高手,怎样用vb标准模块中的sub过程实现多因变量的输出
请问各位高手,怎样用vb标准模块中的sub过程实现多因变量的输出
例如解方程 x^2 - 3x + 2 = 0, x1 = 1, x2 = 2
在vb标准模块窗口中写入解方程的过程:
Public Sub Solve12(ByVal a As Single, ByVal b As Single, ByVal c As Single, ByVal x1 As Single, ByVal x2 As Single)
Dim delta As Single
delta = b * b - 4 * a * c
If delta >= 0 Then
x1 = (-b - Sqr(delta)) / 2 / a
x2 = (-b + Sqr(delta)) / 2 / a
End If
End Sub
在vb工程代码窗口中写入代码:
Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single
a = 1
b = -3
c = 2
Solve12 a, b, c, x1, x2
Me.Print x1
Me.Print x2
End Sub
但是运行后在窗体上没有打印出结果。请各位高手指点,多谢。
例如解方程 x^2 - 3x + 2 = 0, x1 = 1, x2 = 2
在vb标准模块窗口中写入解方程的过程:
Public Sub Solve12(ByVal a As Single, ByVal b As Single, ByVal c As Single, ByVal x1 As Single, ByVal x2 As Single)
Dim delta As Single
delta = b * b - 4 * a * c
If delta >= 0 Then
x1 = (-b - Sqr(delta)) / 2 / a
x2 = (-b + Sqr(delta)) / 2 / a
End If
End Sub
在vb工程代码窗口中写入代码:
Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single
a = 1
b = -3
c = 2
Solve12 a, b, c, x1, x2
Me.Print x1
Me.Print x2
End Sub
但是运行后在窗体上没有打印出结果。请各位高手指点,多谢。