find a "." then

  • Thread starter Thread starter Rivers
  • Start date Start date
R

Rivers

is there a way to search a variable containing "mydoc.doc" for the "." and if
found do the next line i tried

if sel=*.* then

but it doesnt work any ideas

thanks

Rivers
 
If Instr(yourstring, whatyouwanttosearch) > 0 Then

'code in case found

Else

'code in case not found

End if
 
try
If InStr(1, sel, ".", vbTextCompare) > 0 Then

you could also use the Like operator, which is closer to what you originally
tried:
If sel Like "*.*" Then

but the like operator depends on the Option Compare statement at the top of
the module (option compare binary is the default). Shouldn't make a
difference searching for period, but is something to keep in mind for the
future.
 
As Wigi posted, use the Instr function. However, there may be other ways to
accomplish this depending on what your next lines of code are. Can you tell
us what you are ultimately going to do if you find the "." in the text?

Rick
 
is there a way to search a variable containing "mydoc.doc" for the "." and if
found do the next line i tried

if sel=*.* then

but it doesnt work any ideas

thanks

Rivers

Try this:

Dim sel as String
If InStr(sel, ".")>0 Then
' this line is executed if there is a "." in the variable sel
End If

Hope this helps / Lars-Åke
 
wow that was fast

guys that worked brilliantly i have another question if your up for it?

how do i remove a section of a string to a point i.e "untitled.bitmap" to
"untitled" i want to look for the "." and delete it plus everything after it.

however the "." can appear multiple times within the string i just need to
delete the first segment i.e

"found.untitled.bitmap" ="found.untitled"

thanks

rivers
 
Did you mean delete the **last** section (that is what your example shows)?

TheText = "found.untitled.bitmap"
If InStr(TheText, ".") > 0 Then
TheNewText = Left(TheText, InStrRev(TheText, ".") - 1)
End If

Rick
 

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

Back
Top