如何创建组合作为变量 [英] How to create as combo as a variable
问题描述
任何人都可以帮忙。
我有16个组合框,我想使用相同的项目列表。
当我添加一个新项目时,我想将它添加到所有组合框集合中。
我尝试使用此代码;
Dim updateComboName As String
Dim updateCombo As ComboBox
对于 i = 1 要 16
updateComboName = 播放器& i
updateCombo = updateComboName
updateCombo.Items.Add(curComboItem)
Next
但是 updateCombo = updateComboName
这一行失败了,因为左边是组合而右边是一个字符串。当我逐步执行for循环时,如何将updateCombo设置为名称为Player1到Player16的变量?
此外,当项目添加时,一旦应用程序关闭,它就会丢失。如何确保新项目保留以备将来使用?
也许只需将第二行更改为以下内容?
...
updateCombo = CType ( Me .Controls.Find(updateComboName, True ),ComboBox)
...
Can anyone please help.
I have 16 combo boxes which I want to use the same list of items.
When I add a new item, I want to add it to all combo boxes collections.
I tried using this code;
Dim updateComboName As String
Dim updateCombo As ComboBox
For i = 1 To 16
updateComboName = "Player" & i
updateCombo = updateComboName
updateCombo.Items.Add(curComboItem)
Next
but the line "updateCombo = updateComboName
" fails as the left side is a combo and the right a string. How do I set the updateCombo as a variable with a name of Player1 through to Player16 as I step through the for loop?
In addition when the item is added it is lost as soon as the application is closed.How do I ensure the new item is retained for future use?
Maybe just change your second line to the following?
... updateCombo = CType(Me.Controls.Find(updateComboName, True), ComboBox) ...
这篇关于如何创建组合作为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!