Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

InStr("PWD", Var) always = 1???????

Status
Not open for further replies.

MichaelRed

Programmer
Dec 22, 1999
8,410
US
What don't I understand here? (note - all of theis in the "immediate"/DeBug window in VB6.


PubSrch = "PWD"
PubTyp = "": ? PubTyp, InStr("PWD", PubType), Instr(PubSrch, PubTyp)
1 1
PubTyp = "W": ? PubTyp, InStr("PWD", PubType), Instr(PubSrch, PubTyp)
W 1 2
PubTyp = "P": ? PubTyp, InStr("PWD", PubType), Instr(PubSrch, PubTyp)
P 1 1
PubTyp = "D": ? PubTyp, InStr("PWD", PubType), Instr(PubSrch, PubTyp)
D 1 3
PubTyp = "Q": ? PubTyp, InStr("PWD", PubType), Instr(PubSrch, PubTyp)
Q 1 0

Why does the InStr("PWD" ....) ALWAYS return 1,
While InStr(Var, Var2) return the 'right answer?

MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
 
? instr(1,"PWD","D") 'returns 3
Arn't you supposed to put in the start position?

David Paulson


 
Are you using Option Explicit to enforce declaration and then declaring your variables like a good little programmer?

In the code above you are using PubType to compare in one instr and PubTyp in the other. PubType doesn't have a value set so will always = "" and give the result of 1.

By declaring your variables you find furfies like this quite quickly. You should normally declare them as strings not variants for size, speed and good practice.

PS... no, you don't have to declare the starting point in the instr as was suggested.

chat soon
Michael
 
Thanks, I need to go to remedial typing school -- and then learn how to read (my own typing?).



MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top