• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

Setting a value of an item in a collection

Public DLS(1 to 2) as new collection 'in module

... later on in mdi form

msgbox DLS(2).item(x) ' this works fine
DLS(2).item(x)="6" ' Error Object Reqiured... what is the matter with this?
0
hess
Asked:
hess
  • 2
1 Solution
 
ArkCommented:
Hi
Set DLS(2).item(x)="6"
Cheers
0
 
ArkCommented:
Hi
Sorry, ignore my previous message
Correct code:
DLS(2).Remove x
DLS(2).Add "6", , x
Cheers
0
 
FWAllanCommented:

You can add to and remove items from a collection.  You cannot alter the immediate value of a member of the colection.  Generally these would be objects and classes.

You can, however, update the properties of any object that you have put into a collection.

EG

Form has a textbox called txt_Any
and a command button cmd_update


Then in a module

sub cmd_update_click()
' This will update the textbox on the
' screen with a new value

  dim col as collection

  col.add txt_any, "txt_Any"

  col.item("txt_Any").text = "The value"
end sub


What you could do is create a class
called c_Text with the following lone line of code:

Public Text as string


And then in a module or form


sub etc()

  dim avalue as new C_text
 
  C_text.text = "First value"

  col.add avalue , "key1"

  col.item("key1").text = "value2"

end sub
0
 
hessAuthor Commented:
That is what I thought the case was. Thankyou for asuring me.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now