Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

MISE EN FORME DE PARAGRAPHE (JUSTIFIE) EN POLICE A LARGEUR FIXE


Information sur la source

Catégorie :Texte Classé sous : texte, justifier, paragraphe, alignement, wordwrap Niveau : Débutant Date de création : 06/07/2006 Date de mise à jour : 12/07/2006 18:21:41 Vu / téléchargé: 7 918 / 304

Note :
8 / 10 - par 3 personnes
8,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

Commentaire sur cette source (13)
Ajouter un commentaire et/ou une note

Description

Cliquez pour voir la capture en taille normale
Description _________________
Ce module vous fournit une fonction simple et riche pour mettre en forme un texte en police a largeur fixe (Courier ou Lucida).

Fonctionnement ______________
Les polices a largeur fixe utilise la meme largeur pour tous les caracteres alors que les polices a largeur variable adapte la largeur pour chaque caractere ce qui fait qu'un "M" sera plus large qu'un "I".
Mettre en forme de tels paragraphes repose sur l'ajout d'espaces pour donner aux lignes une certaine largeur.

Exemple _________________
Voir image et formulaire.

 

Source

  • '************************************************************************'
  • '************************************************************************'
  • '**                                                                    **'
  • '**            LUCIDA (FIXED-WIDTH FONT) TEXT SETUP MODULE             **'
  • '**                                                                    **'
  • '************************************************************************'
  • '************************************************************************'
  • '----------------------------   ATTRIBUTES   ----------------------------'
  • 'Author = Santiago Diez (santiago.diez@free.fr)
  • 'Website = http://santiago.diez.free.fr
  • 'Webpage = http://www.vbfrance.com/code.aspx?ID=38468
  • 'Date = 10 JULY 2006  14:13
  • 'Version = 2.0
  • '----------------------------   COPYRIGHT   -----------------------------'
  • 'I worked on  that module for  me and for  you. You are  allowed to do the
  • 'following  as long  as you  specify my  name and  website  (please  don't
  • 'laught, one day it will be a real website):
  • '- use the code, partially or totally
  • '- change the code partially
  • 'If you ever improve the features of  that module, fix any bug or find any
  • 'way to make it better, please write to me for feedback.
  • '---------------------------   DESCRIPTION   ----------------------------'
  • 'This module provides you  with functions to setup the layout  of texts to
  • 'display with fixed-width fonts (Courier or Lucida).
  • '---------------------------   HOW IT WORKS   ---------------------------'
  • 'Fixed-width  fonts   use  the   same  width   for  any   character,  when
  • 'variable-width fonts adapt the size for each character which makes an "M"
  • 'larger than an "I".
  • 'Setting the  layout of  such texts is  only based  on adding  or removing
  • 'space characters to make a line reach a certain size.
  • '-----------------   PUBLIC PROCEDURES AND FUNCTIONS   ------------------'
  • 'String = LucidaTextSetup(Text As String, Length As Long, [ParagraphStyle
  • '         As LucidaStyle], [IsOneParagraph As Boolean], [ParagraphTab],
  • '         [FirstLineTab], [LineSeparator As String = vbCrLf])
  • '-----------------------------   EXAMPLES   -----------------------------'
  • '    Text = "I have a dream that one day this nation will rise up and" & _
  • '           " live out the true meaning of its creed : ""We hold thes" & _
  • '           "e truths to be self-evident that all men are created equ" & _
  • '           "al."""
  • '    Debug.Print LucidaTextSetup(Text, 40, , , 3, 6)
  • '    Text = "I have a dream that one day on the red hills of Georgia " & _
  • '           "the sons of former slaves and the sons of former slaveow" & _
  • '           "ners will be able to sit down together at a table of bro" & _
  • '           "therhood."
  • '    Debug.Print LucidaTextSetup(Text, 40, LucidaCenter)
  • '    Text = "I have a dream that one day even the state of Mississipp" & _
  • '           "i, a desert state, sweltering with the heat of injustice" & _
  • '           " and oppression, will be transformed into an oasis of fr" & _
  • '           "eedom and justice."
  • '    Debug.Print LucidaTextSetup(Text, 40, LucidaRight)
  • '    Text = "I have a dream that my four children will one day live i" & _
  • '           "n a nation where they will not be judged by the color of" & _
  • '           " their skin but by the content of their character."
  • '    Debug.Print LucidaTextSetup(Text, 40, LucidaJustify, , 4, 2)
  • '    Debug.Print "I have a dream today."
  • '           +-------------------------------+
  • '           |      I have a dream that one  |
  • '           |   day this nation will rise   |
  • '           |   up and live out the true    |
  • '           |   meaning of its creed : "We  |
  • '           |   hold these truths to be     |
  • '           |   self-evident that all men   |
  • '           |   are created equal."         |
  • '           |                               |
  • '           |I have a dream that one day on |
  • '           | the red hills of Georgia the  |
  • '           |sons of former slaves and the  |
  • '           |  sons of former slaveowners   |
  • '           |   will be able to sit down    |
  • '           |    together at a table of     |
  • '           |         brotherhood.          |
  • '           |                               |
  • '           |   I have a dream that one day |
  • '           |even the state of Mississippi, |
  • '           |    a desert state, sweltering |
  • '           |with the heat of injustice and |
  • '           |           oppression, will be |
  • '           |  transformed into an oasis of |
  • '           |          freedom and justice. |
  • '           |                               |
  • '           |  I have a dream  that my four |
  • '           |    children will one day live |
  • '           |    in  a  nation  where  they |
  • '           |    will not be  judged by the |
  • '           |    color of their skin but by |
  • '           |    the   content   of   their |
  • '           |    character.                 |
  • '           |                               |
  • '           |I have a dream today.          |
  • '           +-------------------------------+
  • '-------------------------------   BUGS   -------------------------------'
  • 'No bug reported.
  • '-----------------------------   SEE ALSO   -----------------------------'
  • 'http://www.vbfrance.com/code.aspx?ID=36370 (by jean_marc_n2)
  • '------------------------   REQUIRED LIBRARIES   ------------------------'
  • 'msvbvm60.dll, VB6.OLB, VB6FR.DLL (Always required)
  • '--------------------   REQUIRED MODULES AND FORMS   --------------------'
  • 'None
  • '-----------------------------   OPTIONS   ------------------------------'
  • Option Base 0
  • Option Compare Text
  • Option Explicit
  • '+----------------------------------------------------------------------+'
  • '+                           TYPES AND ENUMS                            +'
  • '+----------------------------------------------------------------------+'
  • 'Enum: ParagraphStyle
  • '   Enumeration of the paragraph styles.
  • '------------------------------------------------------------------------'
  • Enum LucidaStyle
  • LucidaLeft = &H0
  • LucidaJustify = &H1
  • LucidaRight = &H2
  • LucidaCenter = &H4
  • End Enum
  • '+----------------------------------------------------------------------+'
  • '+                             LAYOUT SETUP                             +'
  • '+----------------------------------------------------------------------+'
  • 'Function: LucidaTextSetup
  • '   Returns a  string expression containing a  text setup with  a specific
  • '   layout.
  • '   Parameters: Text: A String expression specifying the text to setup the
  • '                   layout. If "Text" contains "Null", "Null" is returned.
  • '               Length: A numeric  expression specifying the width  of the
  • '                   layout. If  "Length" is not  greater than 0,  an error
  • '                   occurs.
  • '               ParagraphStyle (Optional): Specify the type of layout used
  • '                   to   setup   the   paragraphs    in   the   text.   If
  • '                   "ParagraphStyle" is  omitted, paragraphs  in text  are
  • '                   setup with left-style.
  • '               IsOneParagraph (Optional): A Boolean expression specifying
  • '                   if "Text" is considered as only one paragraph. Default
  • '                   value  is  "False":  Each   line  in  "Text"  makes  a
  • '                   paragraph.
  • '               ParagraphTab (Optional):  A numeric  expression specifying
  • '                   the number  of spaces to add  on the left side  of the
  • '                   text to  return. If "ParagraphTab"  is less than  0 or
  • '                   greater   than   "Length",   an   error   occurs.   If
  • '                   "ParagraphTab"   is   omitted,   two  cases:   1)   If
  • '                   "IsOneParagraph" is set to  "True" and "Text" contains
  • '                   more than  one line, "ParagraphTab"  is assumed  to be
  • '                   the tab of the second line. 2) In any other case, 0 is
  • '                   assumed.
  • '               FirstLineTab (Optional):  A numeric  expression specifying
  • '                   the number  of spaces to add  on the left side  of the
  • '                   first line  of each paragraph  of the text  to return.
  • '                   "FirstLineTab"     includes     "ParagraphTab".     If
  • '                   "FirstLineTab"  is   less  than  0  or   greater  than
  • '                   "Length",  an  error   occurs.  If  "FirstLineTab"  is
  • '                   omitted, it is assumed to be the tab of the first line
  • '                   for each paragraph in "Text".
  • '               LineSeparator (Optional): A string expression specifying a
  • '                   substring that represent a line separation. Default is
  • '                   vbCrLf (Chr(13) + Chr(10)).
  • '------------------------------------------------------------------------'
  • Function LucidaTextSetup(Text, Length As Long, Optional ParagraphStyle _
  • As LucidaStyle, Optional IsOneParagraph As Boolean, Optional _
  • ParagraphTab, Optional FirstLineTab, Optional LineSeparator As String = _
  • vbCrLf)
  • Dim i As Long
  • Dim Temp As String
  • Dim Lines
  • Dim PTab As Long
  • 'Split text into lines
  • If IsNull(Text) Then
  • LucidaTextSetup = Null
  • Exit Function
  • ElseIf Len(Text) = 0 Then
  • Temp = Array("")
  • Else
  • Lines = Split(Text, LineSeparator)
  • End If
  • 'If text is one paragraph...
  • If IsOneParagraph Then
  • 'Calculate paragraph tab from second line
  • If Not IsMissing(ParagraphTab) Then
  • PTab = ParagraphTab
  • ElseIf UBound(Lines) > 0 Then
  • PTab = Len(Lines(1)) - Len(LTrim$(Lines(1)))
  • End If
  • 'Concatenate lines into one paragraph
  • Temp = Replace(Text, LineSeparator, " ")
  • 'Setup paragraph layout
  • SetUpParagraph Temp, Length, ParagraphStyle, PTab, _
  • FirstLineTab, LineSeparator
  • 'If each line is a paragraph...
  • Else
  • 'Setup layout for each line
  • Temp = ""
  • For i = 0 To UBound(Lines)
  • SetUpParagraph Lines(i), Length, ParagraphStyle, _
  • ParagraphTab, FirstLineTab, LineSeparator
  • Temp = Temp & IIf(i = 0, "", LineSeparator) & Lines(i)
  • Next
  • End If
  • 'Return value
  • LucidaTextSetup = Temp
  • End Function
  • '------------------------------------------------------------------------'
  • 'Sub: SetUpParagraph
  • '   Setup the layout of a paragraph.
  • '   Parameters: Text (Read/Write):  A  String  expression  specifying  the
  • '                   paragraph to setup the layout.
  • '               Length: A numeric  expression specifying the width  of the
  • '                   layout.
  • '               ParagraphStyle (Optional): Specify the type of layout used
  • '                   to  setup   the  paragraph.  If   "ParagraphStyle"  is
  • '                   omitted, paragraph is setup with left-style.
  • '               ParagraphTab (Optional):  A numeric  expression specifying
  • '                   the number  of spaces to add  on the left side  of the
  • '                   paragraph. If "ParagraphTab" is less than 0 or greater
  • '                   than "Length",  an error occurs. If  "ParagraphTab" is
  • '                   omitted, 0 is assumed.
  • '               FirstLineTab (Optional):  A numeric  expression specifying
  • '                   the number  of spaces to add  on the left side  of the
  • '                   first line  of the paragraph.  "FirstLineTab" includes
  • '                   "ParagraphTab". If  "FirstLineTab" is  less than  0 or
  • '                   greater   than   "Length",   an   error   occurs.   If
  • '                   "FirstLineTab" is omitted, it is assumed to be the tab
  • '                   of the first line of "Text".
  • '               LineSeparator (Optional): A string expression specifying a
  • '                   substring that represent a line separation. Default is
  • '                   vbCrLf (Chr(13) + Chr(10)).
  • '------------------------------------------------------------------------'
  • Private Sub SetUpParagraph(Text, Length As Long, ParagraphStyle As _
  • LucidaStyle, Optional ParagraphTab, Optional FirstLineTab, Optional _
  • LineSeparator As String)
  • Dim Words
  • Dim Position As Long
  • Dim FLTab As Long
  • Dim PTab As Long
  • 'Calculate first line tab
  • If IsMissing(FirstLineTab) _
  • Then FLTab = Len(Text) - Len(LTrim$(Text)) _
  • Else: FLTab = CLng(FirstLineTab)
  • 'Calculate paragraph tab
  • If IsMissing(ParagraphTab) _
  • Then PTab = 0 _
  • Else: PTab = CLng(ParagraphTab)
  • 'Remove left and right spaces
  • Text = Trim$(Text)
  • 'Remove double-spaces
  • Do While InStr(Text, " ") > 0
  • Text = Replace(Text, " ", " ")
  • Loop
  • 'Split text into an array of words
  • If Len(Text) = 0 Then
  • Words = Array("")
  • Else
  • Words = Split(Text)
  • End If
  • 'Build first line
  • Text = "": Position = 0
  • AddLine Text, Words, Position, Length, _
  • ParagraphStyle, FLTab, LineSeparator
  • 'Build other lines
  • Do While Position <= UBound(Words)
  • AddLine Text, Words, Position, Length, _
  • ParagraphStyle, PTab, LineSeparator
  • Loop
  • End Sub
  • '------------------------------------------------------------------------'
  • 'Sub: AddLine
  • '   Add as much words as can contain a line to a paragraph.
  • '   Parameters: Text (Read/Write):  A  String  expression  specifying  the
  • '                   paragraph to add a line to.
  • '               Words(): An array  of strings containing the  words to add
  • '                   to the paragraph.
  • '               Position: A numeric expression  specifying the position of
  • '                   the next word to add to the paragraph.
  • '               Length: A numeric  expression specifying the width  of the
  • '                   layout.
  • '               ParagraphStyle: Specify the  type of layout used  to setup
  • '                   the paragraph.
  • '               LineTab:  A numeric  expression specifying  the number  of
  • '                   spaces to add on the left side of the line to add.
  • '               LineSeparator: A string expression  specifying a substring
  • '                   that represent a line separation.
  • '------------------------------------------------------------------------'
  • Private Sub AddLine(Text, Words, Position As Long, Length As Long, _
  • ParagraphStyle As LucidaStyle, LineTab As Long, LineSeparator As String)
  • Dim Line As String
  • Dim EOL As Boolean
  • 'I need to raise the error myself because:
  • '1) If "LineTab" is negative, an error occurs in "Space$(LineTab)"
  • '2) If  "LineTab"  is  greater  than  "Length",  an  error  occurs  in
  • '   "Left$(Words(Position), Length - LineTab)"
  • '3) If "Length" is negative, error (1) or (2) occurs
  • '4) If "Length" is positive and  "LineTab" belongs to [0, "Length"[, a
  • '   correct paragraph can be returned
  • '5) Last  case  is "LineTab"  equal  to  "Length"  which leads  to  an
  • '   everlasting loop
  • If LineTab = Length Then Err.Raise 5
  • 'While there is still words to add and it's not the end of the line
  • Do While Position <= UBound(Words) And Not EOL
  • 'If word can be added, add it and move to next
  • If Len(Line) + Len(Words(Position)) + IIf(Len(Line) = 0, 0, 1) _
  • <= Length - LineTab Then
  • Line = Line & IIf(Len(Line) = 0, "", " ") & Words(Position)
  • Position = Position + 1
  • 'If word cannot be added, set end of line
  • Else
  • EOL = True
  • End If
  • Loop
  • 'If no word fits in line
  • If Len(Line) = 0 And EOL Then
  • 'Add length first characters of next word
  • Line = Left$(Words(Position), Length - LineTab)
  • Words(Position) = Mid$(Words(Position), Length - LineTab + 1)
  • 'Normal line to be setup
  • Else
  • 'Do not setup justify for the last line
  • If Position > UBound(Words) Then
  • SetupLine Line, Length - LineTab, _
  • ParagraphStyle And Not LucidaJustify
  • Else
  • SetupLine Line, Length - LineTab, ParagraphStyle
  • End If
  • End If
  • 'Add new line to text
  • Text = Text & IIf(Len(Text) = 0, "", LineSeparator) _
  • & Space$(LineTab) & Line
  • End Sub
  • '------------------------------------------------------------------------'
  • 'Sub: SetupLine
  • '   Setup the layout of a line.
  • '   Parameters: Line (Read/Write): A String expression specifying the line
  • '                   to setup the layout.
  • '               Length: A numeric  expression specifying the width  of the
  • '                   layout.
  • '               ParagraphStyle: Specify the  type of layout used  to setup
  • '                   the paragraph.
  • '------------------------------------------------------------------------'
  • Private Sub SetupLine(Line, Length As Long, ParagraphStyle As LucidaStyle)
  • Dim i As Long
  • Dim Words() As String
  • Dim SpaceInLine As Long
  • Dim SpaceToAdd As Long
  • Dim SpaceAdded As Long
  • Dim Spaces As String
  • 'If line has to be justified
  • If Len(Line) > 0 And CBool(ParagraphStyle And LucidaJustify) Then
  • 'Split line into array of words
  • Words = Split(Line)
  • 'Calculate number of spaces in line and to add
  • SpaceInLine = UBound(Words) - LBound(Words)
  • SpaceToAdd = Length - Len(Line)
  • 'Initialize line to first word
  • Line = Words(LBound(Words))
  • 'Add other words one after the other
  • For i = LBound(Words) + 1 To UBound(Words)
  • 'Build word separator
  • Spaces = Space$(SpaceToAdd / SpaceInLine _
  • * (i - LBound(Words)) - SpaceAdded)
  • SpaceAdded = SpaceAdded + Len(Spaces)
  • 'Concatenate line, word separator and word
  • Line = Line & " " & Spaces & Words(i)
  • Next
  • End If
  • 'Setup line position
  • If ParagraphStyle And LucidaRight Then
  • Line = Space$(Length - Len(Line)) & Line
  • ElseIf ParagraphStyle And LucidaCenter Then
  • Line = Space$((Length - Len(Line)) / 2) & Line
  • End If
  • End Sub
  • '+----------------------------------------------------------------------+'
  • '+                NON-BREAKING SPACES SMART REPLACEMENT                 +'
  • '+----------------------------------------------------------------------+'
  • 'Function: NBSPSmartInsert
  • '   Returns a  string in  which multiple  spaces have  been replaced  by a
  • '   smart combination of spaces and non-breaking spaces.
  • '   Solution 1: Replace all spaces by  non-breaking spaces. That makes the
  • '       change  irreversible.  A  non-breaking  space  between  two  words
  • '       prevent them to be split in two lines. If all spaces are replaced,
  • '       it will  be impossible  to tell whether  a non-breaking  space was
  • '       user-defined or added by the function.
  • '   Solution 2:  Replace all  double spaces  by a  combination of  space +
  • '       non-breaking  space.  The  change  is  reversible  as  long  as  a
  • '       user-defined non-breaking space  combined with a space  is totally
  • '       useless. The  lack of that solution  is that when displayed  in an
  • '       editor, it will not be possible to use Ctrl+Arrow (that usualy tab
  • '       from word to word) because it will tab every two spaces.
  • '   Solution  3:  Replace  all  groups of  "n"  spaces  by  the  following
  • '       combination: space  + "n-2" non-breaking  spaces + space.  In case
  • '       there  are only  2  spaces  in the  group,  they  are replaced  by
  • '       non-breaking space  + space. This change  is reversible and  it is
  • '       possible  to   tab  from   word  to  word.   To  achieve   such  a
  • '       transformation, I  perform the  following replacements.  Caret (^)
  • '       and tilde  (~) represent  2 non-string  character, underscore  (_)
  • '       represents a non-breaking space:
  • '                           Text: "word                    word"
  • '           Replace "  " by "^~": "word^~^~^~^~^~^~^~^~^~^~word"
  • '           Replace "~^" by "__": "word^__________________~word"
  • '           Replace "^"  by " " : "word __________________~word"
  • '           Replace "~"  by " " : "word __________________ word"
  • '   Parameters: Text:  A String  expression specifying  the text  in which
  • '                   multiple space have to be replaced.
  • '               NBSP:  String  character  representing the  value  of  the
  • '                   non-breaking space character in the current system.
  • '------------------------------------------------------------------------'
  • Function NBSPSmartInsert(Text As String, NBSP As String) As String
  • Dim NoStr1 As String, NoStr2 As String
  • NoStr1 = Chr$(0)
  • NoStr2 = Chr$(1)
  • NBSPSmartInsert = Replace(Replace(Replace(Replace(Replace(Replace( _
  • Text, _
  • " ", NoStr1 & NoStr2), _
  • NoStr2 & NoStr1, NBSP & NBSP), _
  • NoStr1, " "), _
  • NoStr2, " "), _
  • " ", " " & NBSP & " "), _
  • " ", NBSP & " ")
  • End Function
  • '------------------------------------------------------------------------'
  • 'Function: NBSPSmartRemove
  • '   Returns  a  string in  which  useless  non-breaking spaces  have  been
  • '   replaced by spaces.
  • '   Parameters: Text:  A String  expression specifying  the text  in which
  • '                   useless non-breaking spaces have to be replaced.
  • '               NBSP:  String  character  representing the  value  of  the
  • '                   non-breaking space character in the current system.
  • '------------------------------------------------------------------------'
  • Function NBSPSmartReplace(Text As String, NBSP As String) As String
  • NBSPSmartReplace = Text
  • Do While InStr(NBSPSmartReplace, NBSP & " ") > 0
  • NBSPSmartReplace = Replace(NBSPSmartReplace, NBSP & " ", " ")
  • Loop
  • Do While InStr(NBSPSmartReplace, " " & NBSP) > 0
  • NBSPSmartReplace = Replace(NBSPSmartReplace, " " & NBSP, " ")
  • Loop
  • End Function
