VBA Dictionary将文本框值添加到字典中



我需要一些帮助来循环遍历所有的文本框并将值添加到字典中。

目前,我正在添加所有的文本框的名称作为关键的字典。

Dim dict as New Dictionary
Dim Week as Class1, wID as String
Dim ctrl as Control

For Each ctrl in UserForm1.Controls
If TypeName(ctrl) = "TextBox" Then

wID = ctrl.name 

IF dict.exists(wID) = TRUE Then
set Week = class1
else
set week = dict(wID)
dict.add wID, Week
End if

week.field1 = week.field1 + Application.Username
week.field2 = week.field2 + userform1.combox1.value
week.count = week.count + ctrl.Text 'this part i cant get to work, dont have the option for text or value
Set ReadItems = dict
End if
Next ctrl

我想把所有的文本框值传递给week。count,类似于将所有文本框名称添加到wID (key)

感谢所有的帮助。

感谢

我终于明白我要做什么了。

Dim txtname as string, txtvalue as string
txtname = ctrl.name
txtvalue = userform1(txtname).value

然后我把它改成:

week.count = week.count + txtvalue

现在对于每个文本框,输入的值都存储在字典中。count

相关内容

  • 没有找到相关文章

最新更新