保存与PHP数组相同的数据的最佳VBA数据类型为key或value的是什么 [英] What is the best VBA data type`key`=>`value` to save data same as PHP array

查看:66
本文介绍了保存与PHP数组相同的数据的最佳VBA数据类型为key或value的是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VBA,需要将类型为key => value的数据保存到最快的位置;此数据类型可帮助我缓存来自http请求的响应文本,提高查询速度.但是我不知道什么是最好的方法?我需要与key=>value的php数组相同的数据类型!感谢您的帮助!

I'm working with VBA and need to save data in type key=>value to getting fastest; This data type help me cache responese text from http request, increase query speed. But I don't know what is the best way to do it? I need a data type same as php array with key=>value! Thank for help!

推荐答案

您是否看过字典对象?

它是Microsoft脚本运行时的一部分. 此SO答案给出了一个清晰的示例.

It's available as part of the Microsoft Scripting Runtime. A clear example of how to add this is given by this SO answer.

Sub DictExample1()

Dim dict As Dictionary
Dim v As Variant

    'Create the dictionary          
    Set dict = New Dictionary

   'Add some (key, value) pairs
    dict.Add "John", 34
    dict.Add "Jane", 42
    dict.Add "Ted", 402

    'How many items do we have?
    Debug.Print "Number of items stored: " & dict.Count

    'We can retrieve an item based on the key
    Debug.Print "Ted is " & dict.Item("Ted") & " years old"


   'We can test whether an item exists
    Debug.Print "We have Jane's age: " & dict.Exists("Jane")
    Debug.Print "We have Zak's age " & dict.Exists("Zak")

    'We can update a value by replacing it
   dict.Item("Ted") = dict.Item("Ted") / 10

    Debug.Print "Ted's real age is: " & dict.Item("Ted")

   'We can add more items
    dict.Add "Carla", 23

   'And we can iterate through the complete dictionary
    For Each v In dict.Keys
        Debug.Print "Name: " & v & "Age: "; dict.Item(v)
    Next

End Sub

(来源: http://www.techbookreport.com/tutorials/vba_dictionary.html )

这篇关于保存与PHP数组相同的数据的最佳VBA数据类型为key或value的是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