I wrote a program in visual basic 6 a while back, and I have everything working properly except for one thing:
I can't get if statements to work in a procedure. In the functions they work fine. Note: One, Two, Three, Four, and Answer are text boxes.
Here is the relevant code:
Option Explicit
Dim value1 As Double
Dim value2 As Double
-------------------------------------
Sub Midpoint(ByRef One As Double, ByRef Two As Double, ByRef Three As Double, ByRef Four As Double)
value1 = Val(One + Two) / 2
value2 = Val(Three + Four) / 2
Answer = value1 & " , " & value2
End Sub
-------------------------------------
Sub Quadratic(ByRef value1 As Double, ByRef value2 As Double, ByRef One As Double, ByRef Two As Double, ByRef Three As Double)
value1 = (One * -1) + (Sqr((Two) ^ 2) - 4 * One * Three) / (2 * One)
value2 = (One * -1) - (Sqr((Two) ^ 2) - 4 * One * Three) / (2 * One)
Answer = value1 & " , " & value2
End Sub
-------------------------------------
Sub SurfaceCylinder(ByRef One As Double, ByRef Two As Double)
If One <> "" And IsNumeric(One) Then
If Two <> "" And IsNumeric(Two) Then
Answer = 2 * Pi * One ^ (2 + ((2 * Pi * One) * Two))
Exit Sub
Else
MsgBox ("Please do not leave any fields blank."), vbInformation + vbOKOnly, "Missing Data"
End If
End If
End Sub
-------------------------------------
Private Sub Solve_Click()
Select Case Action.Caption
Case Is = "Surface Area of a Cylinder"
Call SurfaceCylinder(One, Two)
Case Is = "Midpoint Formula"
Call Midpoint(One, Two, Three, Four)
Case Is = "Quadratic Formula (-b +... , -b -...)"
Call Quadratic(value1, value2, One, Two, Three)
Case Else
MsgBox ("Please select a function to perform from the menu"), vbOKOnly, "No Function Chosen"
End Select
End Sub
- Option Explicit
- Dim value1 As Double
- Dim value2 As Double
- -------------------------------------
- Sub Midpoint(ByRef One As Double, ByRef Two As Double, ByRef Three As Double, ByRef Four As Double)
- value1 = Val(One + Two) / 2
- value2 = Val(Three + Four) / 2
- Answer = value1 & " , " & value2
- End Sub
- -------------------------------------
- Sub Quadratic(ByRef value1 As Double, ByRef value2 As Double, ByRef One As Double, ByRef Two As Double, ByRef Three As Double)
- value1 = (One * -1) + (Sqr((Two) ^ 2) - 4 * One * Three) / (2 * One)
- value2 = (One * -1) - (Sqr((Two) ^ 2) - 4 * One * Three) / (2 * One)
- Answer = value1 & " , " & value2
- End Sub
- -------------------------------------
- Sub SurfaceCylinder(ByRef One As Double, ByRef Two As Double)
- If One <> "" And IsNumeric(One) Then
- If Two <> "" And IsNumeric(Two) Then
- Answer = 2 * Pi * One ^ (2 + ((2 * Pi * One) * Two))
- Exit Sub
- Else
- MsgBox ("Please do not leave any fields blank."), vbInformation + vbOKOnly, "Missing Data"
- End If
- End If
- End Sub
- -------------------------------------
- Private Sub Solve_Click()
- Select Case Action.Caption
- Case Is = "Surface Area of a Cylinder"
- Call SurfaceCylinder(One, Two)
- Case Is = "Midpoint Formula"
- Call Midpoint(One, Two, Three, Four)
- Case Is = "Quadratic Formula (-b +... , -b -...)"
- Call Quadratic(value1, value2, One, Two, Three)
- Case Else
- MsgBox ("Please select a function to perform from the menu"), vbOKOnly, "No Function Chosen"
- End Select
- End Sub
I would appreciate any help or pointers on this. Thank you.