InStr

  • Thread starter Thread starter gr
  • Start date Start date
G

gr

Hello, something I'm doing wrong in the followig statement:

intInString = VBA.InStr(aAvailable(inty),
strRowSourceSelected)

intInString returns always 0 even when ther's a matching
string.

Thank you
 
Hello, I find out that InStr only works when the second
string is of length 1 - it only searches the first
character -
is there any equivalent that searches the whole word?

i Want to know if a string is already contained in another
example:

strSearchIn = "Hello;GoodBye;Hola;Adios;Gruzi;Tschus"
strSearchFor = "Adios"

I want to get a True or something to tell me that "Adios"
is on strSearchIn and a False to tell me that "Ciao" is
not int strSearchIn.

Any ideas?
 
Hello, I find out that InStr only works when the second
string is of length 1 - it only searches the first
character -
is there any equivalent that searches the whole word?

You are incorrect, The "string to be found" can be any length. Try this
in the debug window...

?InStr(1,"This is the string to search","the") <Enter>

The result is 9.
 
Hello, I find out that InStr only works when the second
string is of length 1 - it only searches the first
character -
is there any equivalent that searches the whole word?
Not True! InStr() searches the entire string from the first character
to the end, unless you specifically tell it to search from a different
start point.
See VBA Help for all the InStr() arguments.
i Want to know if a string is already contained in another
example:

strSearchIn = "Hello;GoodBye;Hola;Adios;Gruzi;Tschus"
strSearchFor = "Adios"

I want to get a True or something to tell me that "Adios"
is on strSearchIn and a False to tell me that "Ciao" is
not int strSearchIn.

Any ideas?

Dim intX as Integer
Dim strSearchIn as String
strSearchIn = "Hello;GoodBye;Hola;Adios;Gruzi;Tschus"
intX = InStr(strSearchIn,"Adios")
If intX = 0 then
MsgBox "Not in string"
Else
MsgBox "In string"
End If
 
ok, I thought that was the problem.
if I type the string in the immediate window works. But
not while code execution. Could it be because I'm using an
array as the strSearchFor??
The syntax i'm using:
varPos = InStr(aAvailable(inty), strRowSource)
thx
 
gr said:
Hello, something I'm doing wrong in the followig statement:

intInString = VBA.InStr(aAvailable(inty),
strRowSourceSelected)

intInString returns always 0 even when ther's a matching
string.

Thank you

I suggest you try dumping the parameter values to the Immediate Window
to see what's happening:

Debug.Print "available", aAvailable(inty)
Debug.Print "rowsource", strRowSourceSelected
intInString = VBA.InStr(aAvailable(inty), strRowSourceSelected)
Debug.Print intInString

You may find that the values aren't what you think they are.
 
But he's passing aAvailable(inty), so in other words it is just a string,
not an array.
 
Back
Top