[Gambas-user] Problem with listbox
timothy
timothy.marshal-nichols at ...247...
Fri Jun 15 08:48:08 CEST 2007
> -----Original Message-----
> From: gambas-user-bounces at lists.sourceforge.net [mailto:gambas-user-
> bounces at lists.sourceforge.net] On Behalf Of Juanra
> Sent: Friday, 15 June 2007 07:01 AM
> To: mailing list for gambas users
> Subject: [Gambas-user] Problem with listbox
>
> HELLO,
>
> I HAVE A PROGRAM DONE IN PRAWNS WITH THE FUNCIONS "LISTBOX1.CONTENTS"
> THAT IN GAMBAS2 DOES NOT WORK.
>
> I WANT TO COPY THE CONTENT OF THE LISTBOX IN A FILE.
>
> LINK THIS....
>
> MCOMUN.LOGFINAL = ListBox1.Contents
> Dialog.Title = "GUARDAR FITXER DE VENDES ORDENAT"
> Dialog.Filter = ["*.*"]
>
> IF NOT Dialog.SaveFile() THEN
> File.Save(DIALOG.Path, MCOMUN.LOGFINAL)
> END IF
>
>
> HOW CAN I DO IT IN GAMBAS2 ??
>
> THANK
>
>
Hello Juanra,
In Gambas 1 the List property of a ListBox was a string and each item in
the ListBox was separated by a new line. In Gambas 2 this has been
changed to a string array. So it is not that difficult to convert your
code to gambas 2.
These examples show how you can open and save the content of a ListBox
to a text file.
Note that that there is at least one defect with these methods. If any
item strings in the ListBox contain new lines than they will be split
into two lines. Maybe not what you want.
' Open a text file for display in the ListBox
PUBLIC SUB ToolButtonOpen_Click()
Dialog.Filter = ["Lists (*.lst)", "Text Files (*.txt)", "All Files
(*)"]
IF Dialog.OpenFile() THEN RETURN
ListBox1.List = Split(File.Load(Dialog.Path), "\n")
CATCH
Message.Info("<b>Cannot load list:</b><br>" & Dialog.Path & "<hr>" &
Error.Text)
END
' Save the ListBox content to a text file
PUBLIC SUB ToolButtonSave_Click()
Dialog.Filter = ["Lists (*.lst)", "Text Files (*.txt)", "All Files
(*)"]
IF Dialog.SaveFile() THEN RETURN
File.Save(Dialog.Path, ListBox1.List.Join("\n"))
CATCH
Message.Info("<b>Cannot save list:</b><br>" & Dialog.Path & "<hr>" &
Error.Text)
END
Will this email make it? We shall see if I have been blacklisted form
source forge. Or may be it was to many people voting for Gambas.
Thanks
8-{)} Timothy Marshal-Nichols
<mailto: timothy.marshal-nichols at ...247...>
More information about the User
mailing list