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)
Re: Is there a structure in VB where you can use myVariable("section") = myInteger?
How about using an array?
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"
:wave:
Re: Is there a structure in VB where you can use myVariable("section") = myInteger?
You could try a two-dimensional array.
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?
Re: Is there a structure in VB where you can use myVariable("section") = myInteger?
Could you elaborate further on what you need to do?
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.
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
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?
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
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.
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?
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).