'************************************************************************'
'************************************************************************'
'**                                                                    **'
'**            LUCIDA (FIXED-WIDTH FONT) TEXT SETUP MODULE             **'
'**                                                                    **'
'************************************************************************'
'************************************************************************'



'----------------------------   ATTRIBUTES   ----------------------------'
'Author = Santiago Diez (santiago.diez@free.fr)
'Website = http://santiago.diez.free.fr
'Webpage = http://www.vbfrance.com/code.aspx?ID=38468
'Date = 10 JULY 2006  14:13
'Version = 2.0

'----------------------------   COPYRIGHT   -----------------------------'
'I worked on  that module for  me and for  you. You are  allowed to do the
'following  as long  as you  specify my  name and  website  (please  don't
'laught, one day it will be a real website):
'- use the code, partially or totally
'- change the code partially
'If you ever improve the features of  that module, fix any bug or find any
'way to make it better, please write to me for feedback.

'---------------------------   DESCRIPTION   ----------------------------'
'This module provides you  with functions to setup the layout  of texts to
'display with fixed-width fonts (Courier or Lucida).

'---------------------------   HOW IT WORKS   ---------------------------'
'Fixed-width  fonts   use  the   same  width   for  any   character,  when
'variable-width fonts adapt the size for each character which makes an "M"
'larger than an "I".
'Setting the  layout of  such texts is  only based  on adding  or removing
'space characters to make a line reach a certain size.

