find a string inside another string

  • Thread starter Thread starter MarkS
  • Start date Start date
M

MarkS

Hi,
this piece of code give a wrong answer
? Test
Dec 05 SFE NSW Base
if Strcomp(Test,"Feb") = true then ? "True" Else ? "Not"
True
if Strcomp(Test,"ASX") = true then ? "True" Else ? "Not"
Not

The word 'Feb' is not in the string but it returns a true
answer. If you try the word 'ASX' it returns false.

WHY and how do you fix it
Thanks MarkS
 
Hello MarkS,

StrComp does not returns boolean.
Try


Code:
--------------------

Debug.Print StrComp(Test, "Feb")

--------------------


The above code returns -1, True stands for -1 then printed "True".

In this case I would suggest you InStr function instead of StrComp
function as follows.


Code:
--------------------

If InStr(Test, "Feb") > 0 Then
Debug.Print "True"
Else
Debug.Print "Not"
End If

--------------------
 
Back
Top