Can anyone help. I have my code below. We have to use GoTo, yeah I know, but I am needing my code to use the last x entered in to the input box (the correct one). Currently it is only using the first value in my calculation. We have to have it so that it continues to let the user choose until the user chooses in the given range. How can I correct?
Sub Calculation()
Dim i As Integer
Dim x As Variant
Dim error As Variant
Dim s0 As Double
Dim s1 As Double
Dim x1 As Variant
'Enter x in the range (0,2) as the formula is derived only for that interval
x = InputBox("Enter the value of x in the range (0,2)") 'lets user select x given the range
error = InputBox("Enter the value of Error in the range")
i = 2 'start of i
s0 = 0 'approximation of ln(x) which for the first i-1 terms
s1 = x - 1 'approximation of ln (x) for
'if user selects number outside of range, they will have to choose again
If x <= 0 Or x >= 2 Then GoTo XDirectionsNotFollowed Else GoTo Project3
XDirectionsNotFollowed:
Do Until InputBox("Enter the value of x in the range (0,2)") > 0 And InputBox("Enter the value of x in the range (0,2)") < 2
Loop
Project3:
Do While Abs(s1 - s0) > error
s0 = s1 'old becomes new
s1 = s1 + ((-1) ^ (i + 1)) * ((x - 1) ^ i) / i 'series computation
i = i + 1 'next i in series
Loop
'Customization
Application.Speech.Speak (s1)
Range("A1").Value = "User Value of x"
Range("A1").Interior.Color = vbRed
Range("B1").Value = x1
Range("A3").Value = "ln of x"
Range("A3").Interior.Color = vbRed
Range("B3").Value = "ln(x) = " & s0
Range("B3").NumberFormat = Number
Range("B3").NumberFormat = "0.0000000000000000"
Range("C1").Value = "User Error Value"
Range("C1").Interior.Color = vbRed
Range("D1").Value = error
Range("C3").Value = "Difference in Values"
Range("C3").Interior.Color = vbRed
Range("D3").Value = (Abs(s1 - s0))
Range("D3").NumberFormat = Number
Range("D3").NumberFormat = "0.0000000000000000"
Range("A:D").ColumnWidth = 30
End Sub
Sub Calculation()
Dim i As Integer
Dim x As Variant
Dim error As Variant
Dim s0 As Double
Dim s1 As Double
Dim x1 As Variant
'Enter x in the range (0,2) as the formula is derived only for that interval
x = InputBox("Enter the value of x in the range (0,2)") 'lets user select x given the range
error = InputBox("Enter the value of Error in the range")
i = 2 'start of i
s0 = 0 'approximation of ln(x) which for the first i-1 terms
s1 = x - 1 'approximation of ln (x) for
'if user selects number outside of range, they will have to choose again
If x <= 0 Or x >= 2 Then GoTo XDirectionsNotFollowed Else GoTo Project3
XDirectionsNotFollowed:
Do Until InputBox("Enter the value of x in the range (0,2)") > 0 And InputBox("Enter the value of x in the range (0,2)") < 2
Loop
Project3:
Do While Abs(s1 - s0) > error
s0 = s1 'old becomes new
s1 = s1 + ((-1) ^ (i + 1)) * ((x - 1) ^ i) / i 'series computation
i = i + 1 'next i in series
Loop
'Customization
Application.Speech.Speak (s1)
Range("A1").Value = "User Value of x"
Range("A1").Interior.Color = vbRed
Range("B1").Value = x1
Range("A3").Value = "ln of x"
Range("A3").Interior.Color = vbRed
Range("B3").Value = "ln(x) = " & s0
Range("B3").NumberFormat = Number
Range("B3").NumberFormat = "0.0000000000000000"
Range("C1").Value = "User Error Value"
Range("C1").Interior.Color = vbRed
Range("D1").Value = error
Range("C3").Value = "Difference in Values"
Range("C3").Interior.Color = vbRed
Range("D3").Value = (Abs(s1 - s0))
Range("D3").NumberFormat = Number
Range("D3").NumberFormat = "0.0000000000000000"
Range("A:D").ColumnWidth = 30
End Sub