'-----------------   PUBLIC PROCEDURES AND FUNCTIONS   ------------------'
'String = LucidaTextSetup(Text As String, Length As Long, [ParagraphStyle
'         As LucidaStyle], [IsOneParagraph As Boolean], [ParagraphTab],
'         [FirstLineTab], [LineSeparator As String = vbCrLf])

'-----------------------------   EXAMPLES   -----------------------------'
'    Text = "I have a dream that one day this nation will rise up and" & _
'           " live out the true meaning of its creed : ""We hold thes" & _
'           "e truths to be self-evident that all men are created equ" & _
'           "al."""
'    Debug.Print LucidaTextSetup(Text, 40, , , 3, 6)
'    Text = "I have a dream that one day on the red hills of Georgia " & _
'           "the sons of former slaves and the sons of former slaveow" & _
'           "ners will be able to sit down together at a table of bro" & _
'           "therhood."
'    Debug.Print LucidaTextSetup(Text, 40, LucidaCenter)
'    Text = "I have a dream that one day even the state of Mississipp" & _
'           "i, a desert state, sweltering with the heat of injustice" & _
'           " and oppression, will be transformed into an oasis of fr" & _
'           "eedom and justice."
'    Debug.Print LucidaTextSetup(Text, 40, LucidaRight)
'    Text = "I have a dream that my four children will one day live i" & _
'           "n a nation where they will not be judged by the color of" & _
'           " their skin but by the content of their character."
'    Debug.Print LucidaTextSetup(Text, 40, LucidaJustify, , 4, 2)
'    Debug.Print "I have a dream today."

