search a string for a few strings in one go

Happy YN

Registered User.
Local time
Today, 09:50
Joined
Jan 27, 2002
Messages
425
I have a string which can contain an arithmetic operator e.g amount*exrate.
I want to be able to search the string for any of the operators i.e +,-,*,/. Is there any way I can use the instr function for this i.e
instr(string,"+" or "-" or "*" or "/") rather than nest a few if functions

Also is there any function which returns a boolean if a string is contained within another or do I have to use if instr(.......)>0 then...etc
Thanks
 
G’day Happy NY.

For the second question: -

Code:
Option Compare Database
Option Explicit


Sub Test()

    [color=green]' Please be careful with this...
    ' In the English version it will return 'True'
    ' but in the Dutch version it [b]might[/b] return 'Waar'[/color]
    MsgBox CBool(InStr(1, "Testit", "sT", vbTextCompare))

End Sub
I’ll have to have a look at the first question when I get a chance.

Hope that is some partial help.

Regards,
Chris.
 
Code:
Option Explicit
Option Compare Database [color=green]' Done for a reason on this occasion.[/color]


Sub Test()
    Dim strSearchOn As String
    
    [color=green]' Again please be careful with the next string.
    ' Limited testing indicates that we should not move
    ' the position of the '/' within the Search string.[/color]
    strSearchOn = "+-/*"
    
    If "Testit/Fred" Like "*[" & strSearchOn & "]*" Then
        MsgBox "True"
    Else
        MsgBox "False"
    End If

End Sub
Hope that helps.

Regards,
Chris.
 
Yes that helps alot thanks
Why did you use compare database and how can I use this in one subroutine only?
Also could I make a public function out of this?
Thanks
 
Now we have to be very specific about this.

“Also could I make a public function out of this?”

Which procedure would you like to make a Public Function and what would you like returned from that Public Function?
 
Like this?: -

Code:
Option Explicit
Option Compare Database


Sub Test()

    MsgBox SearchOn("Testit/Fred", "+-/*")

End Sub


Public Function SearchOn(ByVal strSearchString As String, _
                         ByVal strSearchOn As String) As Boolean

    SearchOn = (strSearchString Like "*[" & strSearchOn & "]*")

End Function
 
Yes thats excellent thanks
You didn't answer re the compare database bit though
thanks again
 
More work needed…

You didn't answer re the compare database bit though

We don’t need no education.
We don’t need no thought control.
No dark sarcasm in the classroom.
Teacher, leave those kids alone.
Hey, teacher, leave those kids alone!
All in all it’s just another brick in the wall.
All in all you’re just another brick in the wall.

Care to re-phrase the question/statement?
 

Attachments

Users who are viewing this thread

Back
Top Bottom