validate a procedure...?

  • the_Maven
  • Graduate
  • Graduate
  • the_Maven
  • Posts: 196

Post 3+ Months Ago

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:

Code: [ Select ]
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
  1. Option Explicit
  2. Dim value1 As Double
  3. Dim value2 As Double
  4. -------------------------------------
  5. Sub Midpoint(ByRef One As Double, ByRef Two As Double, ByRef Three As Double, ByRef Four As Double)
  6.   value1 = Val(One + Two) / 2
  7.   value2 = Val(Three + Four) / 2
  8.   Answer = value1 & " , " & value2
  9. End Sub
  10. -------------------------------------
  11. Sub Quadratic(ByRef value1 As Double, ByRef value2 As Double, ByRef One As Double, ByRef Two As Double, ByRef Three As Double)
  12.   value1 = (One * -1) + (Sqr((Two) ^ 2) - 4 * One * Three) / (2 * One)
  13.   value2 = (One * -1) - (Sqr((Two) ^ 2) - 4 * One * Three) / (2 * One)
  14.   Answer = value1 & " , " & value2
  15. End Sub
  16. -------------------------------------
  17. Sub SurfaceCylinder(ByRef One As Double, ByRef Two As Double)
  18.   If One <> "" And IsNumeric(One) Then
  19.   If Two <> "" And IsNumeric(Two) Then
  20.     Answer = 2 * Pi * One ^ (2 + ((2 * Pi * One) * Two))
  21.     Exit Sub
  22.   Else
  23.     MsgBox ("Please do not leave any fields blank."), vbInformation + vbOKOnly, "Missing Data"
  24.   End If
  25.   End If
  26. End Sub
  27. -------------------------------------
  28. Private Sub Solve_Click()
  29. Select Case Action.Caption
  30.   Case Is = "Surface Area of a Cylinder"
  31.     Call SurfaceCylinder(One, Two)
  32.   Case Is = "Midpoint Formula"
  33.     Call Midpoint(One, Two, Three, Four)
  34.   Case Is = "Quadratic Formula (-b +... , -b -...)"
  35.     Call Quadratic(value1, value2, One, Two, Three)
  36.   Case Else
  37.     MsgBox ("Please select a function to perform from the menu"), vbOKOnly, "No Function Chosen"
  38. End Select
  39. End Sub


I would appreciate any help or pointers on this. Thank you.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

email me the project zipped up and I'll have a look (i'm too lazy to remake it lol :D )
  • the_Maven
  • Graduate
  • Graduate
  • the_Maven
  • Posts: 196

Post 3+ Months Ago

I'll pm you and we can exchange the emails.
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

the_Maven wrote:
Code: [ Select ]
  If One <> "" And IsNumeric(One) Then
  If Two <> "" And IsNumeric(Two) Then
    Answer = 2 * Pi * One ^ (2 + ((2 * Pi * One) * Two))
  1.   If One <> "" And IsNumeric(One) Then
  2.   If Two <> "" And IsNumeric(Two) Then
  3.     Answer = 2 * Pi * One ^ (2 + ((2 * Pi * One) * Two))




cange these three lines to

Code: [ Select ]
  If Len(One) > 0 And IsNumeric(One) Then
  If Len(Two) > 0 And IsNumeric(Two) Then
    Answer = 2 * Pi * One * Two + 2 * Pi * One ^ 2
  1.   If Len(One) > 0 And IsNumeric(One) Then
  2.   If Len(Two) > 0 And IsNumeric(Two) Then
  3.     Answer = 2 * Pi * One * Two + 2 * Pi * One ^ 2


It didn't like your test for zero length string. And what is up with your cylinder surface area equation.......
  • the_Maven
  • Graduate
  • Graduate
  • the_Maven
  • Posts: 196

Post 3+ Months Ago

Quote:
It didn't like your test for zero length string. And what is up with your cylinder surface area equation.......


I tried using the Len() function and it still didnt work. as for the equation it is supposed to be set up that way. are there any more ideas i could try?

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 64 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.