Hello everyone,
I have a trouble to run one of my macro while using a dictionary. Here is how I initialize it (Sorry some of my variables and comments are in french) :
Global dictGlobal As Variant
'Global oFinishedDial As Object
Global iRow As Integer
Global Const Tolerance As Double = 0.00 'seuil de tolérance pour écart
’ Initialisation du dictionnaire global pour stocker les numéros de compte et leurs feuilles
Sub InitializeDictionaries()
’ Appel de la librairie ScriptForge
GlobalScope.BasicLibraries.LoadLibrary(“ScriptForge”)
dictGlobal = CreateScriptService(“Dictionary”)
MsgBox “Dictionnaire initialisé”
End Sub
’ Fonction pour vérifier et initialiser le dictionnaire si nécessaire
Function EnsureDictionaryInitialized() As Boolean
If IsNull(dictGlobal) Or IsEmpty(dictGlobal) Then
InitializeDictionaries()
EnsureDictionaryInitialized = Not (IsNull(dictGlobal) Or IsEmpty(dictGlobal))
Else
EnsureDictionaryInitialized = True
End If
End Function
Then I call the sub inside one of my sub :
Sub CompareAndCreateSheets
' Vérifiez si le dictionnaire est initialisé
If Not EnsureDictionaryInitialized() Then
MsgBox "Le dictionnaire global n'a pas pu être initialisé.", 48, "Erreur"
Exit Sub
End If
…(Then more codes in the middle…)
’ I Have an exception here while i try to verifie if the element is inside the dictionary
If Not bFound Then
WriteRowToSheet(oSheet1, aOrdonnateurData(i), iRowOrdoDiff)
'Ajouter au dictionnaire
Dim NumCompteAbsentString As String
Dim NumCompteAbsent As String
NumCompteAbsentString = CStr(aOrdonnateurData(i)(iOrdNumInvent))
NumCompteAbsent = Cstr(CleanStringValue(NumCompteAbsentString))
If Not dictGlobal.Exists(NumCompteAbsent) Then
dictGlobal.Add(NumCompteAbsent, CreateScriptService("Dictionary"))
End If
If Not dictGlobal(NumCompteAbsent).Exists("OrdNumInvent_Absent") Then
dictGlobal(NumCompteAbsent).Add("OrdNumInvent_Absent", Array())
End If
Dim ordArray As Variant
ordArray = dictGlobal(NumCompteAbsent)("OrdNumInvent_Absent")
ordArray = AddToArray(ordArray, aOrdonnateurData(i))
dictGlobal(NumCompteAbsent)("OrdNumInvent_Absent") = ordArray
End If
Next i
If Someone can help me solve it . Id be Grateful . Have a good Sunday