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

instr()

Status
Not open for further replies.

patweb

Programmer
Apr 17, 2003
174
BE
Dim SUB as boolean
Dim DBS as boolean
Dim IDC as boolean
Dim TWB as boolean

I have string like
"[DBS][IDC][TWB]" or "[IDC][TWB]"
These string contains codes [...] but in a different sequence and some codes are in and others are not.

Do Until rst.EOF
strFRM = rst!PWDFRAME

I need to verify if a certain code is available in the string to determine the boolean value of a variable.
If e.g. the code TWB is available in the string the variabele TWB gets the value true or yes (boolean).

Can I with the function instr() or which other way check that a certain code is available in the string. In fact I need to loop the string because positions are not fixed, only the code is determined in advance.

pat.
 
Code:
If Instr(1,StringToSearch,"TWB") <> 0 Then
  BooleanVariable = True
Else
  BooleanVariable = False
End If

Using this logic, it doesn't matter where it finds the code, as long as it finds the code. If you need to check in a specific location within the string, that's a whole other story.

I am what I am based on the decisions I have made.

DoubleD [bigcheeks]
 
To further DoubleD's suggestion, using

[tt]dim lngPosition as long
lngPosition = Instr(StringToSearch,"TWB")[/tt]

Will give you the starting position of the substring, if that's needed (0 if it isn't within the string)

Or just

[tt]TWB = (Instr(StringToSearch,"TWB")>0)[/tt]

to assign the boolean.

Roy-Vidar
 
And the oneliner:
TWB = (InStr(strFRM, "[TWB]") > 0)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
nice ! it works but little syntasis problem remains in my SQL Statement

SUBDBS is a variable from the type boolean, how do I concatenate this in my SQL ? Below is NOK.

& "WHERE ((([T-LOOKUP-PAG].[SUP DBS]) = """ & SUBDBS
& """))

pat


 
It should be one of these two syntax, I'm not totally sure with the boolean.
"WHERE ([T-LOOKUP-PAG].[SUP DBS] = " & SUBDBS & ")"

"WHERE ([T-LOOKUP-PAG].[SUP DBS] = '" & SUBDBS & "')"


I am what I am based on the decisions I have made.

DoubleD [bigcheeks]
 
you wanted this ?
& "WHERE [T-LOOKUP-PAG].[SUP DBS] Like '*DBS*'"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top