[Gambas-user] Collections

Charlie Reinl Karl.Reinl at ...2345...
Sat Jan 16 12:25:56 CET 2010


Am Samstag, den 16.01.2010, 07:23 -0300 schrieb Pino Zollo:
> 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  
> -----------------------------------------------------
> 
Salut Pino,

my problem with your problem is:
That is just a piece of code, I can only run and debug, if I invent ALL
the rest. 

And so,every test will say nothing(if it is not a typo in that piece
code).

So please sent always a full run able gambas-archive. That has not to be
the whole project, but a part of it, which reach that piece of code
without any problems. I saw often the problem by producing such an
example.

  
-- 
Amicalement
Charlie





More information about the User mailing list