【发布时间】:2016-03-23 14:55:46
【问题描述】:
我正在尝试在 VBS 中创建一个字典,我可以让它工作;但是,似乎我的子级字典是通过引用而不是按值访问的?
我试过这个:
Dim s, fso, f, ts, str, fRead, line, i, dictElements, dictionary, screenItem
Set s = CreateObject("System.Text.StringBuilder")
Set fso = CreateObject("Scripting.FileSystemObject")
Set dictElements = CreateObject("Scripting.Dictionary")
Set dictionary = CreateObject("Scripting.Dictionary")
'add elements to dictionary
dictElements.Add "Name", "MyName"
dictElements.Add "Setpoint", 100.0
dictElements.Add "Process Value", 80.6
'Create Data Structure
dictionary.Add "DigitalInputOne", dictElements
dictionary.Add "DigitalInputTwo", dictElements
'test dictionary
dictionary("DigitalInputTwo")("Name")= "Hello"
dictionary("DigitalInputTwo")("Setpoint")= 40.123
HmiRuntime.Screens("Home").ScreenItems("Text field_1").Text = dictionary ("DigitalInputOne")("Name")
HmiRuntime.Screens("Home").ScreenItems("Text field_2").Text = dictionary("DigitalInputOne")("Setpoint")
HmiRuntime.Screens("Home").ScreenItems("Text field_3").Text = dictionary("DigitalInputOne")("Process Value")
HmiRuntime.Screens("Home").ScreenItems("Text field_4").Text = dictionary("DigitalInputTwo")("Name")
HmiRuntime.Screens("Home").ScreenItems("Text field_5").Text = dictionary("DigitalInputTwo")("Setpoint")
HmiRuntime.Screens("Home").ScreenItems("Text field_6").Text = dictionary("DigitalInputTwo")("Process Value")
当我更改其中一个值时,它会更改所有值,这让我认为我的元素字典是通过引用。有没有办法通过价值实现这一目标?我希望每个子字典都不同。
【问题讨论】:
标签: vbscript