该程序将要求用户输入4次,然后用3个不同的答案显示3个消息框。每个答案包含2个不同的数字(范围),但我无法运行它,因为我无法使用该函数。为什么这不起作用?我找不到任何解决方案
我的主要问题是功能。变量a,b,c,d将由用户提供,x将在程序开始时由我提供。我无法运行该程序,因为函数带有蓝线下划线。
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer
Function f(x As Double) As Double
f = (a * x^3) + (b * x^2) + (c * x) + d
Exit Function
End Function
Sub incremental()
Dim left As Double
Dim right As Double
Dim product As Double
Dim counter As Integer
counter = 0
left = -10
right = -9.7
product = 1
a = InputBox("Please provide a coefficient for x^3.", "title", 0)
b = InputBox("Please provide a coefficient for x^2.", "title", 0)
c = InputBox("Please provide a coefficient for x^1.", "title", 0)
d = InputBox("Please provide a coefficient for x^0.", "title", 0)
Do While product > 0
product = f(left) * f(right)
If product > 0 Then
left = right
right = left + 0.3
Else
If counter = 0 Then
MsgBox("Your approximate root is " & left & " and " & right & ".")
counter = counter + 1
product = 1
left = right
right = left + 0.3
ElseIf counter = 1 Then
MsgBox("Your approximate root is " & left & " and " & right & ".")
counter = counter + 1
product = 1
left = right
right = left + 0.3
Else : counter = 2
MsgBox("Your approximate root is " & left & " and " & right & ".")
counter = 3
End If
End If
Loop
End Sub
你的问题写得不好,或组织得不好。你的问题到底是什么? – Darrell 2014-08-27 18:48:30
你有一个错字“'hhht”。 – 2014-08-27 18:49:19
欢迎来到Stack Overflow。请参阅我们的文章[如何提出一个好问题](http://stackoverflow.com/help/how-to-ask)和[On-Topic Questions](http://stackoverflow.com/help/on-话题)。投入这些简短文件的时间将是值得的,因为通过遵循他们的建议,您可能会更快地得到更好的答案。要特别注意你的头衔 - 这个不能更模糊。 – JDB 2014-08-27 18:56:12