EirikDaude
08-12-2014, 02:19 AM
I have the following code, which stops at the line
Debug.Print (CStr(key1) + " - " + CStr(stoppForVeke(key1)) + " - " + CStr(stoppForVeke(key1)(key2)))
with the error "Run-time error '450': Wrong number of arguments or invalid property assignment.
I suspect the problem is how I refer to the "innermost" dictionary, though I thought the syntax I was using is correct? Can someone please explain to me what I am doing wrong? Is there some other (and better) way to referring to that dictionary?
Option Explicit
Sub finnverdier()
' Oppretting av variabler
Dim områdeÅSøkeI As Range, c As Range
Dim vekenr As Long, stanstid As Long, maskin As String
Dim key1 As Variant, key2 As Variant
Dim stoppForVeke As Dictionary, stoppForMaskin As Dictionary
Set stoppForVeke = New Dictionary
' Ferdig med initialisering
With Innlimt
Set områdeÅSøkeI = Range(.Range("C3"), .Range("C1048576").End(xlUp))
If Not Intersect(.Range("C2"), områdeÅSøkeI) Is Nothing Then
Exit Sub
End If
End With
For Each c In områdeÅSøkeI
vekenr = c.Offset(0, -2): stanstid = c.Offset(0, 2): maskin = c
If stoppForVeke.Exists(vekenr) Then ' Treng ikkje å lage ny ordbok for veka, legg berre til den gamle
If stoppForVeke(vekenr).Exists(maskin) Then ' Treng berre å legge til tida for den eksisterende maskina
stoppForVeke(vekenr)(maskin) = stoppForVeke(vekenr)(maskin) + stanstid
Else ' Må opprette legge til både element og tid for den eksisterande veka
stoppForVeke(vekenr).Add maskin, stanstid
End If
Else ' Må lage nye ordbøker for maskina
Set stoppForMaskin = New Dictionary
stoppForMaskin.Add maskin, stanstid
stoppForVeke.Add vekenr, stoppForMaskin
End If
Next
For Each key1 In stoppForVeke
For Each key2 In stoppForVeke(key1)
Debug.Print (CStr(key1) + " - " + CStr(stoppForVeke(key1)) + " - " + CStr(stoppForVeke(key1)(key2)))
Next
Next
End Sub
Debug.Print (CStr(key1) + " - " + CStr(stoppForVeke(key1)) + " - " + CStr(stoppForVeke(key1)(key2)))
with the error "Run-time error '450': Wrong number of arguments or invalid property assignment.
I suspect the problem is how I refer to the "innermost" dictionary, though I thought the syntax I was using is correct? Can someone please explain to me what I am doing wrong? Is there some other (and better) way to referring to that dictionary?
Option Explicit
Sub finnverdier()
' Oppretting av variabler
Dim områdeÅSøkeI As Range, c As Range
Dim vekenr As Long, stanstid As Long, maskin As String
Dim key1 As Variant, key2 As Variant
Dim stoppForVeke As Dictionary, stoppForMaskin As Dictionary
Set stoppForVeke = New Dictionary
' Ferdig med initialisering
With Innlimt
Set områdeÅSøkeI = Range(.Range("C3"), .Range("C1048576").End(xlUp))
If Not Intersect(.Range("C2"), områdeÅSøkeI) Is Nothing Then
Exit Sub
End If
End With
For Each c In områdeÅSøkeI
vekenr = c.Offset(0, -2): stanstid = c.Offset(0, 2): maskin = c
If stoppForVeke.Exists(vekenr) Then ' Treng ikkje å lage ny ordbok for veka, legg berre til den gamle
If stoppForVeke(vekenr).Exists(maskin) Then ' Treng berre å legge til tida for den eksisterende maskina
stoppForVeke(vekenr)(maskin) = stoppForVeke(vekenr)(maskin) + stanstid
Else ' Må opprette legge til både element og tid for den eksisterande veka
stoppForVeke(vekenr).Add maskin, stanstid
End If
Else ' Må lage nye ordbøker for maskina
Set stoppForMaskin = New Dictionary
stoppForMaskin.Add maskin, stanstid
stoppForVeke.Add vekenr, stoppForMaskin
End If
Next
For Each key1 In stoppForVeke
For Each key2 In stoppForVeke(key1)
Debug.Print (CStr(key1) + " - " + CStr(stoppForVeke(key1)) + " - " + CStr(stoppForVeke(key1)(key2)))
Next
Next
End Sub