List Box question !

BlitzPlus Forums/BlitzPlus Beginners Area/List Box question !

OverDozing(Posted 2005) [#1]
Hey,

I can't figure out how to retrieve the items contained in a List Box .
I mean, let's say we have 30 items in this list box. By pushing a button, I want the 30 items to be written to a txt file, but how do I get back theses 30 items ?


rdodson41(Posted 2005) [#2]
You have to get each item text, and then just write them to a file. When you open the file back up, you just have read the string, and make an item with that string.


OverDozing(Posted 2005) [#3]
But, how do I go from an item to an item ?
The index # wouldn't be organized, as I have many gadgets and entries stuff...
Would it be with a 'Eof' ? 'surprised'

I understand the string conversion process.


Lattyware(Posted 2005) [#4]
Do you mean this:

Window=CreateWindow( "...",0,0,160,120,0,1)
ListBox=CreateListBox( 0,0,130,70,window)

For a=0 To 29
AddGadgetItem ListBox,"... - "+a
Next

SelectGadgetItem ListBox,0

While WaitEvent()<>$803
Wend

file=OpenFile("DotDotDot.txt")
For b=0 To 29
main$= GadgetItemText$(ListBox,b)
WriteLine(file,main$)
Next

FreeGadget ListBox
CloseFile file

ListBox=CreateListBox( 0,0,130,70,window)

file=OpenFile("DotDotDot.txt")
For b=0 To 29
main$=ReadLine(file)
AddGadgetItem ListBox,Main$
Next

While WaitEvent()<>$803
Wend

End


OverDozing(Posted 2005) [#5]
Yeah, but the Indexes will not be organized as 1,2,3,4...
It will be more like 2,40,42,46,48,53,57... then I am having a problem to retrieve the Item as the indexes aren't organized...
Anyone have a solution/idea how to work this out ?
Thank you for the support :)


Lattyware(Posted 2005) [#6]
Hmm...
Instead of giving code I'll give a therory.

Save Item From Listbox.
Also Save Index On Next Line.

So you get:
... 1
2
... 4
58

In the file.

Then read both to temporary locations, sort them, and then re-read them.


OverDozing(Posted 2005) [#7]
I think, I get your idea, but I am not convinced, however, you bring me the idea of using temporary files while working the listing.
I guess this is how it has to be worked? The Listbox gadget would be only a reader (reading a tmp file), the buttons import,add,delete will work on a tmp file and not on the Listbox gadget. Then it will be easy to export! :)
Yeah should work! Awesome :)

Thank you for the help, I appreciate !

I am still open to any other solution, more simple/easy.... tested... :)


Lattyware(Posted 2005) [#8]
No problem, I like to think people would do the same for me, so in some way, some day, I will be returned...