VBA字典将TexBox值添加到字典中

发布于 2025-02-13 06:28:08 字数 698 浏览 2 评论 0原文

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

目前,我将所有文本框名称添加为字典的键。

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

我想将所有文本框的值传递到一周中。计数,类似于将所有文本框名称添加到WID(键)

如何感谢所有帮助。

谢谢

I need some help on looping through all my textboxes and adding the values to a dictionary.

Currently, I'm adding all textboxes name's as the key the 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

I want to pass all the textboxes values in to week.count, similar to how all the textboxes names are added to wID (key)

appreciate all help.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乙白 2025-02-20 06:28:08

我设法弄清楚了我要做什么。

Dim txtname as string, txtvalue as string

txtname = ctrl.name

txtvalue = userform1(txtname).value

然后我更改为:

week.count = week.count + txtvalue

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

I managed to figure out what I was trying to do.

Dim txtname as string, txtvalue as string

txtname = ctrl.name

txtvalue = userform1(txtname).value

which then I changed this bit to be:

week.count = week.count + txtvalue

now for each textbox the value entered is stored in the dictionary in .count

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文