Associative Array using Visual Basic 6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashokbio
    New Member
    • Jul 2007
    • 14

    Associative Array using Visual Basic 6

    I want to create an associative array, similar to PERL language, using Visual Basic 6.

    Example: Using PERL

    %A = ("A"=>"Apple"," B"=>"Banana" );

    i.e., A is associated to the word Apple and B is associated to the word Banana. The alternative conversion is:

    $A{'A'} = "Apple";
    $A{'B'} = "Banana";

    Similarly i want the conversion in Visual Basic 6. Is it possible?

    ---------------------------------------------
    T. Ashok Kumar
    <email address removed>
    _______________ _____________
    Last edited by bartonc; Aug 5 '07, 07:48 PM. Reason: email address removed per site rules
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    You're better off asking this question in the Visual Basic forum.

    kind regards,

    Jos

    Comment

    • bartonc
      Recognized Expert Expert
      • Sep 2006
      • 6478

      #3
      I've removed you email address. Please see our Posting Guidelines. Thank you.

      Also moving from Member Introductions to the VB Forum.

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Definitely. What you're looking for is a Collection. It works in many ways similarly to an array, but rather than (or as well as) a numeric index, you can access it via a key that you supply when creating it.

        Check the doco for Collection.

        There is also a Dictionary object which I've heard is better in some ways than a collection, but I'm not familiar with it.

        Comment

        • Hassan Darwesh
          New Member
          • Aug 2007
          • 6

          #5
          Try this code

          'General
          Dim A(10) as String

          'form load
          sub form_load ()
          A(0) = "Apple"
          A(1)= "Banana"
          end sub

          this code will let you enter 11 String data in your array from A(0) to A(10) and you can also get the data the same way like

          text1.text = A(0) 'in the text you get Apple
          text2.text = A(1) 'in the text you get Banana

          you can also dim you array as integer , double or any other

          I wish that help you

          Comment

          • hariharanmca
            Top Contributor
            • Dec 2006
            • 1977

            #6
            Originally posted by Hassan Darwesh
            tray this code

            you can also dim you array as integer , double or any other

            I wish that help you
            Good Hassan, But he is looking for

            Originally posted by ashokbio
            $A{'A'} = "Apple";
            $A{'B'} = "Banana";
            and he never explain his requirement to give better suggessions.

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Yes, the question is not merely how to use an array, but how to use a key such as "A" or "B" to look something up "automatica lly" in the array. That's why I suggested using a Collection, which I believe covers this situation pretty well.

              Comment

              Working...