excel - 具有“整数”类型键和“整数动态数组”类型值的字典:类型不匹配错误
问题描述
我想要一个字典,其键类型为“整数”,值类型为“动态整数数组”。
以下代码给了我一个类型不匹配。
第一条if
语句设置了一个 key=0 和数组 [0] 的字典。
第二条if
语句尝试将键修改为数组 [0,1] 的值。
Sub tester()
' prepare graph adjacency dictionary
Dim dict As Object
Set dict = CreateObject("Scripting.Dictionary")
Dim a() As Integer
Dim ub As Integer
If (Not dict.Exists(0)) Then
ReDim a(0 To 0)
a(0) = 0
dict.Add 0, a(0)
End If
If (dict.Exists(0)) Then
ub = UBound(dict(0)) ' type mismatch here ? why ?
ReDim a(0 To ub)
a = dict(0)
ReDim Preserve a(0 To ub + 1)
a(ub + 1) = 1
dict(0) = a
End If
End Sub
解决方案
推荐阅读
- python - 条件 Django 表单验证
- regex - 使用正则表达式从具有已知前缀的字符串中提取多个单词
- javascript - 在javascript中转换为e+的脚本
- qt - 基于 CMake 的项目,在运行时加载了自定义 QML 插件,仅使用 MinGW 失败
- snakemake - Snakemake 中的 CalledProcessError
- json - 通过 json 的 jquery 循环无法按预期工作
- mysql - SQL 可以单独插入,但不能作为带有外键的文件加载
- azure - 在混合节点池(Windows/Linux)上的 AKS 上忽略 nodeSelector 约束?
- spring-boot - MissingServletRequestParameterException 未使用 @ControllerAdvice 捕获
- apache-spark - spark nlp中的多语言bert