473,387 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Collections vs Arrays

AaronL
99
Hello,

I need help determining what the best way to store properties of multiple items.

For example, I am creating a list box and every item in the list box needs to have properties. I don't want to use arrays because I'm not going to know the maximum items in the list box. I read briefly on Microsoft's site about "collections" but I don't quite understand how they are used. Can someone give me an example of what I would do as far as code.

Thanks!
Sep 22 '08 #1
11 1920
debasisdas
8,127 Expert 4TB
collection is the best solution for your case.

you just need to create an use defined type and use that.
Sep 22 '08 #2
AaronL
99
I'm not sure how to use collections, can you give me some code examples??
Sep 22 '08 #3
This is how to use a collection or list of


[code]

Dim myList as new List(Of String)

myList.Add("Something")
myList.Add("Other thing no matter what the size is")

/[code]

Tell me if this help you
Sep 23 '08 #4
AaronL
99
Ok, it helps a little, but how to you have multiple fields in a list for example, if I were to create a list that had

Name
Address
Phone Number
Email

I would want all of those in different fields and reference them somewhat like this

MyList.Name(index number)

or something of that sort, how would I do that? Or do I have to use delimiters in the string??
Oct 3 '08 #5
AaronL
99
Also, I want to make my own database, is this the best way to do this in VB6??
Oct 6 '08 #6
Hi Chelf

You want to create a database this is not the best way. Try to use a table.

About your first question you can use struture and keep it into the List of string.

Create a new project and put in a form just one buttom.

Copy this code and try to understand it.

[code]
Public Structure Customer
Public name As String
Public age As Integer
Public address As String
Public gender As String
End Structure
Dim myList As New List(Of Customer)

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'Instanciate a structure
Dim CurCustomer As Customer
'Put some information on the structure
CurCustomer.name = "John"
CurCustomer.age = 24
CurCustomer.address = "Some address"
CurCustomer.gender = "Male"
'Save in the list
myList.Add(CurCustomer)
End Sub
/[code]

I hope this help you
Oct 7 '08 #7
AaronL
99
That's great!! Thank you for your help. Now you mentioned that this isn't the best way to make a database? What do you recommend as far as designing your own database, I don't want to use SQL etc.. I want this to be proprietary...
Oct 7 '08 #8
Ok, if you want to make your data proprietary, you'll need to do by yourself.

In the current market if you intend to create a commercial product, you'll repel your possible customer as soon as they know about proprietary data.

Think about it.

Rpicilli
Oct 8 '08 #9
AaronL
99
I'm using VB6 and I noticed that Structure and List doesn't work with it, I figured out how to make a new structure with the Type declaration but how do I do the List using the Collection declaration? I noticed I can't use Dim MyList as New Collection(Of Type) it says expected end of statement
Oct 10 '08 #10
Hi,

Excuse me by this. I don't have the VB6 and I don't remember how to do that. I'll try to figured out and let you know.

Rpicilli
Oct 12 '08 #11
AaronL
99
Does anyone know what I'm doing wrong?

Public Type UserData
ID As String
Password As String
End Type
Public User As UserData
Public UserFile As Collection

Shouldn't I be able to do something like

UserData.ID = "username"
UserData.Password = "password"
UserFile.Add(User)

I get some weird message about data types being coerced or something stupid. I just want to make a simple collection instead of using an array, why is this so hard to do?
Oct 22 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Anthony Bouch | last post by:
Hi I've been reading using the XmlSerializer with custom collections. I've discovered that when serializing a custom collection (a class that implements ICollection, IList etc.) the...
1
by: Mark | last post by:
Is there an online site where the various methods of storing arrays of classes and variables are explained? For example, I'd love a grid that showed the various pluses and minues of an Array,...
3
by: aa7im | last post by:
I am trying to design a good domain model for a system I am working on but I am having a hard time trying to figure out how to deal with relations and transaction... For example if I create an...
1
by: Fabrizio | last post by:
Hi I'm Fabrizio and I come from Turin in Italy. I'm a new user of C# until now I program only in Java or sometimes in C. I've problem because the C# collections are different and I don't...
5
by: Dale | last post by:
I read an article sometime in the last few weeks comparing the performance of Generic Collections to ArrayList. It was pretty detailed with several charts comparing various collections methods...
12
by: Gilbert | last post by:
H, i'm starting with asp.net/vb.net and have some questions about arrays and collections: 1) what's the difference between: dim x() as string and dim x as array
0
by: sudhaMurugesan | last post by:
Hi guys, Please can anyone tell me that is there any collections or arrays to store details in sql server. if so can we have any dynamic arrays ?
0
by: bearophileHUGS | last post by:
Several languages like Java, C# etc have a List type in the std lib. Python has a built-in list(), it's implemented as array dynamic on the right. Not too much time ago Hettinger has added a...
2
by: SimonDotException | last post by:
I am trying to use reflection in a property of a base type to inspect the properties of an instance of a type which is derived from that base type, when the properties can themselves be instances of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.