Results 1 to 6 of 6

Thread: Is there a collection that works like a Dictionary? [resolved]

  1. #1

    Thread Starter
    Addicted Member Porsche944's Avatar
    Join Date
    Apr 2005
    Location
    Ann Arbor
    Posts
    182

    Lightbulb Is there a collection that works like a Dictionary? [resolved]

    Hey Guys,
    I saw somewhere on MSDN that there is a collection that works much like an array and a dictonary combined. Now I can't seem to find it anymore. Does anyone know what namespace this type of collection is.

    What it needs to do is have the ability of going through the collection based on Index or Based on a Key. The most important thing is it has to have the ability to be multidemnsional or have the ability to store sperate values for just one Key or Index.

    I will be using it to keep track of data I remotely receive using WMI. For each machine I want to be able to access the data from this collection and retieve data based on the position it is in inside the array based on what dimension of the array it is in. Somewhat like an excel speard sheet.

    EX:
    Key=Machine Name Mapped Network Drives Last User on Processes
    SomeMachineName Drive U;Drive;z kevin colletion of processes

    something to that effect. I have a custom class I created that uses a dictionary object that uses the machine names as keys and inside the vale for the key is the index of a sperate array that is multidimensional which contains information from my scans.

    It's kinda hard to work with but it works. There must be something else out there in the collection namespace that can do what I am already doing but better.

    Thank you
    Last edited by Porsche944; May 6th, 2005 at 07:34 PM.

  2. #2
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397

    Re: Is there a collection that works like a Dictionary?

    I've found hashtables in VBNet as useful as the dictionary object.

    For Example:

    VB Code:
    1. '[i][size=1]initialize hash tables at the "form" level[/size][/i]
    2.     Public Export_Log_Fields As New Hashtable()
    3.     Public Export_Log_Mode As New Hashtable()
    4.     Public OUT_FIELD_TYPE As New Hashtable()
    5.     Public OUT_FIELD_LOC As New Hashtable()
    6.     Public OUT_TYPE_LOC_FIELD As New Hashtable()
    7.  
    8.     Public Sub INIT_HASHTABLE()
    9.         Export_Log_Fields.Add("total impressions printed", "total_impressions_printed")
    10.         Export_Log_Fields.Add("total sheets printed", "total_sheets_printed")
    11.         Export_Log_Fields.Add("total black only pages printed", "total_BW_imp_printed")
    12.         Export_Log_Fields.Add("total color pages printed", "total_Color_imp_printed")
    13. '[i][size=1]yadayadayada[/size][/i]
    14.  
    15.         Export_Log_Mode.Add("job status", "1")
    16.         Export_Log_Mode.Add("record status", "2")
    17.         Export_Log_Mode.Add("container id", "1")
    18.         Export_Log_Mode.Add("job id", "2")
    19.  
    20.  
    21.         OUT_FIELD_TYPE.Add("total_BW_imp_printed", "int")
    22.         OUT_FIELD_TYPE.Add("total_Color_imp_printed", "int")
    23.         OUT_FIELD_TYPE.Add("total_sheets_printed", "int")
    24. '[i][size=1]yadayadayada[/size][/i]
    25.         OUT_FIELD_TYPE.Add("page_range", "str")
    26.         OUT_FIELD_TYPE.Add("job_data_number", "str")
    27.         OUT_FIELD_TYPE.Add("job_queue", "str")
    28.         OUT_FIELD_TYPE.Add("sent_by", "str")
    29. '[i][size=1]yadayadayada[/size][/i]
    30.         OUT_FIELD_TYPE.Add("rip_started", "date")
    31.         OUT_FIELD_TYPE.Add("print_started", "date")
    32.         OUT_FIELD_TYPE.Add("date_submitted", "date")
    33. '[i][size=1]yadayadayada[/size][/i]
    34.  
    35. '[i][size=1]now the array index locations, 3 arrays of 3 types, int, string, date[/size][/i]
    36.         OUT_FIELD_LOC.Add("pages_ripped", "0")
    37.         OUT_FIELD_LOC.Add("rip_time", "1")
    38.         OUT_FIELD_LOC.Add("copies_requested", "2")
    39.         OUT_FIELD_LOC.Add("copies_printed", "3")
    40.         OUT_FIELD_LOC.Add("total_sheets_printed", "4")
    41. '[i][size=1]yadayadayada[/size][/i]
    42.         OUT_FIELD_LOC.Add("job_name", "0")
    43.         OUT_FIELD_LOC.Add("job_queue", "1")
    44.         OUT_FIELD_LOC.Add("sent_by", "2")
    45. '[i][size=1]yadayadayada[/size][/i]
    46.         OUT_FIELD_LOC.Add("date_submitted", "0")
    47.         OUT_FIELD_LOC.Add("rip_started", "1")
    48.         OUT_FIELD_LOC.Add("print_started", "2")
    49.         OUT_FIELD_LOC.Add("print_completed", "3")
    50. '[i][size=1]yadayadayada[/size][/i]
    51. '[i][size=1]now, indicate the output field name when looping thru the 3 arrays of varying type[/size][/i]
    52.         OUT_TYPE_LOC_FIELD.Add("str_0", "job_name")
    53.         OUT_TYPE_LOC_FIELD.Add("str_1", "job_queue")
    54.         OUT_TYPE_LOC_FIELD.Add("str_2", "sent_by")
    55. '[i][size=1]yadayadayada[/size][/i]
    56.         OUT_TYPE_LOC_FIELD.Add("int_0", "pages_ripped")
    57.         OUT_TYPE_LOC_FIELD.Add("int_1", "rip_time")
    58.         OUT_TYPE_LOC_FIELD.Add("int_2", "copies_requested")
    59. '[i][size=1]yadayadayada[/size][/i]
    60.         OUT_TYPE_LOC_FIELD.Add("date_0", "date_submitted")
    61.         OUT_TYPE_LOC_FIELD.Add("date_1", "rip_started")
    62.         OUT_TYPE_LOC_FIELD.Add("date_2", "print_started")
    63.         OUT_TYPE_LOC_FIELD.Add("date_3", "print_completed")
    64.  
    65.     End Sub



    -Hope this helps!
    -Lou

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Is there a collection that works like a Dictionary?

    you can also use the DictionaryBase class to create your own Dictionary Class...

  4. #4
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397

    Re: Is there a collection that works like a Dictionary?

    What are the advantages of your suggestion?

    A few weeks ago I came across, I believe, some sample code you wrote.
    It looked good, but I didn't quite understand its functioning if, for example, all I needed was something to return a value if the key existed, or else return nothing.

  5. #5
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: Is there a collection that works like a Dictionary?

    Is this what you are looking for? (I use a couple of sorted lists as dictionaries)

    Public g_StoreList As New SortedList
    Public g_FileList As New SortedList

    This is how it is listed in the Help Heap:

    .NET Framework Class Library
    SortedList Members
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Is there a collection that works like a Dictionary?

    Quote Originally Posted by NotLKH
    What are the advantages of your suggestion?

    A few weeks ago I came across, I believe, some sample code you wrote.
    It looked good, but I didn't quite understand its functioning if, for example, all I needed was something to return a value if the key existed, or else return nothing.
    well if you want a dictionary type class... but need it to have some additional functionality (for example populating its contents from a database) then often times creating your own class is the way to go because they give you these robust base classes to inherit from... I need to know nothing about how to enumerate or any of the inner workings of a collection type class becuase its all brought up from the baseclass

    that is just one example.. but pretty much ANYTHING you may want a dictionarytype class to do that it doesnt by default can be added into your customer class... while still getting everything from the base.

    using a hashtables will no doubt be a useful answer in many situations also

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