LIKE keyword in VB6

2019-05-30 08:28发布

问题:

I saw an example code as below

If numb Like "[0-9]" Then
End If

Here numb is a string holding one character.

What is the LIKE keyword in VB6? Is there any documentation available?

回答1:

Like Operator (Visual Basic for Applications Reference)

Used to compare two strings.

Syntax:

result = string Like pattern


回答2:

To have "Like" comparing the string "ABC", you must use * to mean "0 or any number of".

E.g: "ABC" Like "[A-Z]" results FALSE because "ABC" is not a 1-char long string, but "ABC" Like "*[A-Z]" returns TRUE because "ABC" has many chars in A-Z range

Cheers... Jorge



回答3:

Examples:

"G??" Like "God"

To find sentences that must have 3 characters start with capital G

"Prophet Muhammad (PBUH)" Like "Prophet*"

To find sentences with any length but start with Prophet

"*Islam*" Like "The only logical religion is Islam but they are adding rumors to it"

To find sentences with any length that contains Islam

"##days" Like "40days"

To find sentences that must have 6 characters and must start with 2 numbers and must end with days

"Only[01234][34]DaysDon'tDoSinThenYou'llSeeTheReality" Like "Only40DaysDon'tDoSinThenYou'llSeeTheReality"

Everything inside [ ] means: OR

0 OR 1 OR 2 OR 3 OR 4

3 OR 4

If you input one of them in the exact location. it returns true

In the following example, I must use the pattern otherwise I'll get error while typing:

Private Sub Text2_Change()

With Text2
    If .Text Like "*/*/####" Then
        .ToolTipText = DATE_TOOLTIP_ADDED(.Text)
    End If
End With

End Sub



标签: vb6 keyword