Example of Elsif needed to evaluate text variants

N

Nomey

Dear all,

I'm still busy evaluating strings. I want to evaluate these strings:

". "
" ."
", "
" " & vbCr
"." & vbCr
vbCr
vbTab
etcetera,

And then define an action for each possibility.

I wonder is an Elsif statement is a good way to do this. Maybe I can avoid many (nested) If's that way. Could someone give me an example of such a structure?

Best regards
Shirley
 
G

Greg Maxey

Perhaps as Select Case is what you need:


Sub ScratchMacro()
Dim pStr As String
pStr = "." & vbCr
Select Case pStr
Case ". "
MsgBox "What do you want to do with this string."
Case " ."
MsgBox "What do you want to do with this string."
Case ", "
MsgBox "What do you want to do with this string."
Case " " & vbCr
MsgBox "What do you want to do with this string."
Case "." & vbCr
MsgBox "What do you want to do with this string."
Case vbCr
MsgBox "What do you want to do with this string."
Case vbTab
MsgBox "What do you want to do with this string."
End Select
End Sub
 
H

Helmut Weber

Hi Shirley,

quite as Greg told you.

If you want the same action for a variaty of cases,
you'll arrive at the sample code I gave you lately,
like:

Case " .", ". ", ": " : action...

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
H

Helmut Weber

Dear Greg,

thx, got your mail about ranges, spelling errors etc.
Can't answer it in the usual way, yet,
and wouldn't know what to answer anyway.
I got a new machine running Vista with new software for mail
which is driving me crazy, up the walls, bananas, whatsoever.

I'd be happy to have all basic functions working.

At least, after some erroneous attempts
I'm able again to play chess at World Chess Life.







--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
N

Nomey

Thanx a bunch, Greg & Helmut.

I'll give it a try with case statements.

Best regards,
Shirley (away for a couple of days - your help is much appreciated though)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top