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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with "instr"

Status
Not open for further replies.

Goalie3533

Programmer
Apr 14, 2004
53
0
0
US
I'm having a problem with an instr function contained within an if statement.
Here's the line of code giving me trouble:
-------------------
"If id = prodid(i) and not(instr(Prodname(i)),"RENEWAL")) then"
--------------------
For some reason, as long as my "id" is equal to "prodid(i)" then my data is passing into the if statement regardless of whether or not the "instr" portion is true or not.
Is there anything wrong with the way I've set up my instr function?

Thanks.

-Goalie35
 
I get -1 and 0

In VB "Not 1" is evaluated as True and can be very confusing when you first see it.
Wouldn't this mean that Not(InStr(Blah, blah2)) if the strings were exactly the same then Instr would return 1. Then Not 1 would be true. But what you really wanted was false because you are trying to say:
Logical Not of(Is blah2 in blah?)

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Basically, it is the same as

Response.Write(Not False)
Response.Write(Not True)
 
When you run this code as is, what do you get?
Code:
str1 = "Hello world!"
str2 = "Hello"

'This is not corect
If True And Not(InStr(str1, str2)) Then
    Response.Write "Not in string" ' This is incorrectly output
Else 
    Response.Write "Is in string"
End If


str2 = "not"

If True And Not(InStr(str1, str2)) Then
    Response.Write "Not in string" ' This is correctly output but it is a coincidence
Else 
    Response.Write "Is in string"
End If

str1 = "Hello world!"
str2 = "Hello"

'This is corect
If True And Not(InStr(str1, str2)>0) Then
    Response.Write "Not in string" ' This is correctly output
Else 
    Response.Write "Is in string"
End If


str2 = "not"

If True And Not(InStr(str1, str2)>0) Then
    Response.Write "Not in string" ' This is correctly output 
Else 
    Response.Write "Is in string"
End If

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
in the midst of this boolean debate

Code:
If (id = prodid(i) and instr(Ucase(Prodname(i))),"RENEWAL") = 0) then



[blue]" 'I refuse to prove that I exist,' says God, 'for proof denies faith, and without faith I am nothing.'
.............
'Oh dear,' says God, 'I hadn't thought of that,' and promptly vanishes in a puff of logic." [/blue]

<lights touch paper and retires>[bomb]


Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems

So long, and thanks for all the fish.
 
Wouldn't this mean that Not(InStr(Blah, blah2)) if the strings were exactly the same then Instr would return 1. Then Not 1 would be true. But what you really wanted was false because you are trying to say:
Logical Not of(Is blah2 in blah?)

The NOT operator isn't defined for boolean; the Not operator in VB is always bitwise.

It is also tricky because C and VB bools are different, so depending on the function call , you may receive different results.


There was a very similar discussion going on on egghead a few months back...

Check it out.

 
I get :
Not in stringNot in stringIs in stringNot in string

Gtg,
long meeting in 5 mins.


 
Have fun in your meeting. Better you than me. [tongue]

The bitwise probably explains it.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top