'           +-------------------------------+
'           |      I have a dream that one  |
'           |   day this nation will rise   |
'           |   up and live out the true    |
'           |   meaning of its creed : "We  |
'           |   hold these truths to be     |
'           |   self-evident that all men   |
'           |   are created equal."         |
'           |                               |
'           |I have a dream that one day on |
'           | the red hills of Georgia the  |
'           |sons of former slaves and the  |
'           |  sons of former slaveowners   |
'           |   will be able to sit down    |
'           |    together at a table of     |
'           |         brotherhood.          |
'           |                               |
'           |   I have a dream that one day |
'           |even the state of Mississippi, |
'           |    a desert state, sweltering |
'           |with the heat of injustice and |
'           |           oppression, will be |
'           |  transformed into an oasis of |
'           |          freedom and justice. |
'           |                               |
'           |  I have a dream  that my four |
'           |    children will one day live |
'           |    in  a  nation  where  they |
'           |    will not be  judged by the |
'           |    color of their skin but by |
'           |    the   content   of   their |
'           |    character.                 |
'           |                               |
'           |I have a dream today.          |
'           +-------------------------------+

'-------------------------------   BUGS   -------------------------------'
'No bug reported.

'-----------------------------   SEE ALSO   -----------------------------'
'http://www.vbfrance.com/code.aspx?ID=36370 (by jean_marc_n2)

'------------------------   REQUIRED LIBRARIES   ------------------------'
'msvbvm60.dll, VB6.OLB, VB6FR.DLL (Always required)

'--------------------   REQUIRED MODULES AND FORMS   --------------------'
'None

'-----------------------------   OPTIONS   ------------------------------'
Option Base 0
Option Compare Text
Option Explicit



