cant figure out Collection

07-04-2004, 08:20 AM
i've been looking for a way to do this for days now, i'm not very talented myself im quite new to VB but heres my prob.

i want to create a collection i think, or instances of a class or something like that, right now i have a class called 'Entity' with property 'keycomments' this is just one of the properties i have a few irrelevant ones.

when i click my button i want the text entered in KeyvalID to use as the name of my new instance of Entity, shown as follows:

If KeyvalID.Text = "" Then
MsgBox ("You must enter an ID.")
End If

Dim temp
temp = KeyvalID.Text

Dim bla(temp) As New Entity

'in a function later on this lower section will happen
'and for now it assumes the KeyvalID.Text earlier was "npc_roll"

bla(npc_roll).keycomments = "It Works!"

KeyvalComments.Text = bla(npc_roll).keycomments 'this is on screen for the user to see.

i know this doesnt work because i have to have a constant expression when making the bla(temp), and 'temp' is not constant, but how can i go about achieving this, all i want is the ability to type

bla(npc_roll).keycomments = "It Works!"

i have to be able to create an instance of the class Entity with the name of the users choice.

also if i'm going to have to use a collection, can you explain very carefully because no matter how much i look at tutorials and examples on MSDN or other sites, i just cant figure them out! for a start i cant type

public class bla
end class

it doesnt allow any of it.

i'm just totally stumped on making collections.

Read on if your willing to help find an alternative :):
if theres an alternative you can think of then i'll be just as happy, i'm taking a few values that have been entered and trying to store them for saving later on. there can be any number of them and each will have a few values inside, some wont include some of the values, and in a special case, some will need to create extras (called Choice1, Choice2, Choice3... etc.) if possible i'd also like to create all these inside other classes, for example:


this is basically the exact system i want. i just dont have the skill to do it, and i cant find out how to create something like keyvals, where it has a second or third list of properties inside it.

sorry for the long post.

07-04-2004, 08:42 AM
how about using a Private Type.

Option Explicit
Private Type StringKeys
Keycomments As String
Irrelivantstuff As String
End Type

'then you can

Dim bla(5) As StringKeys 'just threw 5 in, dont know what you want here

bla(0).Keycomments = "some stuff"
bla(0).Irrelivantstuff = "some other stuff"

Debug.Print bla(0).Keycomments & " " & bla(0).Irrelivantstuff

is this what you are looking for ?

07-04-2004, 08:47 AM
almost, is there a way to make a type with more than just


so i could have


EDIT: oh yea and is it possible to just add 1 on the end of that, say it starts with 8 in and i add 1 so it becomes bla(9) or do i need to have bla(1000) at the beginning as a set limit.

also using this method is it possible to start off with


and later on add


07-04-2004, 09:00 AM
try this then

Option Explicit

Private Type StringKeys
Keycomments As String
Irrelivantstuff As String
End Type

Private Type skeys
key1 As StringKeys
End Type


Dim bla(5) As skeys

bla(0).key1.Keycomments = "blahblah"
bla(0).key1.Irrelivantstuff = "blahblahblah"

Debug.Print bla(0).key1.Keycomments & " " & bla(0).key1.Irrelivantstuff

07-04-2004, 09:04 AM
excellent, now all i need is a way to create key2, key3... and so on while its running, since both key's and bla's can be added and deleted, have u got any ideas on this?

EDIT: wait this isnt all i need, i need a way to create these keys and bla's using 'I' in a For loop, because i'll need to see how many have already been created, if theres really no way to do this i think it'll be ok just setting limits to how many you can make, but i'd prefer a more efficient way.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum