View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Michael Bednarek[_3_] Michael Bednarek[_3_] is offline
external usenet poster
 
Posts: 18
Default help with Or statement

On Thu, 4 Sep 2003 10:15:32 -0400, "Bob C" wrote in
microsoft.public.excel.programming:

Can someone tell me how I can shorten the below "Or" statement without
repeating the entire string?

If (frmMaintest.CBox1.Text = "bob") Or (frmMaintest.CBox1.Text = "george")
Or (frmMaintest.CBox1.Text = "kevin") Then
MsgBox "You must select another name!"
Exit Sub
ElseIf (frmMaintest.CBox1.Text = "john") Or (frmMaintest.CBox1.Text = "tom")
Then
MsgBox "This name is acceptable!"
End If


Maybe I don't quite understand the problem, but to me the two obvious
ways of shortening the code (and make it faster, too), seem to be:

With frmMaintest.CBox1
If (.Text = "bob") Or (.Text = "george") _
Or (.Text = "kevin") Then
MsgBox "You must select another name!"
Exit Sub
ElseIf (.Text = "john") Or (.Text = "tom") Then
MsgBox "This name is acceptable!"
End If
End With

or

sTmp=frmMaintest.CBox1.Text
If (sTmp = "bob") Or (sTmp = "george") _
Or (sTmp = "kevin") Then
MsgBox "You must select another name!"
Exit Sub
ElseIf (sTmp = "john") Or (sTmp = "tom") Then
MsgBox "This name is acceptable!"
End If

--
Michael Bednarek, IT Manager, TGM Ltd, Brisbane, Australia
http://mcmbednarek.tripod.com/ "POST NO BILLS"