'+----------------------------------------------------------------------+'
'+                           TYPES AND ENUMS                            +'
'+----------------------------------------------------------------------+'
'Enum: ParagraphStyle
'   Enumeration of the paragraph styles.
'------------------------------------------------------------------------'
Enum LucidaStyle
    LucidaLeft = &H0
    LucidaJustify = &H1
    LucidaRight = &H2
    LucidaCenter = &H4
End Enum



'+----------------------------------------------------------------------+'
'+                             LAYOUT SETUP                             +'
'+----------------------------------------------------------------------+'
'Function: LucidaTextSetup
'   Returns a  string expression containing a  text setup with  a specific
'   layout.
'   Parameters: Text: A String expression specifying the text to setup the
'                   layout. If "Text" contains "Null", "Null" is returned.
'               Length: A numeric  expression specifying the width  of the
'                   layout. If  "Length" is not  greater than 0,  an error
'                   occurs.
'               ParagraphStyle (Optional): Specify the type of layout used
'                   to   setup   the   paragraphs    in   the   text.   If
'                   "ParagraphStyle" is  omitted, paragraphs  in text  are
'                   setup with left-style.
'               IsOneParagraph (Optional): A Boolean expression specifying
'                   if "Text" is considered as only one paragraph. Default
'                   value  is  "False":  Each   line  in  "Text"  makes  a
'                   paragraph.
'               ParagraphTab (Optional):  A numeric  expression specifying
'                   the number  of spaces to add  on the left side  of the
'                   text to  return. If "ParagraphTab"  is less than  0 or
'                   greater   than   "Length",   an   error   occurs.   If
'                   "ParagraphTab"   is   omitted,   two  cases:   1)   If
'                   "IsOneParagraph" is set to  "True" and "Text" contains
'                   more than  one line, "ParagraphTab"  is assumed  to be
'                   the tab of the second line. 2) In any other case, 0 is
'                   assumed.
'               FirstLineTab (Optional):  A numeric  expression specifying
'                   the number  of spaces to add  on the left side  of the
'                   first line  of each paragraph  of the text  to return.
'                   "FirstLineTab"     includes     "ParagraphTab".     If
'                   "FirstLineTab"  is   less  than  0  or   greater  than
'                   "Length",  an  error   occurs.  If  "FirstLineTab"  is
'                   omitted, it is assumed to be the tab of the first line
'                   for each paragraph in "Text".
'               LineSeparator (Optional): A string expression specifying a
'                   substring that represent a line separation. Default is
'                   vbCrLf (Chr(13) + Chr(10)).
'------------------------------------------------------------------------'
Function LucidaTextSetup(Text, Length As Long, Optional ParagraphStyle _
As LucidaStyle, Optional IsOneParagraph As Boolean, Optional _
ParagraphTab, Optional FirstLineTab, Optional LineSeparator As String = _
vbCrLf)
    Dim i As Long
    Dim Temp As String
    Dim Lines
    Dim PTab As Long
    'Split text into lines
    If IsNull(Text) Then
        LucidaTextSetup = Null
        Exit Function
    ElseIf Len(Text) = 0 Then
        Temp = Array("")
    Else
        Lines = Split(Text, LineSeparator)
    End If
    'If text is one paragraph...
    If IsOneParagraph Then
        'Calculate paragraph tab from second line
        If Not IsMissing(ParagraphTab) Then
            PTab = ParagraphTab
        ElseIf UBound(Lines) > 0 Then
            PTab = Len(Lines(1)) - Len(LTrim$(Lines(1)))
        End If
        'Concatenate lines into one paragraph
        Temp = Replace(Text, LineSeparator, " ")
        'Setup paragraph layout
        SetUpParagraph Temp, Length, ParagraphStyle, PTab, _
                       FirstLineTab, LineSeparator
    'If each line is a paragraph...
    Else
        'Setup layout for each line
        Temp = ""
        For i = 0 To UBound(Lines)
            SetUpParagraph Lines(i), Length, ParagraphStyle, _
                           ParagraphTab, FirstLineTab, LineSeparator
            Temp = Temp & IIf(i = 0, "", LineSeparator) & Lines(i)
        Next
    End If
    'Return value
    LucidaTextSetup = Temp
End Function

'------------------------------------------------------------------------'
'Sub: SetUpParagraph
'   Setup the layout of a paragraph.
'   Parameters: Text (Read/Write):  A  String  expression  specifying  the
'                   paragraph to setup the layout.
'               Length: A numeric  expression specifying the width  of the
'                   layout.
'               ParagraphStyle (Optional): Specify the type of layout used
'                   to  setup   the  paragraph.  If   "ParagraphStyle"  is
'                   omitted, paragraph is setup with left-style.
'               ParagraphTab (Optional):  A numeric  expression specifying
'                   the number  of spaces to add  on the left side  of the
'                   paragraph. If "ParagraphTab" is less than 0 or greater
'                   than "Length",  an error occurs. If  "ParagraphTab" is
'                   omitted, 0 is assumed.
'               FirstLineTab (Optional):  A numeric  expression specifying
'                   the number  of spaces to add  on the left side  of the
'                   first line  of the paragraph.  "FirstLineTab" includes
'                   "ParagraphTab". If  "FirstLineTab" is  less than  0 or
'                   greater   than   "Length",   an   error   occurs.   If
'                   "FirstLineTab" is omitted, it is assumed to be the tab
'                   of the first line of "Text".
'               LineSeparator (Optional): A string expression specifying a
'                   substring that represent a line separation. Default is
'                   vbCrLf (Chr(13) + Chr(10)).
'------------------------------------------------------------------------'
Private Sub SetUpParagraph(Text, Length As Long, ParagraphStyle As _
LucidaStyle, Optional ParagraphTab, Optional FirstLineTab, Optional _
LineSeparator As String)
    Dim Words
    Dim Position As Long
    Dim FLTab As Long
    Dim PTab As Long
    'Calculate first line tab
    If IsMissing(FirstLineTab) _
    Then FLTab = Len(Text) - Len(LTrim$(Text)) _
    Else: FLTab = CLng(FirstLineTab)
    'Calculate paragraph tab
    If IsMissing(ParagraphTab) _
    Then PTab = 0 _
    Else: PTab = CLng(ParagraphTab)
    'Remove left and right spaces
    Text = Trim$(Text)
    'Remove double-spaces
    Do While InStr(Text, "  ") > 0
        Text = Replace(Text, "  ", " ")
    Loop
    'Split text into an array of words
    If Len(Text) = 0 Then
        Words = Array("")
    Else
        Words = Split(Text)
    End If
    'Build first line
    Text = "": Position = 0
    AddLine Text, Words, Position, Length, _
            ParagraphStyle, FLTab, LineSeparator
    'Build other lines
    Do While Position <= UBound(Words)
        AddLine Text, Words, Position, Length, _
                ParagraphStyle, PTab, LineSeparator
    Loop
End Sub

