該程序將要求用戶輸入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