INSTR with 5 condition

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

INSTR with 5 condition

Post by sal21 »

I have:

dim STRINGA as string

i need to intecept into this strong 5 condition.

actually i use OR statment, similar:

if instr(STRINGA,"1") OR instr(STRINGA,"9")instr(STRINGA,"b") ... Ecc

Short solution?

Tks

User avatar
HansV
Administrator
Posts: 78531
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: INSTR with 5 condition

Post by HansV »

Five conditions isn't much, I'd simply write them out.
If you had many more, you could do something like this:

Code: Select all

Function Contains(STRINGA As String, CHARS As String) As Boolean
    Dim i As Long
    For i = 1 To Len(CHARS)
        If InStr(STRINGA, Mid(CHARS, i, 1)) Then
            Contains = True
            Exit Function
        End If
    Next i
End Function

Sub Test()
    Dim STRINGA As String
    STRINGA = "..."
    If Contains(STRINGA, "19bdgikqstwz=!@>") Then
        ' STRINGA contains at least one of the characters
    Else
        ' STRINGA contains none of the characters
    End If
End Sub
but for 5 characters that is overkill.
Best wishes,
Hans

snb
4StarLounger
Posts: 584
Joined: 14 Nov 2012, 16:06

Re: INSTR with 5 condition

Post by snb »

Code: Select all

Sub M_snb()
   MsgBox [sum(find(mid("abcde",row(1:5),1),"abzwqcdefghijkl"))>0]
End Sub

User avatar
HansV
Administrator
Posts: 78531
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: INSTR with 5 condition

Post by HansV »

Sal21 is working in VB6, as always, so an Excel formula will fail.
Best wishes,
Hans

User avatar
SpeakEasy
4StarLounger
Posts: 562
Joined: 27 Jun 2021, 10:46

Re: INSTR with 5 condition

Post by SpeakEasy »

Could always use a Regular Expression ...

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: INSTR with 5 condition

Post by sal21 »

SpeakEasy wrote:
23 Feb 2024, 15:01
Could always use a Regular Expression ...
Tks bro....
But never used

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: INSTR with 5 condition

Post by sal21 »

HansV wrote:
23 Feb 2024, 13:05
Five conditions isn't much, I'd simply write them out.
If you had many more, you could do something like this:

Code: Select all

Function Contains(STRINGA As String, CHARS As String) As Boolean
    Dim i As Long
    For i = 1 To Len(CHARS)
        If InStr(STRINGA, Mid(CHARS, i, 1)) Then
            Contains = True
            Exit Function
        End If
    Next i
End Function

Sub Test()
    Dim STRINGA As String
    STRINGA = "..."
    If Contains(STRINGA, "19bdgikqstwz=!@>") Then
        ' STRINGA contains at least one of the characters
    Else
        ' STRINGA contains none of the characters
    End If
End Sub
but for 5 characters that is overkill.
HUMMMMM....
But my really prob is...

i put the value of STRINGA in to a Access table via sql and ADO.

if i insert with:

..

COMUNE = Split(RIGA, ";")(1)
COMUNE=Ucase(COMUNE)
...
other values
...

SQL = "INSERT INTO SAM_COMUNI (ISTATEXT, CF, CAP, COMUNE, PRFX, AGG) VALUES ('" & ISTAT & "', '" & CF & "', '" & CAP & "','" & Replace(COMUNE, "'", "''") & "', '" & PRFX & "','" & Date & "')"
CON.Execute (SQL)

Sorry but in string i just have this:

001001;Agliè;;A074;10011;0124;Torino
Last edited by sal21 on 23 Feb 2024, 15:52, edited 1 time in total.

User avatar
HansV
Administrator
Posts: 78531
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: INSTR with 5 condition

Post by HansV »

My guess is that VB6 cannot handle Unicode characters. But perhaps someone else has a workaround.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: INSTR with 5 condition

Post by sal21 »

HansV wrote:
23 Feb 2024, 15:52
My guess is that VB6 cannot handle Unicode characters. But perhaps someone else has a workaround.
correct my post

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: INSTR with 5 condition

Post by sal21 »

sal21 wrote:
23 Feb 2024, 15:43
HansV wrote:
23 Feb 2024, 13:05
Five conditions isn't much, I'd simply write them out.
If you had many more, you could do something like this:

Code: Select all

Function Contains(STRINGA As String, CHARS As String) As Boolean
    Dim i As Long
    For i = 1 To Len(CHARS)
        If InStr(STRINGA, Mid(CHARS, i, 1)) Then
            Contains = True
            Exit Function
        End If
    Next i
End Function

Sub Test()
    Dim STRINGA As String
    STRINGA = "..."
    If Contains(STRINGA, "19bdgikqstwz=!@>") Then
        ' STRINGA contains at least one of the characters
    Else
        ' STRINGA contains none of the characters
    End If
End Sub
but for 5 characters that is overkill.
HUMMMMM....
But my really prob is...

i put the value of STRINGA in to a Access table via sql and ADO.

if i insert with:

..

COMUNE = Split(RIGA, ";")(1)
COMUNE=Ucase(COMUNE)
...
other values
...

SQL = "INSERT INTO SAM_COMUNI (ISTATEXT, CF, CAP, COMUNE, PRFX, AGG) VALUES ('" & ISTAT & "', '" & CF & "', '" & CAP & "','" & Replace(COMUNE, "'", "''") & "', '" & PRFX & "','" & Date & "')"
CON.Execute (SQL)

Sorry but in string i just have this:

001001;Agliè;;A074;10011;0124;Torino
is a result of API REST output

User avatar
HansV
Administrator
Posts: 78531
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: INSTR with 5 condition

Post by HansV »

I'm afraid I cannot help with that.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: INSTR with 5 condition

Post by sal21 »

HansV wrote:
23 Feb 2024, 16:01
I'm afraid I cannot help with that.
to share the solution...

i call the api with:

Set Request = CreateObject("WinHttp.WinHttpRequest.5.1")

change with:

Set Request = CreateObject("Microsoft.XMLHTTP")

and all work, perferct.


is a unicode prob, as you mentioned.

User avatar
HansV
Administrator
Posts: 78531
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: INSTR with 5 condition

Post by HansV »

Thanks for the update.
Best wishes,
Hans