'------------------------------------------------------------------------'
'Sub: AddLine
'   Add as much words as can contain a line to a paragraph.
'   Parameters: Text (Read/Write):  A  String  expression  specifying  the
'                   paragraph to add a line to.
'               Words(): An array  of strings containing the  words to add
'                   to the paragraph.
'               Position: A numeric expression  specifying the position of
'                   the next word to add to the paragraph.
'               Length: A numeric  expression specifying the width  of the
'                   layout.
'               ParagraphStyle: Specify the  type of layout used  to setup
'                   the paragraph.
'               LineTab:  A numeric  expression specifying  the number  of
'                   spaces to add on the left side of the line to add.
'               LineSeparator: A string expression  specifying a substring
'                   that represent a line separation.
'------------------------------------------------------------------------'
Private Sub AddLine(Text, Words, Position As Long, Length As Long, _
ParagraphStyle As LucidaStyle, LineTab As Long, LineSeparator As String)
    Dim Line As String
    Dim EOL As Boolean
    'I need to raise the error myself because:
    '1) If "LineTab" is negative, an error occurs in "Space$(LineTab)"
    '2) If  "LineTab"  is  greater  than  "Length",  an  error  occurs  in
    '   "Left$(Words(Position), Length - LineTab)"
    '3) If "Length" is negative, error (1) or (2) occurs
    '4) If "Length" is positive and  "LineTab" belongs to [0, "Length"[, a
    '   correct paragraph can be returned
    '5) Last  case  is "LineTab"  equal  to  "Length"  which leads  to  an
    '   everlasting loop
    If LineTab = Length Then Err.Raise 5
    'While there is still words to add and it's not the end of the line
    Do While Position <= UBound(Words) And Not EOL
        'If word can be added, add it and move to next
        If Len(Line) + Len(Words(Position)) + IIf(Len(Line) = 0, 0, 1) _
                <= Length - LineTab Then
            Line = Line & IIf(Len(Line) = 0, "", " ") & Words(Position)
            Position = Position + 1
        'If word cannot be added, set end of line
        Else
            EOL = True
        End If
    Loop
    'If no word fits in line
    If Len(Line) = 0 And EOL Then
        'Add length first characters of next word
        Line = Left$(Words(Position), Length - LineTab)
        Words(Position) = Mid$(Words(Position), Length - LineTab + 1)
    'Normal line to be setup
    Else
        'Do not setup justify for the last line
        If Position > UBound(Words) Then
            SetupLine Line, Length - LineTab, _
                      ParagraphStyle And Not LucidaJustify
        Else
            SetupLine Line, Length - LineTab, ParagraphStyle
        End If
    End If
    'Add new line to text
    Text = Text & IIf(Len(Text) = 0, "", LineSeparator) _
                & Space$(LineTab) & Line
End Sub

'------------------------------------------------------------------------'
'Sub: SetupLine
'   Setup the layout of a line.
'   Parameters: Line (Read/Write): A String expression specifying the line
'                   to setup the layout.
'               Length: A numeric  expression specifying the width  of the
'                   layout.
'               ParagraphStyle: Specify the  type of layout used  to setup
'                   the paragraph.
'------------------------------------------------------------------------'
Private Sub SetupLine(Line, Length As Long, ParagraphStyle As LucidaStyle)
    Dim i As Long
    Dim Words() As String
    Dim SpaceInLine As Long
    Dim SpaceToAdd As Long
    Dim SpaceAdded As Long
    Dim Spaces As String
    'If line has to be justified
    If Len(Line) > 0 And CBool(ParagraphStyle And LucidaJustify) Then
        'Split line into array of words
        Words = Split(Line)
        'Calculate number of spaces in line and to add
        SpaceInLine = UBound(Words) - LBound(Words)
        SpaceToAdd = Length - Len(Line)
        'Initialize line to first word
        Line = Words(LBound(Words))
        'Add other words one after the other
        For i = LBound(Words) + 1 To UBound(Words)
            'Build word separator
            Spaces = Space$(SpaceToAdd / SpaceInLine _
                            * (i - LBound(Words)) - SpaceAdded)
            SpaceAdded = SpaceAdded + Len(Spaces)
            'Concatenate line, word separator and word
            Line = Line & " " & Spaces & Words(i)
        Next
    End If
    'Setup line position
    If ParagraphStyle And LucidaRight Then
        Line = Space$(Length - Len(Line)) & Line
    ElseIf ParagraphStyle And LucidaCenter Then
        Line = Space$((Length - Len(Line)) / 2) & Line
    End If
End Sub



'+----------------------------------------------------------------------+'
'+                NON-BREAKING SPACES SMART REPLACEMENT                 +'
'+----------------------------------------------------------------------+'
'Function: NBSPSmartInsert
'   Returns a  string in  which multiple  spaces have  been replaced  by a
'   smart combination of spaces and non-breaking spaces.
'   Solution 1: Replace all spaces by  non-breaking spaces. That makes the
'       change  irreversible.  A  non-breaking  space  between  two  words
'       prevent them to be split in two lines. If all spaces are replaced,
'       it will  be impossible  to tell whether  a non-breaking  space was
'       user-defined or added by the function.
'   Solution 2:  Replace all  double spaces  by a  combination of  space +
'       non-breaking  space.  The  change  is  reversible  as  long  as  a
'       user-defined non-breaking space  combined with a space  is totally
'       useless. The  lack of that solution  is that when displayed  in an
'       editor, it will not be possible to use Ctrl+Arrow (that usualy tab
'       from word to word) because it will tab every two spaces.
'   Solution  3:  Replace  all  groups of  "n"  spaces  by  the  following
'       combination: space  + "n-2" non-breaking  spaces + space.  In case
'       there  are only  2  spaces  in the  group,  they  are replaced  by
'       non-breaking space  + space. This change  is reversible and  it is
'       possible  to   tab  from   word  to  word.   To  achieve   such  a
'       transformation, I  perform the  following replacements.  Caret (^)
'       and tilde  (~) represent  2 non-string  character, underscore  (_)
'       represents a non-breaking space:
'                           Text: "word                    word"
'           Replace "  " by "^~": "word^~^~^~^~^~^~^~^~^~^~word"
'           Replace "~^" by "__": "word^__________________~word"
'           Replace "^"  by " " : "word __________________~word"
'           Replace "~"  by " " : "word __________________ word"
'   Parameters: Text:  A String  expression specifying  the text  in which
'                   multiple space have to be replaced.
'               NBSP:  String  character  representing the  value  of  the
'                   non-breaking space character in the current system.
'------------------------------------------------------------------------'
Function NBSPSmartInsert(Text As String, NBSP As String) As String
    Dim NoStr1 As String, NoStr2 As String
    NoStr1 = Chr$(0)
    NoStr2 = Chr$(1)
    NBSPSmartInsert = Replace(Replace(Replace(Replace(Replace(Replace( _
                              Text, _
                              "  ", NoStr1 & NoStr2), _
                              NoStr2 & NoStr1, NBSP & NBSP), _
                              NoStr1, " "), _
                              NoStr2, " "), _
                              "   ", " " & NBSP & " "), _
                              "  ", NBSP & " ")
