Comprendre une macro qui n'est pas de moi

Sanegone

XLDnaute Nouveau
Bonjour,

Je cherchais à faire de la saisie semi automatique dans une combobox et je suis tombé sur ça :

Code:
    ' M O D U L E
    '--------------------------------------------------------------------------------
    ' www.idev.fr.st
    '
    ' Syntax
    ' ------
    ' In the CHANGE event of your ComboBox, put in the following line
    ' iSenseChange YourComboBoxName
    ' Where "YourComboBoxName" is the name of the ComboBox associated with the event.
    '
    ' In the KEYPRESS event of your ComboBox, put in the following line
    ' iSenseKeyPress YourComboBoxName, KeyAscii
    ' Where "YourComboBoxName" is the name of the ComboBox associated with the event.'
    '
    ' ADAPTED FROM :
    '--------------------------------------------------------------------------------
    ' IntelliSense for VB the TextBox Control.
    ' Danny Young
    ' dan@mydan.com
    ' http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=9313&lngWId=1
    '--------------------------------------------------------------------------------
    Option Explicit
    Global WasDelete As Boolean
    Public Function IntelliSense(cBox As ComboBox, AddRecord As Boolean) As String
    Dim i As Integer
    Dim Done As Boolean
    If AddRecord Then
    'Pour ajouter le texte dans la ComboBox
    'cBox.AddItem cBox.Text
    Else
    ' For i = 0 To cBox.ListCount And Done = False
    For i = cBox.ListCount To 0 Step -1 And Done = False
    If UCase(cBox.Text) = Mid(RTrim(UCase(cBox.List(i))), 1, Len(cBox.Text)) Then
    IntelliSense = RTrim(cBox.List(i))
    End If
    Next i
    End If
    End Function
    Public Sub iSenseChange(cBox As ComboBox)
    Dim iStart As Integer
    Dim iSense As String
    iStart = cBox.SelStart
    iSense = IntelliSense(cBox, False)
    If iSense <> "" And Not WasDelete Then
    cBox.Text = iSense
    cBox.SelStart = iStart
    cBox.SelLength = Len(cBox.Text) - iStart
    End If
    End Sub
    Public Sub iSenseKeyPress(cBox As ComboBox, KeyAscii As Integer)
    If KeyAscii = 13 And cBox.Text <> "" Then
    IntelliSense cBox, True
    ElseIf KeyAscii = 8 Then
    WasDelete = True
    Else
    WasDelete = False
    End If
    End Sub

bien joli tout ça cependant il y'a une partie que je ne comprend pas :

For i = cBox.ListCount To 0 Step -1 And Done = False

Que veux dire exactement ce "And Done" ?

Pour i est égal cbox.listCount jusqu'à 0 en ajoutant à chaque fois -1 -> Pas de soucis mais And Done je vois pas : /
 

CBernardT

XLDnaute Barbatruc
Re : Comprendre une macro qui n'est pas de moi

Bonjour à tous,

Done semble être une variable Boolean. Les variables de type Boolean ne peuvent avoir pour valeur que True ou False. Elles expriment un changement d'état VRAI/FAUX. On Utilise les mots clés True et False pour les faire passer d'un état à l'autre.
 

tototiti2008

XLDnaute Barbatruc
Re : Comprendre une macro qui n'est pas de moi

Bonjour Sanegone, bonjour CBernardT :)

Bien que je ne connaissais pas cette écriture dans un For, il semble que
For i = cBox.ListCount To 0 Step -1 And Done = False
fait que si la variable Done est égale à False, on fait la boucle, sinon la boucle n'a pas lieu
personnellement j'aurais mis un If autour de la boucle mais c'est plus long à taper
 

Discussions similaires

Réponses
6
Affichages
311

Statistiques des forums

Discussions
312 345
Messages
2 087 470
Membres
103 551
dernier inscrit
d3vi