validate a procedure...?

• the_Maven
• Joined: Feb 02, 2004
• Posts: 196
• Status: Offline

April 15th, 2004, 7:48 am

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
• Joined: 25 Feb 2008
• Posts: ?
• Loc: Ozzuland
• Status: Online

April 15th, 2004, 7:48 am

• rtm223
• Mastermind
• Joined: Mar 24, 2004
• Posts: 1855
• Loc: Uk
• Status: Offline

April 15th, 2004, 10:04 am

email me the project zipped up and I'll have a look (i'm too lazy to remake it lol )
CSS website design tutorials
• the_Maven
• Joined: Feb 02, 2004
• Posts: 196
• Status: Offline

April 16th, 2004, 6:48 am

I'll pm you and we can exchange the emails.
• rtm223
• Mastermind
• Joined: Mar 24, 2004
• Posts: 1855
• Loc: Uk
• Status: Offline

April 16th, 2004, 9:14 am

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.......
CSS website design tutorials
• the_Maven
• Joined: Feb 02, 2004
• Posts: 196
• Status: Offline

April 16th, 2004, 7:20 pm

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 188 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

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.