End Function

'------------------------------------------------------------------------'
'Function: NBSPSmartRemove
'   Returns  a  string in  which  useless  non-breaking spaces  have  been
'   replaced by spaces.
'   Parameters: Text:  A String  expression specifying  the text  in which
'                   useless non-breaking spaces have to be replaced.
'               NBSP:  String  character  representing the  value  of  the
'                   non-breaking space character in the current system.
'------------------------------------------------------------------------'
Function NBSPSmartReplace(Text As String, NBSP As String) As String
    NBSPSmartReplace = Text
    Do While InStr(NBSPSmartReplace, NBSP & " ") > 0
        NBSPSmartReplace = Replace(NBSPSmartReplace, NBSP & " ", "  ")
    Loop
    Do While InStr(NBSPSmartReplace, " " & NBSP) > 0
        NBSPSmartReplace = Replace(NBSPSmartReplace, " " & NBSP, "  ")
    Loop
End Function

Conclusion

J'ai tout fait pour que ma fonction soit la plus generale possible. Elle prend en compte ou non les retours a la ligne, et est capable d'analyser la mise en forme precedente pour y coller au mieux. Et elle conserve les espaces insecables (selon les conseils de Jean-Marc). Je vais m'en servir pour un projet de mise en forme de code VB. En attendant, utilisez la, notez la, trouvez les bugs, proposez des ameliorations et surtout dites le moi.
 

Fichier Zip

Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip

Historique

12 juillet 2006 18:21:42 :
Version 2.0 (2006 JULY 10 14:13) 1) Changement du nom du module 2) Correction de commentaires 3) Correction de la gestion des valeurs abherentes : Plutot que de renvoyer Null si la largeur de la mise en forme est negative, je laisse l'erreur se produire et l'utilisateur prendre ses dispositions. Il ne me parrait pas pertinent de renvoyer une quelconque valeur avec des parametres abherents. 4) La fonction GetLucidaTextSetup n'existe plus, il faut la remplacer par LucidaTextSetup qui n'est plus une procedure mais une fonction. 5) Suppression de la constante LINE_SEP = vbCrLf (C'est un parametre de la fonction principale) 6) Modification de la gestion des chaines vides ("") : Si un paragraphe est vide, il est quand meme tabule (cf comportement de Microsoft Word). 7) Ajout des fonctions NBSPSmartReplace et NBSPSmartInsert. Elles ajoutent des espaces insecables ou les remplacent de maniere reversibles et permettent de conserver au texte sa mise en forme meme si l'application qui l'affiche ignore les double espaces (comme l'afficheur de code de vbfrance).

Commentaires et avis

signaler à un administrateur
Commentaire de MadM@tt le 06/07/2006 17:50:34

Ola j'ai jamais vu un code avec autant de commentaires ^^, y'en a plus que de code
C'est peut etre meme trop à des moments non ? Enfin c'est surtout que c'est en anglais, et qu'ici ça passe moyen les trucs en anglais (perso ça ne me brule pas les yeux, mais faut penser à ceux qui ne comprenne pas cette langue, ou alors pas suffisamment). Enfin je pense que tu ferais mieux de rédiger les commentaires en français pour ce site.

signaler à un administrateur
Commentaire de jean_marc_n2 le 07/07/2006 13:30:42

Hello,

pas mal du tout. QQ remarques:
- Les gros blocs de commentaires ne facilitent pas la lecture. A ce niveau de détail, on préfère en général rédiger un document séparé, contenant les specifications et les les exemples. Dans le code, on se contente alors des commentaires techniques et on fait référence à la documentation. Eventuellement, on peut éviter de trainer un document externe en rédigeant la doc dans un module séparé, qui ne contient QUE la spec et les exemples.
- Pourquoi avoir employer partout "Lucida"? C'est peu judicieux, car Lucida n'est pas la seule police à empattement fice. Il eut été sans doute plus naturel de remplacer "Lucida" par "FixedWidth", qui aurait été plus générique.
- Au niveau présentation, tout est ok, mais amha, tu gagnerais en lisibilité en écrivant d'écrire tes instructions immédiatement derrière le Then ou derrière le Else. De plus, si tu devais ajouter des instructions supplémentaires, tu cours le risque d'oublier le endif et d'obtenir qq chose qui peut être difficile à débugger. On préfère en général:
If tutu Then
    ' des trucs
    ' des machins
Else
    ' des bidules
Endif

Qui plus est, la structure du code devient immédiatement visible. La lecture est facilitée, le débuggage ou le suivi pas à pas est plus agréable, on peut placer plus facilement des breakpoints, etc.

Je mets donc un 7, car d'un point de vue fonctionnel, c'est tout à fait ok.

Amicalement;

signaler à un administrateur
Commentaire de santiago69 le 09/07/2006 17:56:27

Salut MadM@tt,
Desole pour l'anglais, en fait je bosse sur des projets avec des turcs, des indiens et un reunionnais. Donc quand l'un de nous cree un module, il le document entierement en anglais. Je poste quand meme sur vbfrance parceque certaines personnes peuvent quand meme etre interessees. Et puis faut pas oublier que 80% de la doc mondiale sur l'informatique est en anglais.
Pour les commentaires, meme pb, avec mon equipe, on cree un cahier des charge et on s'echange des modules qui doivent etre parfaitement documentes (c'est la MSDN de nos applications).
Donc desole 2 fois mais ca risque de pas beaucoup changer.
Merci quand meme d'avoir poste un commentaire.

Salut Jean-Marc,
Voir plus haut pour l'explication des tartines de commentaires.
Je suis d'accord avec toi pour Lucida, en fait l'explication est tres simple. Je trouvais le mot Lucida joli et Fixed-width trop ringard. C'est un peu comme donner un nom plutot qu'un numero a une voiture (Espace au lieu de 806). Sur ce point je te l'accorde, je suis aux antipodes de la rigueur ! Mais vraiment, Lucida c'est joli, ca fait prenom de femme nordique... Bon bon bon j'arrete les conneries.
Pour la presentation, j'ai bien compris ton conseil, j'ai deja commence a rediger d'autres modules en utilisant la forme standard de If, Then, Else, End If. Je verrais si j'ai le temps de reecrire celui la.
Merci pour la note.

A plus
Santiago

signaler à un administrateur
Commentaire de jean_marc_n2 le 09/07/2006 18:05:24

Hello,

Les commentaires en anglais sont un standard, tu as entièrement raison. Moi je travaille avec des anglais, des américains, des sud-africains, des portugais, etc. il est évident que l'on commente tout en anglais! Un programmeur qui aujourd'hui ne peut pas lire et écrire l'anglais technique ne trouvera pas un boulot sérieux, VBFrance ou pas.

