从以前的字典(VBA)添加项目到字典

时间:2015-09-14 14:32:40

标签: excel-vba dictionary vba excel

我该怎么做?这是我试过的一些示例代码

exports.collectData = function(req, callback) {
    var data = "";

    req.on("data", function(chunk) {
        data += chunk;
    })

    req.on("end", function() {
        callback(data);
    })
}

http.createServer(function(req, res){
res.writeHead(200, {"Content-type": "text/plain"});
res.write("Howdy");
res.end();
}).listen(port);

这会引发错误:

var fs = require("fs"); // Read File fs.createReadStream("input/people.json") // Write File .pipe(fs.createWriteStream("output/people.json")); Sub testing() Dim n As Long Dim dict As New Dictionary Dim obj as MyClass For n = 1 To 10 Set obj = New MyClass obj.value="I am an object" 'setting obj property dict.Add n, bcell Next n subDict.Add dict.Keys(1), dict.Items(1)'error here End Sub

1 个答案:

答案 0 :(得分:1)

项目和密钥都是必需的 - 这就是为什么你得到的'参数不是可选的'错误。

现在您正在添加既未声明也未实例化的bcell。您的意思是添加obj吗?

Sub test()

    Dim Dict As Scripting.Dictionary
    Dim subDict As Scripting.Dictionary
    Dim obj As MyClass
    Dim n As Long

    Set Dict = New Scripting.Dictionary

    For n = 1 To 10
        Set obj = New MyClass
        obj.Value = "I'm object #" & n
        Dict.Add n, obj
    Next n

    Set subDict = New Scripting.Dictionary
    subDict.Add Dict.Keys(0), Dict.Items(0)

    Debug.Print subDict.Items(0).Value

End Sub

请注意,dictionairy indeces从0开始而不是1。