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
INSTR with 5 condition
-
- Administrator
- Posts: 78788
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: INSTR with 5 condition
Five conditions isn't much, I'd simply write them out.
If you had many more, you could do something like this:
but for 5 characters that is overkill.
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
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 596
- Joined: 14 Nov 2012, 16:06
Re: INSTR with 5 condition
Code: Select all
Sub M_snb()
MsgBox [sum(find(mid("abcde",row(1:5),1),"abzwqcdefghijkl"))>0]
End Sub
-
- Administrator
- Posts: 78788
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: INSTR with 5 condition
Sal21 is working in VB6, as always, so an Excel formula will fail.
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 593
- Joined: 27 Jun 2021, 10:46
Re: INSTR with 5 condition
Could always use a Regular Expression ...
-
- PlatinumLounger
- Posts: 4402
- Joined: 26 Apr 2010, 17:36
-
- PlatinumLounger
- Posts: 4402
- Joined: 26 Apr 2010, 17:36
Re: INSTR with 5 condition
HUMMMMM....HansV wrote: ↑23 Feb 2024, 13:05Five conditions isn't much, I'd simply write them out.
If you had many more, you could do something like this:
but for 5 characters that is overkill.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 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.
-
- Administrator
- Posts: 78788
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: INSTR with 5 condition
My guess is that VB6 cannot handle Unicode characters. But perhaps someone else has a workaround.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4402
- Joined: 26 Apr 2010, 17:36
-
- PlatinumLounger
- Posts: 4402
- Joined: 26 Apr 2010, 17:36
Re: INSTR with 5 condition
is a result of API REST outputsal21 wrote: ↑23 Feb 2024, 15:43HUMMMMM....HansV wrote: ↑23 Feb 2024, 13:05Five conditions isn't much, I'd simply write them out.
If you had many more, you could do something like this:
but for 5 characters that is overkill.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 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
-
- Administrator
- Posts: 78788
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- PlatinumLounger
- Posts: 4402
- Joined: 26 Apr 2010, 17:36
-
- Administrator
- Posts: 78788
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands