Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to search In a Structure ?

How to search In a Structure ?

Scheduled Pinned Locked Moved Visual Basic
questiondatabasetutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Georg Kohler
    wrote on last edited by
    #1

    Before I go crazy on this I was wondering if somebody could point me in the right direction :-) I was trying to use a structure to store "datasets" Anyway: Creating / populating the structure seems straight forward

    Public Structure Test_Structure
    Public Name As String
    Public MapTo As String
    Public Description As String
    '......
    '....
    End Structure

    Dim TEST(10) as Test_Structure

    Test(0).Name = "FirstName"
    Test(1).Name= "SecondName

    But How do I now search / get the index for the Dataset containing the .name "FirstName" Should I use a Hashtable to store the index ???? Thanks georg

    C G 2 Replies Last reply
    0
    • G Georg Kohler

      Before I go crazy on this I was wondering if somebody could point me in the right direction :-) I was trying to use a structure to store "datasets" Anyway: Creating / populating the structure seems straight forward

      Public Structure Test_Structure
      Public Name As String
      Public MapTo As String
      Public Description As String
      '......
      '....
      End Structure

      Dim TEST(10) as Test_Structure

      Test(0).Name = "FirstName"
      Test(1).Name= "SecondName

      But How do I now search / get the index for the Dataset containing the .name "FirstName" Should I use a Hashtable to store the index ???? Thanks georg

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You would use foreach to iterate over your array and check each item for the value you want.

      Christian Graus Driven to the arms of OSX by Vista.

      G 1 Reply Last reply
      0
      • C Christian Graus

        You would use foreach to iterate over your array and check each item for the value you want.

        Christian Graus Driven to the arms of OSX by Vista.

        G Offline
        G Offline
        Georg Kohler
        wrote on last edited by
        #3

        Well if that's the "only" way, a Hashtable will be a lot faster I just can not belive there is not another way of indexing a Structure . One would think that indexing / searching is probabaly one of the most required tasks to be performe with a structure - But I might be wrong :-) Georg

        C 1 Reply Last reply
        0
        • G Georg Kohler

          Well if that's the "only" way, a Hashtable will be a lot faster I just can not belive there is not another way of indexing a Structure . One would think that indexing / searching is probabaly one of the most required tasks to be performe with a structure - But I might be wrong :-) Georg

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Well a structure doesn't automatically build indexes into all it's data, imagine how wasteful that would be if it did that even when not required. Yes, a hashtable would be faster.

          Christian Graus Driven to the arms of OSX by Vista.

          1 Reply Last reply
          0
          • G Georg Kohler

            Before I go crazy on this I was wondering if somebody could point me in the right direction :-) I was trying to use a structure to store "datasets" Anyway: Creating / populating the structure seems straight forward

            Public Structure Test_Structure
            Public Name As String
            Public MapTo As String
            Public Description As String
            '......
            '....
            End Structure

            Dim TEST(10) as Test_Structure

            Test(0).Name = "FirstName"
            Test(1).Name= "SecondName

            But How do I now search / get the index for the Dataset containing the .name "FirstName" Should I use a Hashtable to store the index ???? Thanks georg

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            First of all, you should not use a structure for this, you should use a class. A structure should not be larger than 16 bytes, and you break this if you have more than four string references. Also structures are tricker than classes to implement correctly. If you want a fast lookup for a field you can create a Dictionary with the field as key and the object as value.

            Despite everything, the person most likely to be fooling you next is yourself.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups