Manuel Cavero
New Member
- Joined
- Feb 17, 2018
- Messages
- 26
Hello everyone:
I have two differents subs, each one calls to a different class to build the same object. The unique difference between both is the type of item used to load the dictionary inside the class. Let's have a look on the first one:
In the first one the dictionary is located inside a SUB procedure Añadir (add in English):
In the second one, the dictionary is located inside the procedure Let Property Añadir (add in English):
When the code is initialized in the first case the count property of dictionary = 0, but in the second case the count property of dictionary = 1.
How could I avoid this?
I have two differents subs, each one calls to a different class to build the same object. The unique difference between both is the type of item used to load the dictionary inside the class. Let's have a look on the first one:
In the first one the dictionary is located inside a SUB procedure Añadir (add in English):
Code:
Option Explicit
Private Valores As Scripting.Dictionary
Private y As Integer
----------------------------------------------
Private Sub Class_Initialize()
Set Valores = New Scripting.Dictionary
End Sub
----------------------------------------------
Private Sub Class_Terminate()
Set Valores = Nothing
End Sub
----------------------------------------------
Public Sub Añadir(Valor As Integer)
With Valores
If .Exists(y) Then
If Valor = 1 And .Item(y) > 0 Then
.Item(y) = .Item(y) + 1
ElseIf Valor = 1 And .Item(y) < 0 Then
y = y + 1
.Add y, Valor
ElseIf Valor = -1 And .Item(y) < 0 Then
.Item(y) = .Item(y) - 1
ElseIf Valor = -1 And .Item(y) > 0 Then
y = y + 1
.Add y, Valor
End If
Else
.Add y, Valor
End If
End With
End Sub
Code:
Option Explicit
Private Valores As Scripting.Dictionary
Private y As Integer
----------------------------------------------
Private Sub Class_Initialize()
Set Valores = New Scripting.Dictionary
End Sub
----------------------------------------------
Private Sub Class_Terminate()
Set Valores = Nothing
End Sub
----------------------------------------------
Public Property Let Añadir(Valor As Integer)
With Valores
If .Exists(y) Then
If Valor = 1 And .Item(y) > 0 Then
.Item(y) = .Item(y) + 1
ElseIf Valor = 1 And .Item(y) < 0 Then
y = y + 1
.Add y, Valor
ElseIf Valor = -1 And .Item(y) < 0 Then
.Item(y) = .Item(y) - 1
ElseIf Valor = -1 And .Item(y) > 0 Then
y = y + 1
.Add y, Valor
End If
Else
.Add y, Valor
End If
End With
End Property
When the code is initialized in the first case the count property of dictionary = 0, but in the second case the count property of dictionary = 1.
How could I avoid this?