Il venerdì 15 gennaio 2010 17:39:14 hai scritto:
> Am Freitag, den 15.01.2010, 16:04 -0300 schrieb Pino Zollo:
> > DIM Dict AS NEW Collection
> > DIM Element AS String
> >
> > Dict["Blue"] = 3
> > Dict["Red"] = 1
> > Dict["Green"] = 2
> >
> > FOR EACH Element IN Dict
> >   PRINT Element;
> > NEXT
>
> Salut,
>
> did you ever more then run that code ? debug ? or looked whats a
> Collection ?
>
> OK, "Blue","Red" and "Green" are the KEY for the Collection Element,
> and so they declared and asigned.
>
> try that!
>
> PUBLIC SUB Main()
>    DIM Dict AS NEW Collection
>    DIM Element AS String
>
>    Dict["Blue"] = 3
>    Dict["Red"] = 1
>    Dict["Green"] = 2
>
>    FOR EACH Element IN Dict
>      PRINT Element
>      PRINT Dict.Key
>    NEXT
> END

Thanks Charlie,
I was trying to understand Collections better as I have a wrong behaviour in 
the following piece of code 
when I use an array of two strings as element; the key is an unique string.

The two print statements print exactly the same thing...the Lista.key is 
correct and all different, but the 
other ( ; Element[1];; "   ";; Element[0] ) print always the last element added 
to the structure.

If instead of using an Array[2] I use a single String joining the two strings 
into a single one, then all works 
perfectly....

...so I guess that there is a bug in how Structure handles Variant elements.

Just another example of my bad luck !
....or maybe I do not understand something.

Best regards

Pino
---------------------------------------------
DO WHILE i < MyArray.Count
            myStruc = MyArray.Pop()
            a = 0
              DO WHILE a < myStruc.Count
      '           DEBUG myStruc.Key(a);; myStruc.Value(a)  ' myStruc.dataType(a)
                Disp.DisRes.Text = Disp.DisRes.Text & myStruc.Key(a) & ": " & 
myStruc.Value(a) 
                WAIT 
                 Disp.DisRes.Pos = Len(Disp.DisRes.Text)
                 Disp.DisRes.EnsureVisible()
                INC a
              LOOP 
              Parti[0] = myStruc.Value(0)
              Parti[1] = myStruc.Value(2)
'               DEBUG Parti[0];; Parti[1];; myStruc.Value(1)
'               Lista.Add(Parti, myStruc.Value(1))    ' acts same as the 
following
              Lista[myStruc.Value(1)] = Parti
              DEBUG Lista.Count;; Lista[myStruc.Value(1)][1];; "   ";; 
Lista[myStruc.Value(1)][0] 
              Disp.DisRes.Text = Disp.DisRes.Text & "~~~~~~~~~"
            INC i
         LOOP 
         ' CBCommand.Clear
         ' CBComm2.Clear
         FOR EACH Element IN Lista 
              
              PRINT Lista.Key;; "   ";; Lista[Lista.key][1];; "   ";; 
Lista[Lista.key][0] 
              PRINT Lista.Key;; "   ";; Element[1];; "   ";; Element[0]

              ' SELECT CASE Element[1]
              '    CASE "n:s"
              '      CBCommand.Add(Lista.Key)
              '    CASE "s:n"
              '      CBComm2.Add(Lista.Key)
              ' END SELECT 
         NEXT  
-----------------------------------------------------

-- 
Key ID: 0xF6768208 
Key fingerprint = B16D 0A7C 5B29 A334 CE6A  71F6 EAF8 3D88 F676 8208
Key server: hkp://wwwkeys.eu.pgp.net

------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to