• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

problem wit Instr function

If InStr(lbl1,lblCredit, "$") = True Then  this does not work
but this does;  If InStr(1, lblCredit, "$") Then
why?
0
isnoend2001
Asked:
isnoend2001
  • 4
  • 2
1 Solution
 
Martin LissOlder than dirtCommented:
In the first one did you mean

InStr(lbl1,lblCredit, "$") = True

or did you mean

InStr(1,lblCredit, "$") = True
0
 
Martin LissOlder than dirtCommented:
In any case InStr returns a position and since True is equal to -1, True will never be equal to the position.
0
 
isnoend2001Author Commented:
Whoops i meant
InStr(1,lblCredit, "$") = True does not work
this does
If InStr(1, lblCredit, "$") Then
using the = True causes it not to work
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Martin LissOlder than dirtCommented:
Let me restate what I said. In VB any non-zero value is 'True' but True itself is -1 so the position returned by InStr while non-zero and therefore True can never be = -1.
0
 
isnoend2001Author Commented:
thanks, learn something new everyday
0
 
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now