|
-
Aug 3rd, 2005, 12:16 AM
#1
Thread Starter
Frenzied Member
Is there a structure in VB where you can use myVariable("section") = myInteger?
The closest thing I can think of is a collection object, but it is very very slow, and limited to the number of items u can put in it
Is there an easier way to do this? Basically I want to have an structure that holds an array of strings, and each string has one integer associated with it
For example, im making a chat client and I want to log messages sent for a username in realtime
So if john says a message
myVar("john") = myVar("john") + 1
if mike says something
myVar("mike") = myVar("mike") + 1
similar to php i guess
how can i do this in vb? efficeintly? (i dont want to use a type because it will involve looping through all the items looking for where "john" occurs)
-
Aug 3rd, 2005, 12:19 AM
#2
Re: Is there a structure in VB where you can use myVariable("section") = myInteger?
How about using an array?
-
Aug 3rd, 2005, 01:36 AM
#3
Thread Starter
Frenzied Member
Re: Is there a structure in VB where you can use myVariable("section") = myInteger?
but how can i do something like myArray("a") = b? otherwise i have to do a loop thru all the things in the array looking for "a"
-
Aug 3rd, 2005, 01:54 AM
#4
Re: Is there a structure in VB where you can use myVariable("section") = myInteger?
You could try a two-dimensional array.
-
Aug 3rd, 2005, 01:57 AM
#5
Thread Starter
Frenzied Member
Re: Is there a structure in VB where you can use myVariable("section") = myInteger?
ive never worked with those before..
do u have an example?
can i do what im trying to do without loops?
-
Aug 3rd, 2005, 01:59 AM
#6
Re: Is there a structure in VB where you can use myVariable("section") = myInteger?
Could you elaborate further on what you need to do?
-
Aug 3rd, 2005, 02:06 AM
#7
Re: Is there a structure in VB where you can use myVariable("section") = myInteger?
What about using a 'hidden' ListBox; add each new 'message', and you can go back as required.
Bruce.
-
Aug 4th, 2005, 02:22 AM
#8
Thread Starter
Frenzied Member
Re: Is there a structure in VB where you can use myVariable("section") = myInteger?
that would be really slow..
basically i want to have something FAST..
a collection is really really slow
do you think sql would be best?
update table set messages = messages + 1 where chatter = 'mike'
and will it be fast to retrieve messagecount also?
or is there another way to do with vb
something like a listbox where u can set a tag for each item but you cant do that
-
Aug 4th, 2005, 02:29 AM
#9
Re: Is there a structure in VB where you can use myVariable("section") = myInteger?
Why would using a listbox or collection slow for you? Do you really need it fast? What do you really want to track by the way?
-
Aug 4th, 2005, 03:18 AM
#10
Re: Is there a structure in VB where you can use myVariable("section") = myInteger?
You could create your own class module. I doubt you've tried this if you haven't worked with two-dimensional arrays before, but believe me, its worth looking into. Look up a beginners class tutorial, and see how to use them. This can be achieved using them 
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Aug 4th, 2005, 04:36 AM
#11
Re: Is there a structure in VB where you can use myVariable("section") = myInteger?
Use a Dictionary object; they are hash-based associative arrays (effective collections) and as such very much faster than the Collection object, for string work.
You will need to add a reference to the Microsoft Scripting Runtime.
-
Aug 4th, 2005, 04:42 PM
#12
Thread Starter
Frenzied Member
Re: Is there a structure in VB where you can use myVariable("section") = myInteger?
dictionary object works like a charm 
what is a hash-based associative array?
-
Aug 5th, 2005, 04:47 AM
#13
Re: Is there a structure in VB where you can use myVariable("section") = myInteger?
An associative array is basically two linked arrays, one of keys and one of data. Accessing by key returns the data linked to that key.
Being hash-bashed means that instead of storing keys the object stores hashes of the keys, which makes it faster to access. Being hashes, there is a (extremely) low possiblity that they may not be unique, however this only becomes an issue for very very high numbers of elements (probably more than you could store anyway).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|