PeterBunde
New Member
- Joined
- Dec 7, 2016
- Messages
- 45
Fellow sufferers
I am using Object class to create a two-dimensional array. See code below.
Sometimes, I ned to overwrite the valie at x,y. Now, if that value has already been set, there is an error. But just asking if it is empty, apparently sets the value, but to "".
What is the right code to write a value into the x,y position - with or without it being previously defined?
I am using Object class to create a two-dimensional array. See code below.
Sometimes, I ned to overwrite the valie at x,y. Now, if that value has already been set, there is an error. But just asking if it is empty, apparently sets the value, but to "".
What is the right code to write a value into the x,y position - with or without it being previously defined?
Code:
Sub Test()
Dim inhabitants_in As Object
Set inhabitants_in = CreateObject("Scripting.Dictionary")
' add countries
inhabitants_in.Add "Norway", CreateObject("Scripting.Dictionary")
inhabitants_in.Add "France", CreateObject("Scripting.Dictionary")
inhabitants_in.Add "Italy", CreateObject("Scripting.Dictionary")
' add cities and number of inhabitants
inhabitants_in("Norway").Add "Oslo", 9
inhabitants_in("France").Add "Paris", 200
inhabitants_in("Italy").Add "Roma", 300
inhabitants_in("Italy").Add "Milano", 400
inhabitants_in("Italy").Add "Firenze", 500
inhabitants_in("Italy").Add "Venezia", 600
inhabitants_in("Norway")("Oslo") = 800
MsgBox (inhabitants_in("Norway")("Hardanger"))
inhabitants_in("Norway").Add "Hardanger", 111600 '<<< This line fails
MsgBox (inhabitants_in("Norway")("Hadanger"))
' Show values
MsgBox _
inhabitants_in("Italy")("Venezia") & vbNewLine & _
inhabitants_in("France")("Paris") & vbNewLine & _
inhabitants_in("Norway")("Oslo")
End Sub