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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
| Private Sub TxtArticleDesignationLongue_LostFocus()
Dim LcStrDesignLong As String, LcStrPremLigne As String, LcStrSuivLigne As String
Dim LcStrTableauCaract() As String, LcStrTableauProv() As String, LcStrTableauLigne() As String
Dim LcIntI01 As Integer, LcIntI02 As Integer, LcIntNbrLigneNonVide As Integer, LcIntNbrCaract As Integer
Dim LcIntPosRetour As Integer, LcIntPremPosTexte As Integer, LcIntDernPosTexte As Integer
'(1)Mise en forme du texte
'-------------------------
LcStrDesignLong = TxtArticleDesignationLongue 'Selectionne la totalité du contenu du champs TxtArticleDesignationLongue avec les balises HTML
LcIntPosRetour = InStr(LcStrDesignLong, vbCrLf) 'Donne la position du premier retour chariot
'Debug.Print "Contenu du champ :"
'Debug.Print LcStrDesignLong
If LcIntPosRetour = 0 Then 'S'il n'y a pas de retour chariot (donc qu'il n'y a qu'une ligne)
ReDim LcStrTableauLigne(0)
LcStrTableauLigne(0) = LcStrDesignLong
Else 'Sinon
LcStrTableauProv = Split(LcStrDesignLong, vbCrLf) 'Crée un tableau provisoire avec chaque portion comprise entre les retours chariot
For LcIntI01 = 0 To UBound(LcStrTableauProv)
If LcStrTableauProv(LcIntI01) = "" And LcIntI01 = 0 Then
MsgBox ("Veuillez remplir la désignation longue !")
ElseIf LcStrTableauProv(LcIntI01) <> "" And InStr(LcStrTableauProv(LcIntI01), "*") = 0 Then
LcIntNbrLigneNonVide = LcIntNbrLigneNonVide + 1
End If
Next LcIntI01
ReDim LcStrTableauLigne(LcIntNbrLigneNonVide - 1) 'Crée un tableau définif nettoyé de ses lignes vides et des sauts de ligne dans le champ
LcIntI02 = 0
For LcIntI01 = 0 To UBound(LcStrTableauProv)
If LcStrTableauProv(LcIntI01) <> "" And InStr(LcStrTableauProv(LcIntI01), "*") = 0 Then
LcStrTableauLigne(LcIntI02) = LcStrTableauProv(LcIntI01)
LcIntI02 = LcIntI02 + 1
End If
Next LcIntI01
ReDim LcStrTableauProv(0)
End If
'Debug.Print "provisoire"
'For LcIntI01 = 0 To UBound(LcStrTableauProv)
'Debug.Print LcIntI01 & " " & LcStrTableauProv(LcIntI01)
'Next LcIntI01
'Debug.Print "Contenu du tableau ligne :"
'For LcIntI01 = 0 To UBound(LcStrTableauLigne)
'Debug.Print LcIntI01 & " " & LcStrTableauLigne(LcIntI01)
'Next LcIntI01
'Traitement de la premiere ligne
LcIntNbrCaract = Len(LcStrTableauLigne(0)) 'Compte le nombre de caractere de la ligne
ReDim LcStrTableauCaract(LcIntNbrCaract - 1) 'Defini la taille du tableau des caracteres
'Debug.Print "Ligne 01 :"
For LcIntI01 = 0 To UBound(LcStrTableauCaract) 'Rempli le tableau des caracteres
LcStrTableauCaract(LcIntI01) = Mid(LcStrTableauLigne(0), LcIntI01 + 1, 1)
'Debug.Print LcIntI01 & " : " & LcStrTableauCaract(LcIntI01)
If LcIntI01 > 0 Then
If LcStrTableauCaract(LcIntI01 - 1) = ">" And LcStrTableauCaract(LcIntI01) <> "<" Then 'Donne la position du premier caractere du texte apres les balises ouvrantes
If LcIntPremPosTexte = 0 Then
LcIntPremPosTexte = LcIntI01
End If
End If
If LcStrTableauCaract(LcIntI01 - 1) = "<" And LcStrTableauCaract(LcIntI01) = "/" Then 'Donne la position du dernier caractere du texte avant les balises fermantes
If LcIntDernPosTexte = 0 Then
LcIntDernPosTexte = LcIntI01 - 2
End If
End If
End If
Next LcIntI01
'Debug.Print "Position début : " & LcIntPremPosTexte
'Debug.Print "Position fin : " & LcIntDernPosTexte
If LcIntPremPosTexte = 0 And LcIntDernPosTexte = 0 Then 'S'il n'y a pas de balise de mise en forme
LcStrTableauLigne(0) = "<div><font size:11pt><strong>" & LcStrTableauLigne(0) & "</strong></font></div>"
Else
LcStrTableauLigne(0) = ""
For LcIntI01 = LcIntPremPosTexte To LcIntDernPosTexte 'Compile les valeurs de la ligne pour reformer le texte sans les balises de mise en forme
LcStrTableauLigne(0) = LcStrTableauLigne(0) & LcStrTableauCaract(LcIntI01)
Next LcIntI01
LcStrTableauLigne(0) = "<div><font size:11pt><strong>" & LcStrTableauLigne(0) & "</strong></font></div>"
End If
'Debug.Print "TableauLigne(0) remise en forme :"
'Debug.Print LcStrTableauLigne(0)
'Traitement des lignes suivantes (s'il y en a ...)
If UBound(LcStrTableauLigne) > 0 Then
For LcIntI02 = 1 To UBound(LcStrTableauLigne)
'Debug.Print "Ligne 0" & LcIntI02 + 1
LcIntPremPosTexte = 0
LcIntDernPosTexte = 0
LcIntNbrCaract = Len(LcStrTableauLigne(LcIntI02)) 'Compte le nombre de caractere de la ligne
ReDim LcStrTableauCaract(LcIntNbrCaract - 1) 'Defini la taille du tableau des caracteres
For LcIntI01 = 0 To UBound(LcStrTableauCaract) 'Rempli le tableau des caracteres
LcStrTableauCaract(LcIntI01) = Mid(LcStrTableauLigne(LcIntI02), LcIntI01 + 1, 1)
'Debug.Print LcIntI01 & " : " & LcStrTableauCaract(LcIntI01)
If LcIntI01 > 0 Then
If LcStrTableauCaract(LcIntI01 - 1) = ">" And LcStrTableauCaract(LcIntI01) <> "<" Then 'Donne la position du premier caractere du texte apres les balises ouvrantes
If LcIntPremPosTexte = 0 Then
LcIntPremPosTexte = LcIntI01
End If
End If
If LcStrTableauCaract(LcIntI01 - 1) = "<" And LcStrTableauCaract(LcIntI01) = "/" Then 'Donne la position du dernier caractere du texte avant les balises fermantes
If LcIntDernPosTexte = 0 Then
LcIntDernPosTexte = LcIntI01 - 2
End If
End If
End If
Next LcIntI01
'Debug.Print "Position début : " & LcIntPremPosTexte
'Debug.Print "Position fin : " & LcIntDernPosTexte
If LcIntPremPosTexte = 0 And LcIntDernPosTexte = 0 Then 'S'il n'y a pas de balise de mise en forme
LcStrTableauLigne(LcIntI02) = "<div><font size=2><em>" & LcStrTableauLigne(LcIntI02) & "</em></font></div>"
Else
LcStrTableauLigne(LcIntI02) = ""
For LcIntI01 = LcIntPremPosTexte To LcIntDernPosTexte 'Compile les valeurs de la ligne pour reformer le texte sans les balises de mise en forme
LcStrTableauLigne(LcIntI02) = LcStrTableauLigne(LcIntI02) & LcStrTableauCaract(LcIntI01)
Next LcIntI01
LcStrTableauLigne(LcIntI02) = "<div><font size=2><em>" & LcStrTableauLigne(LcIntI02) & "</em></font></div>"
End If
'Debug.Print "TableauLigne(" & LcIntI02 & ") remise en forme :"
'Debug.Print LcStrTableauLigne(LcIntI02)
Next LcIntI02
End If
'Remplissage du champ avec la nouvelle mise en forme
If UBound(LcStrTableauLigne) = 0 Then
TxtArticleDesignationLongue = LcStrTableauLigne(0)
Else
TxtArticleDesignationLongue = ""
For LcIntI02 = 0 To UBound(LcStrTableauLigne) - 1
TxtArticleDesignationLongue = TxtArticleDesignationLongue & LcStrTableauLigne(LcIntI02) & Chr(13) & Chr(10)
Next LcIntI02
TxtArticleDesignationLongue = TxtArticleDesignationLongue & LcStrTableauLigne(UBound(LcStrTableauLigne))
End If
'(1)Fin
End Sub |
Partager