Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case Statement

Status
Not open for further replies.

Phrodeaux

Mechanical
Dec 7, 2004
2
Currently, having problems with a case statement. Case 265 and Case 229 are not sending out the correct values. Do I need a Case to statement to correct this? Any and all help will be appreciated.

Sub LandDrill(ToolDiameter, Flutes, TolPlus, TolMinus, FluteStyle)
Select Case FluteStyle
Case 204
Select Case ToolDiameter
Case Is < 0.2499
TolPlus = 0.5 * ToolDiameter
TolMinus = 0.6 * ToolDiameter

Case Else
TolPlus = 0.55 * ToolDiameter
TolMinus = 0.6 * ToolDiameter
End Select
Case 212
Select Case ToolDiameter
Case Is < 0.2499
TolPlus = 0.5 * ToolDiameter
TolMinus = 0.6 * ToolDiameter

Case Else
TolPlus = 0.55 * ToolDiameter
TolMinus = 0.6 * ToolDiameter
End Select
Case 265
TolPlus = 0.66 * ToolDiameter
TolMinus = 0.74 * ToolDiameter
Case 229
TolPlus = 0.15 * ToolDiameter
TolMinus = 0.2 * ToolDiameter

Case Else
TolPlus = 0.55 * ToolDiameter
TolMinus = 0.6 * ToolDiameter


End Select
End Sub
 
Replies continue below

Recommended for you

What happens if you move those case statements up to the top of the function?
 
No luck on moving the 229 and 265 statement to the top. Pulls hair out
 
When you feed in 229 or 265, which section of code appears to be executed?

Perhaps you should ensure that the FluteStyle argument is either of type Integer or of type Long.
 
Is FluteStyle an integer? Is it part of an enumeration? Are you sure the value of 229 or 265 is being passed into the Sub? Can any other procedure change the value of FluteStyle (or any other variable used in LandDrill) before calling Sub LandDrill (I notice it is passed by ref - the default if not specified by val).

Two things I would try: put the case numbers in ascending order and eliminate the nested select case statements. I can't guarantee this will help, it's just what I'd try.

Code:
Sub LandDrill(ToolDiameter, Flutes, TolPlus, TolMinus, FluteStyle)
    Select Case FluteStyle
        Case 204
            If ToolDiameter < 0.2499
                TolPlus = 0.5 * ToolDiameter
            Else
                TolPlus = 0.55 * ToolDiameter
            End If
		    TolMinus = 0.6 * ToolDiameter

        Case 212
            If ToolDiameter < 0.2499
                TolPlus = 0.5 * ToolDiameter
            Else
                TolPlus = 0.55 * ToolDiameter
            End If
		    TolMinus = 0.6 * ToolDiameter

        Case 229
            TolPlus = 0.15 * ToolDiameter
            TolMinus = 0.2 * ToolDiameter

        Case 265
            TolPlus = 0.66 * ToolDiameter
            TolMinus = 0.74 * ToolDiameter

        Case Else
            TolPlus = 0.55 * ToolDiameter
            TolMinus = 0.6 * ToolDiameter
                
        End Select
End Sub
 
It may depend on which version of Excel you're using. I seem to recall that some older versions require that Select Case statements with numeric arguments need to be in numeric order, although that isn't the case now (XP)

Good Luck
johnwm
________________________________________________________
To get the best from these forums read faq731-376 before posting

UK steam enthusiasts:
 
I'd feed it a value, then step through the function in VB, looking at values. Does it work in the VB editor environment but not the spreadsheet?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor