home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / Megafan_Sc2113845252008.psc / ClsMots.cls < prev    next >
Text File  |  2007-02-28  |  17KB  |  475 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "ClsMots"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15.  
  16. Private TabResultat() As String
  17. Private p As ClsPile
  18. Private StrJocker As String
  19. Private mDico As ClsDictionnaire
  20. Private PtrResultat As Long
  21.  
  22. Public Function IsMotexiste(StrMot As String, Optional PtrPere As Long) As Boolean
  23.  
  24.     Dim PtrFils As Long
  25.     Dim PtrPereBackup As Long
  26.     Dim Index As Integer
  27.     Dim lg As Integer
  28.     Dim i As Integer
  29.     
  30.     StrMot = UCase(StrMot)
  31.     If PtrPere = 0 Then
  32.         Index = Asc(Left(StrMot, 1)) - 64
  33.         PtrPere = Index
  34.     End If
  35.     lg = Len(StrMot)
  36.     
  37.     For i = 2 To lg
  38.         Index = Asc(Mid(StrMot, i, 1)) - 64
  39.         PtrFils = mDico.GetNoeud(PtrPere, Index)
  40.         If PtrFils = 0 Then Exit Function
  41.         PtrPereBackup = PtrPere
  42.         PtrPere = PtrFils
  43.     Next
  44.     
  45.     If mDico.MotExisteByNoeud(PtrPereBackup, Index) Then IsMotexiste = True
  46.  
  47. End Function
  48.  
  49. Public Function IsMotCommencePar(StrMot As String, Optional PtrPere As Long) As Long
  50.  
  51.     Dim PtrFils As Long
  52.     Dim PtrPereBackup As Long
  53.     Dim Index As Integer
  54.     Dim lg As Integer
  55.     Dim i As Integer
  56.     
  57.     If PtrPere = 0 Then
  58.         Index = Asc(Left(StrMot, 1)) - 64
  59.         PtrPere = Index
  60.     End If
  61.     lg = Len(StrMot)
  62.     
  63.     For i = 2 To lg
  64.         Index = Asc(Mid(StrMot, i, 1)) - 64
  65.         PtrFils = mDico.GetNoeud(PtrPere, Index)
  66.         If PtrFils = 0 Then Exit Function
  67.         PtrPereBackup = PtrPere
  68.         PtrPere = PtrFils
  69.     Next
  70.     
  71.     IsMotCommencePar = PtrPere
  72.  
  73. End Function
  74.  
  75. Public Function GetMot(LngIndex As Long) As String
  76.  
  77.     GetMot = TabResultat(LngIndex)
  78.  
  79. End Function
  80.  
  81. Public Function TotalMots() As Long
  82.  
  83.     TotalMots = UBound(TabResultat)
  84.  
  85. End Function
  86.  
  87. Public Function AnaGramme(StrMot As String, Optional MotComplet As String, Optional PtrArbre As Long) As Long
  88.  
  89.     Dim i As Long
  90.     Dim p As Integer
  91.     ReDim TabResultat(0)
  92.     ReDim TabResultat(MAXMOTS)
  93.     PtrResultat = 1
  94.     StrJocker = ""
  95.     
  96.     '//////// Mettre les ? α la fin de StrMot/////////////////////////////
  97.     i = 0
  98.     Do
  99.         p = InStr(StrMot, "?")
  100.         If p Then
  101.             StrMot = Left(StrMot, p - 1) & Right(StrMot, Len(StrMot) - p)
  102.             i = i + 1
  103.         Else
  104.             Exit Do
  105.         End If
  106.     Loop While 1
  107.     StrMot = StrMot & String(i, "?")
  108.     '////////////////////////////////////////////////////////////////////
  109.     
  110.     AnaGrammeP UCase(StrMot)
  111.    
  112.     For i = 1 To UBound(TabResultat)
  113.         If TabResultat(i) = "" Then Exit For
  114.     Next
  115.     ReDim Preserve TabResultat(i - 1)
  116.     
  117.     Me.ClasserMotsParLongueur
  118.     
  119.     AnaGramme = i - 1
  120.  
  121. End Function
  122.  
  123. Private Sub AnaGrammeP(StrMot As String, Optional MotComplet As String, Optional PtrArbre As Long)
  124.         
  125.     Dim i As Integer
  126.     Dim IndexFils As Integer
  127.     Dim TempMot As String
  128.     Dim Lettre As String
  129.     Dim LettresUtilisees  As String
  130.     Dim k As Integer
  131.     
  132.     
  133.     For i = 1 To Len(StrMot)
  134.         Lettre = Mid(StrMot, i, 1)
  135.         If Lettre <> "?" Then
  136.             If InStr(LettresUtilisees, Lettre) = 0 Then
  137.                 IndexFils = Asc(Left(Lettre, 1)) - 64
  138.                 MotComplet = MotComplet & Lettre
  139.                 LettresUtilisees = LettresUtilisees & Lettre
  140.                 
  141.                 TempMot = StrMot
  142.                 TempMot = Left(TempMot, i - 1) & Right(TempMot, Len(TempMot) - i)
  143.                 
  144.                 If mDico.MotExisteByNoeud(PtrArbre, IndexFils) Then
  145.                     AjouteListe MotComplet, StrJocker
  146.                 End If
  147.             
  148.                 If TempMot <> "" Then
  149.                     If mDico.GetNoeud(PtrArbre, IndexFils) <> 0 Then
  150.                         AnaGrammeP TempMot, MotComplet, mDico.GetNoeud(PtrArbre, IndexFils)
  151.                     End If
  152.                 End If
  153.                 MotComplet = Left(MotComplet, Len(MotComplet) - 1)
  154.             End If
  155.         Else
  156.             For k = 65 To 90 ' A to Z
  157.                 Lettre = Chr(k)
  158.                 If InStr(LettresUtilisees, Lettre) = 0 Then
  159.                     IndexFils = Asc(Left(Lettre, 1)) - 64
  160.                     MotComplet = MotComplet & Lettre
  161.                     StrJocker = StrJocker & Lettre
  162.                     LettresUtilisees = LettresUtilisees & Lettre
  163.                     
  164.                     TempMot = StrMot
  165.                     TempMot = Left(TempMot, i - 1) & Right(TempMot, Len(TempMot) - i)
  166.                 
  167.                     If mDico.MotExisteByNoeud(PtrArbre, IndexFils) Then
  168.                         AjouteListe MotComplet, StrJocker
  169.                     End If
  170.                 
  171.                     If TempMot <> "" Then
  172.                         If mDico.GetNoeud(PtrArbre, IndexFils) <> 0 Then
  173.                             AnaGrammeP TempMot, MotComplet, mDico.GetNoeud(PtrArbre, IndexFils)
  174.                         End If
  175.                     End If
  176.                     MotComplet = Left(MotComplet, Len(MotComplet) - 1)
  177.                     StrJocker = Left(StrJocker, Len(StrJocker) - 1)
  178.                 End If
  179.             Next
  180.         End If
  181.     Next
  182.     
  183. End Sub
  184.  
  185. Public Function AnaGrammSelonMasque(StrMasque As String, StrMot As String, IntLgMini As Integer) As Long
  186.     
  187.     ReDim TabResultat(0)
  188.     ReDim TabResultat(MAXMOTS)
  189.     PtrResultat = 1
  190.     StrJocker = ""
  191.     Dim i As Long
  192.     Dim p As Integer
  193.     
  194.     '//////// Mettre les ? α la fin de StrMot/////////////////////////////
  195.     i = 0
  196.     Do
  197.         p = InStr(StrMot, "?")
  198.         If p Then
  199.             StrMot = Left(StrMot, p - 1) & Right(StrMot, Len(StrMot) - p)
  200.             i = i + 1
  201.         Else
  202.             Exit Do
  203.         End If
  204.     Loop While 1
  205.     StrMot = StrMot & String(i, "?")
  206.     '////////////////////////////////////////////////////////////////////
  207.     
  208.     
  209.     AnaGrammSelonMasqueP UCase(StrMasque), UCase(StrMot), IntLgMini
  210.  
  211.     For i = 1 To UBound(TabResultat)
  212.         If TabResultat(i) = "" Then Exit For
  213.     Next
  214.     ReDim Preserve TabResultat(i - 1)
  215.         
  216.     AnaGrammSelonMasque = i - 1
  217.  
  218. End Function
  219.  
  220.  
  221. Private Sub AnaGrammSelonMasqueP(StrMasque As String, StrMot As String, IntLgMini As Integer, Optional MotComplet As String, Optional PtrArbre As Long, Optional PtrMasque As Integer)
  222.         
  223.     Dim i As Integer
  224.     Dim IndexFils As Integer
  225.     Dim TempMot As String
  226.     Dim Lettre As String
  227.     Dim LettresUtilisees  As String
  228.     Dim k As Integer
  229.     Dim SavePtr As Long
  230.     Dim StrTemp As String
  231.     
  232.         
  233.     For i = 1 To Len(StrMot)
  234.         Lettre = Mid(StrMot, i, 1)
  235.         If Lettre <> "?" Then
  236.             If InStr(LettresUtilisees, Lettre) = 0 Then
  237.                 If PtrMasque < Len(StrMasque) Then
  238.                     PtrMasque = PtrMasque + 1
  239.                     If Mid(StrMasque, PtrMasque, 1) <> "*" Then
  240.                         Do
  241.                             Lettre = Mid(StrMasque, PtrMasque, 1)
  242.                             IndexFils = Asc(Left(Lettre, 1)) - 64
  243.                             If mDico.GetNoeud(PtrArbre, IndexFils) <> 0 Then
  244.                                 MotComplet = MotComplet + Lettre
  245.                                 PtrMasque = PtrMasque + 1
  246.                                 If mDico.MotExisteByNoeud(PtrArbre, IndexFils) Then
  247.                                     If Len(MotComplet) >= IntLgMini Then
  248.                                         AjouteListe MotComplet, StrJocker
  249.                                     End If
  250.                                 End If
  251.                                 
  252.                                 p.Push PtrArbre
  253.                                 PtrArbre = mDico.GetNoeud(PtrArbre, IndexFils)
  254.                                 
  255.                                 If Len(MotComplet) < Len(StrMasque) Then
  256.                                     Lettre = Mid(StrMot, i, 1)
  257.                                 Else
  258.                                     PtrMasque = PtrMasque - 1
  259.                                     Lettre = ""
  260.                                     Exit Do
  261.                                 End If
  262.                             Else
  263.                                 PtrMasque = PtrMasque - 1
  264.                                 Lettre = ""
  265.                                 Exit Do
  266.                             End If
  267.                             
  268.                         Loop While Mid(StrMasque, PtrMasque, 1) <> "*"
  269.                     End If
  270.  
  271.                     If Lettre <> "" Then
  272.                         MotComplet = MotComplet & Lettre
  273.                         IndexFils = Asc(Left(Lettre, 1)) - 64
  274.                         LettresUtilisees = LettresUtilisees & Lettre
  275.                         
  276.                         TempMot = StrMot
  277.                         TempMot = Left(TempMot, i - 1) & Right(TempMot, Len(TempMot) - i)
  278.                         
  279.                         If mDico.MotExisteByNoeud(PtrArbre, IndexFils) Then
  280.                             If Len(MotComplet) >= IntLgMini Then
  281.                                 AjouteListe MotComplet, StrJocker
  282.                             End If
  283.                         End If
  284.                     
  285.                         'If TempMot <> "" Then
  286.                             If PtrMasque < Len(StrMasque) Then
  287.                                 If mDico.GetNoeud(PtrArbre, IndexFils) <> 0 Then
  288.                                     AnaGrammSelonMasqueP StrMasque, TempMot, IntLgMini, MotComplet, mDico.GetNoeud(PtrArbre, IndexFils), PtrMasque
  289.                                 End If
  290.                             End If
  291.                         'End If
  292.                         MotComplet = Left(MotComplet, Len(MotComplet) - 1)
  293.                         PtrMasque = PtrMasque - 1
  294.                     End If
  295.                 End If
  296.             End If
  297.         Else
  298.             For k = 65 To 90 ' A to Z
  299.                 DoEvents '<---------------------------------------- Indispensable
  300.                 Lettre = Chr(k)
  301.                 If InStr(LettresUtilisees, Lettre) = 0 Then
  302.                     If PtrMasque < Len(StrMasque) Then
  303.                         PtrMasque = PtrMasque + 1
  304.                         If Mid(StrMasque, PtrMasque, 1) <> "*" Then
  305.                             Do
  306.                                 'DoEvents
  307.                                 Lettre = Mid(StrMasque, PtrMasque, 1)
  308.                                 IndexFils = Asc(Left(Lettre, 1)) - 64
  309.                                 If mDico.GetNoeud(PtrArbre, IndexFils) <> 0 Then
  310.                                     MotComplet = MotComplet + Lettre
  311.                                     PtrMasque = PtrMasque + 1
  312.                                     If mDico.MotExisteByNoeud(PtrArbre, IndexFils) Then
  313.                                         If Len(MotComplet) >= IntLgMini Then
  314.                                             AjouteListe MotComplet, StrJocker
  315.                                         End If
  316.                                     End If
  317.                                     
  318.                                     p.Push PtrArbre
  319.                                     PtrArbre = mDico.GetNoeud(PtrArbre, IndexFils)
  320.                                     
  321.                                     If Len(MotComplet) < Len(StrMasque) Then
  322.                                         Lettre = Mid(StrMot, i, 1)
  323.                                         Lettre = Chr(k)
  324.                                     Else
  325.                                         PtrMasque = PtrMasque - 1
  326.                                         Lettre = ""
  327.                                         Exit Do
  328.                                     End If
  329.                                 Else
  330.                                     PtrMasque = PtrMasque - 1
  331.                                     Lettre = ""
  332.                                     Exit Do
  333.                                 End If
  334.                                 
  335.                             Loop While Mid(StrMasque, PtrMasque, 1) <> "*"
  336.                         End If
  337.                         
  338.  
  339.                         If Lettre <> "" Then
  340.                         
  341.                             StrJocker = StrJocker & Lettre
  342.                             MotComplet = MotComplet & Lettre
  343.                             IndexFils = Asc(Left(Lettre, 1)) - 64
  344.                             LettresUtilisees = LettresUtilisees & Lettre
  345.                             
  346.                             TempMot = StrMot
  347.                             TempMot = Left(TempMot, i - 1) & Right(TempMot, Len(TempMot) - i)
  348.                             
  349.                             If mDico.MotExisteByNoeud(PtrArbre, IndexFils) Then
  350.                                 If Len(MotComplet) >= IntLgMini Then
  351.                                     AjouteListe MotComplet, StrJocker
  352.                                 End If
  353.                             End If
  354.                         
  355.                             'If TempMot <> "" Then
  356.                                 If PtrMasque < Len(StrMasque) Then
  357.                                     If mDico.GetNoeud(PtrArbre, IndexFils) <> 0 Then
  358.                                         AnaGrammSelonMasqueP StrMasque, TempMot, IntLgMini, MotComplet, mDico.GetNoeud(PtrArbre, IndexFils), PtrMasque
  359.                                     End If
  360.                                 End If
  361.                             'End If
  362.                             MotComplet = Left(MotComplet, Len(MotComplet) - 1)
  363.                             PtrMasque = PtrMasque - 1
  364.                             StrJocker = Left(StrJocker, Len(StrJocker) - 1)
  365.                         End If
  366.                     End If
  367.                 End If
  368.                 'StrJocker = Left(StrJocker, Len(StrJocker) - 2)
  369.             Next
  370.         End If
  371.     Next
  372.     
  373.     If MotComplet <> "" Then
  374.         If Mid(StrMasque, Len(MotComplet), 1) <> "*" Then
  375.             Do
  376.                 MotComplet = Left(MotComplet, Len(MotComplet) - 1)
  377.                 PtrMasque = PtrMasque - 1
  378.                 p.Pop PtrArbre
  379.                 If MotComplet = "" Then Exit Do
  380.             Loop While Mid(StrMasque, Len(MotComplet), 1) <> "*"
  381.         End If
  382.         
  383.         If StrMot = "" Then
  384.             If Len(MotComplet) < Len(StrMasque) Then
  385.                 StrTemp = Right(StrMasque, Len(StrMasque) - Len(MotComplet))
  386.                 If InStr(StrTemp, "*") = 0 Then
  387.                     If IsMotexiste(MotComplet & StrTemp) Then
  388.                         If Len(MotComplet) >= IntLgMini Then
  389.                             AjouteListe MotComplet, StrJocker
  390.                         End If
  391.                     End If
  392.                 End If
  393.             End If
  394.         End If
  395.     End If
  396.     
  397. End Sub
  398.  
  399. Private Sub AjouteListe(StrMot As String, Optional StrJocker As String)
  400.         
  401.     If StrJocker <> "" Then
  402.         TabResultat(PtrResultat) = StrMot & " (" & StrJocker & ")"
  403.     Else
  404.         TabResultat(PtrResultat) = StrMot
  405.     End If
  406.     PtrResultat = PtrResultat + 1
  407.     
  408. End Sub
  409.  
  410. Public Sub ClasserMotParOrdreAlphabetique()
  411.  
  412.     Dim i As Long
  413.     Dim j As Long
  414.     Dim StrTemp As String
  415.     
  416.     If UBound(TabResultat) = 0 Then Exit Sub
  417.     If UBound(TabResultat) > 10000 Then
  418.         MsgBox "Il y a " & CStr(UBound(TabResultat)) & " solutions, veuillez prΘciser votre recherche !", vbExclamation
  419.         Exit Sub
  420.     End If
  421.  
  422.     For i = 1 To UBound(TabResultat)
  423.         For j = i + 1 To UBound(TabResultat)
  424.             If j <> i Then
  425.                 If TabResultat(j) < TabResultat(i) Then
  426.                     StrTemp = TabResultat(j)
  427.                     TabResultat(j) = TabResultat(i)
  428.                     TabResultat(i) = StrTemp
  429.                 End If
  430.             End If
  431.         Next
  432.     Next
  433.  
  434. End Sub
  435.  
  436. Public Sub ClasserMotsParLongueur()
  437.  
  438.     Dim i As Long
  439.     Dim j As Long
  440.     Dim StrTemp As String
  441.     Dim LgMot As Integer
  442.     Dim Debut As Long
  443.     
  444.     If UBound(TabResultat) = 0 Then Exit Sub
  445.     If UBound(TabResultat) > 10000 Then
  446.         MsgBox "Il y a " & CStr(UBound(TabResultat)) & " solutions, veuillez prΘciser votre recherche !", vbExclamation
  447.         Exit Sub
  448.     End If
  449.     
  450.     For i = 1 To UBound(TabResultat)
  451.         For j = 1 To UBound(TabResultat)
  452.             If Len(TabResultat(j)) < Len(TabResultat(i)) Then
  453.                 StrTemp = TabResultat(j)
  454.                 TabResultat(j) = TabResultat(i)
  455.                 TabResultat(i) = StrTemp
  456.             End If
  457.         Next
  458.     Next
  459. End Sub
  460.  
  461. Private Sub Class_Initialize()
  462.     
  463.     Set p = New ClsPile
  464.     p.InitPile (50)
  465.       
  466. End Sub
  467.  
  468. Property Let Dictionnaire(Dico As ClsDictionnaire)
  469.  
  470.    Set mDico = Dico
  471.    
  472. End Property
  473.  
  474.  
  475.