Function IsDisplayable(vParam As Variant) As Boolean
' vParam contient soit :
' 1. le code ascii d'un caractère
' 2. une chaîne composée de 1 ou plusieurs caractères
IsDisplayable = False
Dim iType As VbVarType
iType = VarType(vParam)
If (iType <> vbInteger) And (iType <> vbString) Then
Err.Raise vbObject Or vbVariant, "IsDisplayable", "Type de paramètre incorrect."
Exit Function
Else
Dim sString As String, i As Long, iAscii As Integer
If iType = vbInteger Then
If Val(vParam) < 0 Or Val(vParam) > 255 Then
Err.Raise vbObject Or vbVariant, "IsDisplayable", "Paramètre inattendu."
Exit Function
End If
sString = Chr$(vParam)
Else
sString = CStr(vParam)
End If
For i = 1 To LenB(sString) Step 2
iAscii = Asc(MidB$(sString, i, 2))
If (iAscii < 32) Or (iAscii = 127) Or ((iAscii > 128) And (iAscii < 145)) Or ((iAscii > 146) And (iAscii < 160)) Then Exit Function
Next i
IsDisplayable = True
End If
End Function
' EXEMPLE D'UTILISATION
MsgBox IsDisplayable(127) ' (carré)
MsgBox IsDisplayable("›") '155 (autre carré)
MsgBox IsDisplayable("Test de phrase correcte")
MsgBox IsDisplayable("Test de phrase " & Chr$(13) & "incorrecte")