1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| Public Function VerifReqt(Req As String) As String
'pour mettre entre [ et ] un nom de colonne ou un nom de table contenant un caractére engendrant une erreur, ICI le / et ~ (a complèté)
Dim Deb As Integer, Pos As Integer
Dim Cpt As Integer
Dim NotCara(2) As String * 1
Dim MsgTemp As String
On Error GoTo GestErr
NotCara(0) = "/": NotCara(1) = "~": NotCara(2) = "'"
VerifReqt = Req
For Cpt = 0 To UBound(NotCara)
Pos = 1: MsgTemp = ""
If InStr(Pos, Req, NotCara(Cpt)) <> 0 Then
Do
Deb = -1
Pos = InStr(Pos, Req, NotCara(Cpt))
DoEvents
Select Case Pos
Case 0: Exit Do 'le caractère spécial n'est pas contenu dans la phrase
Case 1
' MsgTemp = "le caractère spécial débute le mot et ce mot débute la phrase"
Deb = 1: MsgTemp = RecupMotDebute(Req, Deb, Len(Req))
Pos = Fin
Case Is > 1
If Mid(Req, Pos - 1, 1) = " " Then
'MsgTemp = "le caractère spécial débute le mot mais pas la phrase"
Deb = Pos: MsgTemp = RecupMotDebute(Req, Deb, Len(Req))
Pos = Fin
Else
If Pos = Len(Req) Then
'MsgTemp = "le caractère spécial finit le mot et la phrase"
Deb = 1: MsgTemp = RecupMotFinit(Req, Deb, Len(Req))
Pos = Fin
Else
If Mid(Req, Pos + 1, 1) = " " Or Mid(Req, Pos + 1, 1) = "," Then
'MsgTemp = "le caractère spécial finit le mot mais pas la phrase"
Deb = 1: MsgTemp = RecupMotFinit(Req, Deb, Pos)
Pos = Pos + 1
Else
'MsgTemp = "le caractère spécial est contenu dans le mot"
MsgTemp = RecupleMot(Req, Pos)
Pos = Fin
End If
End If
End If
End Select
Req = Replace(Req, MsgTemp, "[" & MsgTemp & "]")
Req = Replace(Req, "[[", "[")
Req = Replace(Req, "]]", "]")
Loop
End If
Next Cpt
Req = Replace(Req, "[[", "[")
Req = Replace(Req, "]]", "]")
VerifReqt = Req
Exit Function
GestErr:
VerifReqt = "False"
End Function
Private Function RecupMotDebute(Reqt As String, Db As Integer, Fi As Integer) As String
Dim Cpt0
For Cpt0 = Db To Fi
If Mid(Reqt, Cpt0, 1) = " " Or Mid(Reqt, Cpt0, 1) = "," Then
RecupMotDebute = Mid(Reqt, Db, Cpt0 - Db): Exit For
End If
Next Cpt0
If RecupMotDebute = "" Then RecupMotDebute = Mid(Reqt, Db, Len(Reqt) - (Db - 1))
Fin = Db + Len(RecupMotDebute) + 1
End Function
Private Function RecupMotFinit(Reqt As String, Db As Integer, Fi As Integer) As String
Dim Cpt0
For Cpt0 = Fi To Db Step -1
If Mid(Reqt, Cpt0, 1) = " " Or Mid(Reqt, Cpt0, 1) = "," Then
RecupMotFinit = Mid(Reqt, Cpt0 + 1, Fi - Cpt0): Exit For
End If
Next Cpt0
If RecupMotFinit = "" Then RecupMotFinit = Mid(Reqt, Db, Fi - (Db - 1))
Fin = Len(Reqt) + 1
End Function
Private Function RecupleMot(Reqt As String, Posi As Integer) As String
Dim Cpt0
Dim MotGauche As String, MotDroite As String
'<---< remonte la phrase
For Cpt0 = Posi To 1 Step -1
If Mid(Reqt, Cpt0, 1) = " " Or Mid(Reqt, Cpt0, 1) = "," Then
MotGauche = Mid(Reqt, Cpt0 + 1, Posi - Cpt0 - 1): Exit For
End If
Next Cpt0
If MotGauche = "" Then MotGauche = Mid(Reqt, 1, Posi - 1)
'descend la phrase >--->
For Cpt0 = Posi + 1 To Len(Reqt)
If Mid(Reqt, Cpt0, 1) = " " Or Mid(Reqt, Cpt0, 1) = "," Then
MotDroite = Mid(Reqt, Posi + 1, Cpt0 - Posi - 1): Exit For
End If
Next Cpt0
If MotDroite = "" Then MotDroite = Mid(Reqt, Posi + 1, Len(Reqt) - Posi)
RecupleMot = MotGauche & Mid(Reqt, Posi, 1) & MotDroite
Fin = Posi + Len(MotDroite) + 1
End Function |
Partager