Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

VB "Select Case" Syntax

Status
Not open for further replies.

Tobin1

Petroleum
Joined
Nov 9, 2007
Messages
176
Location
US
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 :-) .
Can anyone help me with this?

Thanks


Tobin Sparks
 
Check the help in the macro editor.

SW macro help said:
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
 
TheTick,

Thanks for your responce. I have been looking in all kinds of help files :-) . I'm sure I came across this one before. I hope I've applied it to the attached file. I think I've been here before :-) . I'm still missing something though.

Can anyone help?

Tobin Sparks
www.nov.com
 
 http://files.engineering.com/getfile.aspx?folder=a6e2ba2c-e63c-4a32-9a9a-8d4c52309ed8&file=Make_Note2.swp
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
 
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
 
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)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top