Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > cant figure out Collection


Reply
 
Thread Tools Display Modes
  #1  
Old 07-04-2004, 07:20 AM
under_seeg under_seeg is offline
Regular
 
Join Date: Feb 2004
Posts: 64
Unhappy cant figure out Collection


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:

Code:
    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
Code:
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
Code:
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:

No1.ID
No1.Name
No1.Keyvals.1.ID
No1.Keyvals.1.Name
No1.Keyvals.1.Comments
No1.Keyvals.2.ID
No2.ID
...

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.
Reply With Quote
  #2  
Old 07-04-2004, 07:42 AM
stevo stevo is offline
Senior Contributor

* Expert *
 
Join Date: May 2004
Location: Manchester, England.
Posts: 1,254
Default

how about using a Private Type.
Code:
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 ?
Reply With Quote
  #3  
Old 07-04-2004, 07:47 AM
under_seeg under_seeg is offline
Regular
 
Join Date: Feb 2004
Posts: 64
Default

almost, is there a way to make a type with more than just

bla(0).comment

so i could have

bla(0).key1.comment?

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

bla(0).ID
bla(0).Keycomment

and later on add

bla(0).Choice1

Last edited by under_seeg; 07-04-2004 at 07:53 AM.
Reply With Quote
  #4  
Old 07-04-2004, 08:00 AM
stevo stevo is offline
Senior Contributor

* Expert *
 
Join Date: May 2004
Location: Manchester, England.
Posts: 1,254
Default

try this then
Code:
Option Explicit Private Type StringKeys Keycomments As String Irrelivantstuff As String End Type Private Type skeys key1 As StringKeys End Type 'then 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
Reply With Quote
  #5  
Old 07-04-2004, 08:04 AM
under_seeg under_seeg is offline
Regular
 
Join Date: Feb 2004
Posts: 64
Default

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.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->