1. win32lib: List's

hello list.

I am using win32lib v 0.57.9 and have a List.

I have a loop that uses insertItem().

i am using: insertItem(id,text,1) but..
everything that gets added ends up at then end of the list instead of the
top.
So what do I use to add it at the top ?

Thanks
    Robert Szalay

new topic     » topic index » view message » categorize

2. Re: win32lib: List's

Robert,

The function works ok for me; I just ran the following mod of ex06.exw,
under 57.9, and it gave me the inserted numbers, in order, at the top of the
list without problem.  The mod is marked in the procedure "Load_Win".

Of course, if you insert *everything* at position 1, the inserts will show
up in reverse order, with the last item inserted being at position 1 & all
others previously inserted being below it.

Dan Moyer

-- example6.exw  (modified to demo inserting items at the top of the list)
--
-- This opens a window with a populated list in it.

include win32lib.ew
without warning

constant cr = { 13, 10 }

constant
    Win   = create( Window, "List", 0, Default, Default, 200, 220, 0 ),
    List1 = create( List, "", Win, 10, 10, 120, 140, 0 ),
    Button1 = create( PushButton, "Info...", Win, 10, 150, 60, 32, 0 )

object dummy

procedure Load_Win(integer self, integer event, sequence parms)

    -- build the list
    addItem( List1, "one" )
    addItem( List1, "two" )
    addItem( List1, "three" )
    addItem( List1, "four" )
    addItem( List1, "five" )
    addItem( List1, "six" )
    addItem( List1, "seven" )
    addItem( List1, "eight" )
    addItem( List1, "nine" )
    addItem( List1, "ten" )

-- ADDED THIS TO TEST FOR INSERTING ITEMS AT TOP OF LIST:
    for n = 1 to 10 do
      dummy = insertItem(List1, sprint(n), n)
   end for

end procedure

procedure Click_Button1(integer self, integer event, sequence parms )
    integer index
    object result

    -- get index
    index = getIndex( List1 )

    result = message_box(
        sprintf( "List Count = %d ", {getCount(List1)} ) & cr &
        sprintf( "Selected Item Index = %d ", { index } ) & cr &
        sprintf( "Selected Item Text = %s ", {getItem(List1,index)} ),
        "List Information", 0 )

end procedure

setHandler(Button1, w32HClick,    routine_id( "Click_Button1" ))
setHandler(Win,     w32HActivate, routine_id( "Load_Win" ))

WinMain( Win, Normal )



----- Original Message -----
From: "Robert Szalay" <robsz1 at netzero.net>
To: "EUforum" <EUforum at topica.com>
Sent: Friday, November 01, 2002 6:42 PM
Subject: win32lib: List's


>
> hello list.
>
> I am using win32lib v 0.57.9 and have a List.
>
> I have a loop that uses insertItem().
>
> i am using: insertItem(id,text,1) but..
> everything that gets added ends up at then end of the list instead of the
> top.
> So what do I use to add it at the top ?
>
> Thanks
>     Robert Szalay
>
>
>
>

new topic     » goto parent     » topic index » view message » categorize

3. Re: win32lib: List's

Robert,
I agree that insertItem(lst,text,1) does not insert at the top of the list.
I don't know why 'cos that's what the API says it should do.

However, insertItem(lst,text,0) does work. Also, the addItem() function
works too.

My example code...

include win32lib.ew
without warning
integer win, lst1
win =  create(Window, "Simple List",    0,   0,  0, 400, 400, 0)
lst1 = create(List, "", win, 5,5, 350, 340, 0)
constant LISTTOP = 0
VOID = insertItem(lst1, "One", LISTTOP)
VOID = insertItem(lst1, "Two", LISTTOP)
VOID = insertItem(lst1, "Three", LISTTOP)
VOID = insertItem(lst1, "Four", LISTTOP)
WinMain(win, Normal)



----------------
cheers,
Derek Parnell
----- Original Message -----
From: "Robert Szalay" <robsz1 at netzero.net>
To: "EUforum" <EUforum at topica.com>
Sent: Saturday, November 02, 2002 1:42 PM
Subject: win32lib: List's


>
> hello list.
>
> I am using win32lib v 0.57.9 and have a List.
>
> I have a loop that uses insertItem().
>
> i am using: insertItem(id,text,1) but..
> everything that gets added ends up at then end of the list instead of the
> top.
> So what do I use to add it at the top ?
>
> Thanks
>     Robert Szalay
>
>
>
>

new topic     » goto parent     » topic index » view message » categorize

4. Re: win32lib: List's

Derek, Robert,

I don't understand this-- I *don't* get the problem Robert described when I
put :

    for n = 1 to 10 do
      dummy = insertItem(List1, sprint(n),n)
   end for

into "ex06.exw" AFTER all the addItems in "LoadWin()".

What I do get is a list of numbers (digits) 1-10, followed by a list of
numbers (text) one thru ten, just as would be expected.

And even when I initially inserted every number in at position 1,
      dummy = insertItem(List1, sprint(n),1)
I still got them all inserted at the *top* of the list, each after the
previous, into position 1, resulting in a list of 10-1 at the top, and "one"
thru "ten" at the bottom of the list.


Maybe there's some platform problem?  I'm running under Win98 1st ed.

Dan Moyer

----- Original Message -----
From: "Derek Parnell" <ddparnell at bigpond.com>
To: "EUforum" <EUforum at topica.com>
Sent: Friday, November 01, 2002 11:36 PM
Subject: Re: win32lib: List's


