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
| '----------------------------------------Les fonctions -----------------------------------------
Private Function StrLeft(Mot As String, NbrCaracteres As Integer, Caractere As String) As String
Dim CpT As Integer, StrMot As String
StrMot = Left(Mot, NbrCaracteres)
CpT = NbrCaracteres - Len(StrMot)
If Caractere = "" Then Caractere = " "
If NbrCaracteres > CpT Then
StrLeft = StrMot & String$(CpT, Caractere)
Else
StrLeft = StrMot
End If
End Function
Private Function StrCentr(Mot As String, NbrCaracteres As Integer, CaractereG As String, Optional CaractereD As String = "False") As String
Dim CpT As Integer, StrMot As String
StrMot = Left(Mot, NbrCaracteres)
CpT = (NbrCaracteres - Len(StrMot)) / 2
If CaractereG = "" Then CaractereG = " "
If NbrCaracteres > CpT Then
StrCentr = String$(CpT, CaractereG) & StrMot
If CaractereD = "False" Or CaractereD = "" Then
StrCentr = StrCentr & String$(NbrCaracteres - Len(StrCentr), CaractereG)
Else
StrCentr = StrCentr & String$(NbrCaracteres - Len(StrCentr), CaractereD)
End If
Else
StrCentr = StrMot
End If
End Function
Private Function StrRight(Mot As String, NbrCaracteres As Integer, Caractere As String) As String
Dim CpT As Integer, StrMot As String
StrMot = Left(Mot, NbrCaracteres)
CpT = NbrCaracteres - Len(StrMot)
If Caractere = "" Then Caractere = " "
If NbrCaracteres > CpT Then
StrRight = String$(CpT, Caractere) & StrMot
Else
StrRight = StrMot
End If
End Function
'------------------------------- utilisation -----------------------------------
Private Sub Form_Load()
MsgBox StrLeft("Salut",10,">")
MsgBox StrRight("Re",20,"<")
MsgBox StrCentr("Utilisable?",25,">","<")
MsgBox StrLeft("tout ne sera pas affiché, mais pas de bug",5,"?")
End Sub |
Partager