×
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

VB "Select Case" Syntax

VB "Select Case" Syntax

VB "Select Case" Syntax

(OP)
Howdy All,

I'm trying to set up a VB Select Case construct and seem to be missing something.
Attached is a SW Macro I've been trying to set-up. I think I'm close or way-off smile .
Can anyone help me with this?

Thanks

Tobin Sparks
www.nov.com

RE: VB "Select Case" Syntax

Check the help in the macro editor.

Quote (SW macro help):

Function Bonus(performance, salary)
    Select Case performance
        Case 1
            Bonus = salary * 0.1
        Case 2, 3
            Bonus = salary * 0.09
        Case 4 To 6
            Bonus = salary * 0.07
        Case Is > 8
            Bonus = 100
        Case Else
            Bonus = 0
    End Select
End Function

RE: VB "Select Case" Syntax

CODE

Case SelectOpt(0)
WTF?  Is SelectOpt an array?  Make it a simple long with possible values from 0 to 3.  Pass the long to your function and then Select Case will sort it out from there.  Then each Case statement should reflect what to do for each possible value.

Also, can't repeat values for Case statements (i.e. can't have two "Case 1" statements)

CODE

Dim SelectOpt as Long 'expected value range 0 to 3
If Len(TextBox1.Text) = 0 And Len(TextBox2.Text) = 0 Then SelectOpt=0
' TextBox1 only
If Len(TextBox1.Text) > 0 And Len(TextBox2.Text) = 0 Then SelectOpt=1 ' TextBox2 only
If Len(TextBox1.Text) = 0 And Len(TextBox2.Text) > 0 Then SelectOpt=2' TextBox1 & TextBox2
If Len(TextBox1.Text) > 0 And Len(TextBox2.Text) > 0 Then SelectOpt=3

CODE

Select Case SelectOpt
Case 0 ' NO Selected Options
    MsgBox ("No Text entered! "), vbInformation, "Make Note2"
Case 1 ' TextBox1 only
    Set AddNoteLines = swPart.InsertNote(Me.TextBox1)
Case 2 ' TextBox1 only
    Set AddNoteLines = swPart.InsertNote(Me.TextBox2)
Case 3 ' TextBox1 & TextBox2
    Set AddNoteLines = swPart.InsertNote(Me.TextBox1 & Me.TextBox2)
Case Else ' Catch all error
    MsgBox ("Unknown Error"), vbInformation, "Make Note2"
    
End Select

RE: VB "Select Case" Syntax

(OP)
TheTick

Thanks for your response AGAIN!

Yes I was trying to use "SelectOpt(3)" as an Array.
Do you know how I can make it work that way?
Maybe it's not the best way to go in this situation.

I really appreciate your help.

Tobin Sparks
www.nov.com

RE: VB "Select Case" Syntax

Use the first block of code to replace the code assigning True to each of your array values.  Note that I redefine SelectOp as a long.

P.S. you may want to add a space or carriage return when you concatenate the text boxes.

CODE

Set AddNoteLines = swPart.InsertNote(Me.TextBox1 & " " & Me.TextBox2)

RE: VB "Select Case" Syntax

(OP)
TheTick

Thank you very much for all your help!

 

Tobin Sparks
www.nov.com

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