×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Case Statement

Case Statement

Case Statement

(OP)
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

RE: Case Statement

What happens if you move those case statements up to the top of the function?

RE: Case Statement

(OP)
No luck on moving the 229 and 265 statement to the top. Pulls hair out

RE: Case Statement

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.

RE: Case Statement

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

RE: Case Statement

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: www.essexsteam.co.uk

RE: Case Statement

Nice pun, johnwm.

RE: Case Statement

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?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources