Results 1 to 13 of 13

Thread: Is there a structure in VB where you can use myVariable("section") = myInteger?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269

    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)

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Is there a structure in VB where you can use myVariable("section") = myInteger?

    How about using an array?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269

    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"

  4. #4
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Is there a structure in VB where you can use myVariable("section") = myInteger?

    You could try a two-dimensional array.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269

    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?

  6. #6
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Is there a structure in VB where you can use myVariable("section") = myInteger?

    Could you elaborate further on what you need to do?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  7. #7
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    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.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269

    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

  9. #9
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    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?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  10. #10
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    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

  11. #11
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269

    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?

  13. #13
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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
  •  



Click Here to Expand Forum to Full Width