Pour "Lucida", ton explication est simple mais parfaite :-)

Amicalement,

signaler à un administrateur
Commentaire de santiago69 le 09/07/2006 18:15:11

Bon ben tout va bien alors,
Quand tu disais beaucoup, moi perso je n'ai que 2 polices a largeur fixe dans mon ordi : Lucida et Courier (la deuxieme possibilite faisait vraiment trop tennis-man a mon gout lol ;o)

signaler à un administrateur
Commentaire de MadM@tt le 09/07/2006 18:18:50

Salut,

Merci d'avoir pris le temps d'expliquer ces choix, au niveau de la langue anglaise par contre je suis d'accord que c'est un standard et que tout programmeur qui se respecte doit connaitre l'anglais et savoir bosser avec, c'est sur je suis d'accord, et moi l'anglais ne me gène pas.
Simplement ici c'est un site d'echange de programmation en français. Et beaucoup des membres sont des débutants, généralement jeunes, et il y a également beaucoup de développeurs amateurs. Ce site a été créé pour partager en français, car il existe déjà pas mal de site en anglais sur le meme sujet.
Donc je pense qu'il faut quand meme différencier la programmation pour le boulot, qui doit respecter des standards, et la programmation amateur qui cherche avant tout à apprendre et enseigner.

Enfin ceci dit, il faut nuancer, c'est pas la fin du monde pour une source, personne va mourir. Et au pire si qqn ne comprend pas une fonction y'aura du monde pour lui expliquer.

Et au niveau du Lucida, j'adore ce genre de choix lol ;)

Bonne prog

signaler à un administrateur
Commentaire de MadM@tt le 09/07/2006 18:20:35

Oh et je remarque qqch que je n'avais jamais vu :
Option Base 1
Option Compare Text
A quoi servent ces 2 lignes ?

signaler à un administrateur
Commentaire de jean_marc_n2 le 09/07/2006 18:27:55

Hello,

Option Base 1 précise que les tableaux commencent à l'indice 1, au lieu de zéro par défaut.

Option Compare text permet lors de la comparaison de texte de faire que
(A=a) < (E=e) < etc
alors que par défaut (Option Compare Binary), c'est:
A<E<A<a

Utile quand on cherche à trier des éléments en orde Lexicographique.

Les détails de tout cela ici:
http://msdn.microsoft.com/library/en-us/vbenlr98/html/vastmOptionCompare.asp

et la:
http://msdn.microsoft.com/library/en-us/vbenlr98/html/vastmOptionBase.asp

signaler à un administrateur
Commentaire de jean_marc_n2 le 09/07/2006 18:28:37

oups je voulais bien sur écrire:
A<E<a<e

signaler à un administrateur
Commentaire de MadM@tt le 09/07/2006 18:30:08

Merci pour les infos ;)

signaler à un administrateur
Commentaire de santiago69 le 09/07/2006 19:11:10

Salut MadM@tt,

Option Base 1
C'est une erreur de ma part, d'habitude je met Option Base 0 qui ne sert a rien puisque c'est la valeur par defaut.
    Pourquoi ?
La fonction Split() renvoi TOUJOURS un tableau qui commence a 0.
La fonction Array() renvoi un tableau qui comment a Option Base.
De plus la fontion Split renvoi un tableau vide si la chaine a decoupe est vide ("").
Donc pour ne pas avoir d'erreur lorsque je ne sais pas si la chaine est vide (par exemple un ligne vide qu'on essaierait de decouper en mots), j'effectue les actions suivantes
If Text = "" Then
    Tableau = Array("")
Else
    Tableau = Split(Text)
End If
En l'occurence, j'ai oublie d'ecrire ca dans ce code.

Option Compare Text
L'option par defaut est Option Compare Binary, en precisant Option Compare Text, on evite de reecrire ce choix dans les fonctions suivantes : Split(), InStr(), Replace(), etc...
En simple, Option Compare Binary est sensible a la casse, pas Option Compare Text.
Ce module n'utilise que Split() et a ma connaissance, l'espace et le retour a la ligne sont de toute facon non sensibles a la casse ;o)

signaler à un administrateur
Commentaire de santiago69 le 09/07/2006 19:12:49

ah ben j'avais pas vu la reponse, desole, j'ai pas une connexion d'enfer a Istanbul.

signaler à un administrateur
Commentaire de santiago69 le 12/07/2006 18:22:09

je poste la version 2.0

Ajouter un commentaire

Discussions en rapport avec ce code source dans le forum

Selection de texte [ par hub ] Bonjour à tous,Quelqu'un connait t-il une méthode pour selectionner automatiquement 1 paragraphe d'un Textbox :Lorsque l'utilisateur clique sur un mot Justification de texte [ par Gringo ] Est-il possible de justifier du texte dans un Textbox ou un Richtextbox? Attention, j'ai dit justifier et non centrer ou aligner à droite ou à gauche. justifier du texte? [ par phildarvador ] Salut !je cherche à justifier un bloc de texte en vb.net. Plus précisement, je veux imprimer: j'arrive a le faire, mais ce serait plus jouli si c'etai Alignement vertical de texte dans une msflexgrid [ par JDenis ] Bonjour !Je sais positionner du texte dans des cellules d'une msflexgrid mais j'ignore la manière d'aligner du texte verticalement ou avec une orienta Coment fait-on pour justifier du texte en vb.net dans une RichTextBox? [ par ArtLeeRoy ] IGotNoPowa-IWannaKnow spreadsheet, alignement du texte [ par SebDesPieux ] Bonjour à tous. J'utilise un spreadsheet sous vb, et je n'arrive pas à écrire du texte verticalement. Pouvez vous m'aidez please ? Alignement à droite dans fichier texte [ par Biboune ] Bonjour,J'ai un fichier Excel avec 3 colonnes :la première est composée de chiffresla seconde est videla troisième est composée de montant avec 2 déci Sélectionner un texte d'un point à un autre [ par grivel ] Salut &#224; tous !J'aimerai en fait s&#233;lectionner une partie d'un texte dans un texte plus grand.Par exemple dans une page, un paragraphe seuleme listview et alignement de texte [ par moi4975 ] voila mon petit probl&#232;me, ca fait 1 h que je cherche et je ne trouve pas comment align&#233; le texte &#224; gauche dans une colonne de ma listvi alignement du texte à imprimer [ par YPMN ] salut!mon problème se presente  comme suit:Que puis-je faire pour imprimer un texte avec comme alignement: "A DROITE" par exemple, contrairement au ce


Nos sponsors

Sondage...

CalendriCode

Juillet 2009
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
2728293031  

Consulter la suite du CalendriCode

Téléchargements

Logiciels à télécharger sur le même thème :

Comparez les prix Nouvelle version

Photothèque Nouveau !



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,406 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.