Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Visual Basic's 'LIKE' Function in VBScript?

1,193 views
Skip to first unread message

Salty

unread,
Aug 10, 2001, 9:27:53 AM8/10/01
to
Hi All,
Is it true that VBScript has no support for the Like function
found in Visual Basic (you know the one that allows you to compare a string
agains wildcards like in dos [*, ?]) I've looked long and hard and have been
unable to find any mention of it in reference to VBScript.

Does anyone have a code to provide VBScript with this same functionality
(and would be willing to provide me a copy)

It would be greatly appreciated.

Salty.
Ps. It's been one of "those" days so if I'm completely of track here and
VBScript does support the Like function feel free to vent some of your anger
on me. :)


Nathan Ernst

unread,
Aug 10, 2001, 9:41:24 AM8/10/01
to
You're not completely off the wall - Like is NOT supported
in VBS. As to provide the same functionality, my brain is
also fried this morning, so hopefully someone else may
help...

Nathan Ernst

>.
>

Peter W Johnson

unread,
Aug 10, 2001, 11:06:30 AM8/10/01
to
This is what I use..
SQLQuery = "SELECT * FROM CUSTID WHERE CUSTID.FirstName like '%" & Forename
& "%'"

Peter


"Salty" <salt...@newmail.net> wrote in message
news:OaDhKBaIBHA.1948@tkmsftngp03...

DogWalker

unread,
Aug 10, 2001, 8:31:31 PM8/10/01
to
VBScript has Regular Expressions. Regular Expressions are powerful pattern
matchers.

"Salty" <salt...@newmail.net> wrote in message
news:OaDhKBaIBHA.1948@tkmsftngp03...

nicholas

unread,
Aug 11, 2001, 3:30:29 AM8/11/01
to
Why not use Instr?

On Fri, 10 Aug 2001 23:27:53 +1000, "Salty" <salt...@newmail.net>
wrote:

Jim Teeuwen

unread,
Aug 10, 2001, 11:18:30 AM8/10/01
to
SQL code is not really the same as vbscript, Peter.
nice try though :-)
----------------------------
Jim Teeuwen
www.defiance.nl
ma...@defiance.nl
---------------------------
"Peter W Johnson" <peter.w...@cwsthelena.sh> wrote in message
news:uxnty2aIBHA.1256@tkmsftngp05...

Nick Osdale-Popa

unread,
Aug 14, 2001, 5:11:40 PM8/14/01
to
This code is from Windows Script Host Programmer's Reference by Mr. Dino
Esposito. It can be downloaded directly from the Wrox website. IF the
practice of posting this code is discouraged, please let me know, I don't
want to be blamed for plagarism. [at least the reference is sited and I'm
not posting it as my own code :-) .]

MsgBox IsLike("config.sys", "c*.*") 'returns true

Function IsLike(strText, match)
Dim i, str, spec, temp, token, nPos

' Turn strings to lower case
str = LCase(strText)
spec = LCase(match)

' Split the various components of the match string
aInput = split(spec, "*") ' "c*.*m" becomes Array("c", ".", "m")

' Walk the array of specification sub-components
i = 0
For Each token In aInput

' The first token plays an important role: the file name must begin
' with a substring identical to the token.
If i = 0 Then
temp = Left(str, Len(token))

' Don't match...
If temp <> token Then
IsLike = False
Exit Function
End If

' Removes the leading substring before next step
str = Right(str, Len(str) - Len(token))
Else
temp = str

' For each asterisk we come accross, we chack that what remains of
' the filename contains the next token of the match string.
nPos = Instr(1, temp, token)

' Don't match...
If nPos = 0 Then
IsLike = False
Exit Function
End If

' Removes the leading substring before next step
str = Right(str, Len(str) - nPos + 1)
End If

i = i + 1
Next

IsLike = True
End Function


"Salty" <salt...@newmail.net> wrote in message
news:OaDhKBaIBHA.1948@tkmsftngp03...

Nick Osdale-Popa

unread,
Aug 14, 2001, 5:12:39 PM8/14/01
to

Nick Osdale-Popa

unread,
Aug 14, 2001, 5:13:00 PM8/14/01
to

Torgeir Bakken

unread,
Aug 14, 2001, 5:36:40 PM8/14/01
to

But posting the same article 3 times <can> get you some blame ;-)

Torgeir

Nick Osdale-Popa

unread,
Aug 14, 2001, 6:32:06 PM8/14/01
to
actually, I'm not sure how that happened!?!?
"Torgeir Bakken" <Torgeir.B...@hydro.com> wrote in message
news:3B7999E8...@hydro.com...

Patrick

unread,
Aug 15, 2001, 11:59:59 AM8/15/01
to
Often used in SQL--

"Salty" <salt...@newmail.net> wrote in message
news:OaDhKBaIBHA.1948@tkmsftngp03...
0 new messages