>
> Robert,
> I agree that insertItem(lst,text,1) does not insert at the top of the
list.
> I don't know why 'cos that's what the API says it should do.
>
> However, insertItem(lst,text,0) does work. Also, the addItem() function
> works too.
>
> My example code...
>
> include win32lib.ew
> without warning
> integer win, lst1
> win =  create(Window, "Simple List",    0,   0,  0, 400, 400, 0)
> lst1 = create(List, "", win, 5,5, 350, 340, 0)
> constant LISTTOP = 0
> VOID = insertItem(lst1, "One", LISTTOP)
> VOID = insertItem(lst1, "Two", LISTTOP)
> VOID = insertItem(lst1, "Three", LISTTOP)
> VOID = insertItem(lst1, "Four", LISTTOP)
> WinMain(win, Normal)
>
>
> ----------------
> cheers,
> Derek Parnell
> ----- Original Message -----
> From: "Robert Szalay" <robsz1 at netzero.net>
> To: "EUforum" <EUforum at topica.com>
> Sent: Saturday, November 02, 2002 1:42 PM
> Subject: win32lib: List's
>
>
> > hello list.
> >
> > I am using win32lib v 0.57.9 and have a List.
> >
> > I have a loop that uses insertItem().
> >
> > i am using: insertItem(id,text,1) but..
> > everything that gets added ends up at then end of the list instead of
the
> > top.
> > So what do I use to add it at the top ?
> >
> > Thanks
> >     Robert Szalay
> >
> >
>
>
>

new topic     » goto parent     » topic index » view message » categorize

5. Re: win32lib: List's

Hello Dan.

This is what was happening..

(not actually but similar)

I had a sequence of items. say:
s = {"a","b","c","d"}

then, i did:

for i = 1 tl length(s) do
    <some code>
    junk = insertItem(mylist,s[i],1)
end for

The result was:::
a
b
c
d

Well, I was going for the reverse of this.  i.e.:::
d
c
b
a


does that help at clarification ?

Regards, 
    Robert Szalay

new topic     » goto parent     » topic index » view message » categorize

6. Re: win32lib: List's

Robert,

I understand what you are trying to do, but my point is that when I do what
you say you're doing, I get the results you *want*, not the results you say
you *get*.

The following re-mod of ex06.exw includes your sample code, and the result I
get is
d
c
b
a
above one thru ten in text.

Try it & see what you get; I'm running under Win98 1st ed, what are you
running under?

Of course, you could just use "reverse" on the sequence, or go from length
to 1 instead of from  1 to length, but if there is a platform problem, that
would just make it work ok on some & not ok on other platforms.

Dan Moyer


-- example6.exw  (modified to test order of insertItem)
--
-- This opens a window with a populated list in it.

include win32lib.ew
without warning

constant cr = { 13, 10 }

constant
    Win   = create( Window, "List", 0, Default, Default, 200, 220, 0 ),
    List1 = create( List, "", Win, 10, 10, 120, 140, 0 ),
    Button1 = create( PushButton, "Info...", Win, 10, 150, 60, 32, 0 )

object junk
sequence s
s = {"a","b","c","d"}


procedure Load_Win(integer self, integer event, sequence parms)

    -- build the list
    addItem( List1, "one" )
    addItem( List1, "two" )
    addItem( List1, "three" )
    addItem( List1, "four" )
    addItem( List1, "five" )
    addItem( List1, "six" )
    addItem( List1, "seven" )
    addItem( List1, "eight" )
    addItem( List1, "nine" )
    addItem( List1, "ten" )

for i = 1 to length(s) do
--<some code>
junk = insertItem(List1,s[i],1)
end for



end procedure

procedure Click_Button1(integer self, integer event, sequence parms )
    integer index
    object result

    -- get index
    index = getIndex( List1 )

    result = message_box(
        sprintf( "List Count = %d ", {getCount(List1)} ) & cr &
        sprintf( "Selected Item Index = %d ", { index } ) & cr &
        sprintf( "Selected Item Text = %s ", {getItem(List1,index)} ),
        "List Information", 0 )

end procedure

setHandler(Button1, w32HClick,    routine_id( "Click_Button1" ))
setHandler(Win,     w32HActivate, routine_id( "Load_Win" ))

WinMain( Win, Normal )



----- Original Message -----
From: "Robert Szalay" <robsz1 at netzero.net>
To: "EUforum" <EUforum at topica.com>
Sent: Saturday, November 02, 2002 10:47 PM
Subject: Re: win32lib: List's


>
> Hello Dan.
>
> This is what was happening..
>
> (not actually but similar)
>
> I had a sequence of items. say:
> s = {"a","b","c","d"}
>
> then, i did:
>
> for i = 1 tl length(s) do
>     <some code>
>     junk = insertItem(mylist,s[i],1)
> end for
>
> The result was:::
> a
> b
> c
> d
>
> Well, I was going for the reverse of this.  i.e.:::
> d
> c
> b
> a
>
>
> does that help at clarification ?
>
> Regards,
>     Robert Szalay
>
>
>
>

new topic     » goto parent     » topic index » view message » categorize

7. Re: win32lib: List's

Ummm...
  OOooops!

I managed to get that mixed around.
what I was going for was:

A
B
C
D
E


It was outputing the opposite.


Regards, 
    Robert Szalay

---------------------------------------------

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu