Writes entries of a lister in a variable

Find quick help here to get you started with Hollywood
Post Reply
papiosaur
Posts: 161
Joined: Fri Mar 31, 2023 1:34 pm

Writes entries of a lister in a variable

Post by papiosaur »

Hello ,

i would like add entries (names of file) of a listview (lv1 for example) of RAPAGui in a variable (a$ for example)
Example:

File1
File2
File3
etc.

a$ = File1 .. File2 .. File3 .. etc.

How to do that please ?

Thanks a lot!
plouf
Posts: 468
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Writes entries of a lister in a variable

Post by plouf »

add it where?

if it strings (names) e.g "Calculator" "GoldED" you can with double dots as said

Code: Select all

Filename1$  = "Calculator"
Filename2$ = "GoldED"

all$ = Filename1$..Filename2$   ;all$ now is "CalculatorGoldED"
Christos
papiosaur
Posts: 161
Joined: Fri Mar 31, 2023 1:34 pm

Re: Writes entries of a lister in a variable

Post by papiosaur »

Sorry, i would like say from a "listview" and not "of" maybe.

I add file names in a listview with drag'n drop but i don't know how to write names of each entry in a variable like the example.

My code for the drag'drop is:

Code: Select all

Function p_EventFunc(msg)
Switch msg.Action
   Case "Ragagui"
       Switch msg.Attribute
       Case "DropFile"
             For local k = 0 to ListItems(msg.triggervalue)-1
                  f$ = msg.triggervalue[k]
                  moai.domethod("lv1", "insert", bottom", f$)
             Next
       Endswitch
 Endswitch
 Endfunction
 
plouf
Posts: 468
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Writes entries of a lister in a variable

Post by plouf »

Why dont you keep names when you get from event "DropFile"
Simultaneously to a variable AND additional insert it to listview

If, on the other hand, you point is to read listview entries you use GetEntry

https://www.hollywood-mal.com/docs/html ... Entry.html
Christos
User avatar
jPV
Posts: 603
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Writes entries of a lister in a variable

Post by jPV »

Yeah, you'll have to GetEntry for all items in the listview and process that data.

Code: Select all

Local a$ = ""
 ; Go through all entries in the listiview, index numbers start from 0, so from 0 to total entries minus one
For Local i = 0 To moai.Get("lv1", "Entries") - 1
    ; Get entry data for each index number into a local temp variable
    Local name$ = moai.DoMethod("lv1", "GetEntry", i)
    ; Process that data somehow, in this case just add it to another variable (a$)
    a$ = a$ .. name$
Next
ConsolePrint(a$)

Another option would be to use tables, and then you have data of the the whole listview in similar indexed way like in the listview, but in a table when it might be easier to proces or save etc without needing to get data from the listview all the time.

Code: Select all

Local mytable = {}
 ; Go through all entries in the listiview, index numbers start from 0, so from 0 to total entries minus one
For Local i = 0 To moai.Get("lv1", "Entries") - 1
    ; Get entry data for each index number into local temp variable
    Local name$ = moai.DoMethod("lv1", "GetEntry", i)
    ; Process that data somehow, in this case just add it into a table
    InsertItem(mytable, name$)
Next
; When you have all items in a table, you can process in in many ways, for example:
Local a$ = Concat(mytable)
ConsolePrint(a$)
; Or add a separator:
a$ = Concat(mytable, ", ")
ConsolePrint(a$)

Another option would store the data (filenames in this case) in two places, both in a global table and in the listview, but then you have to remember to add/remove/rename/arrange the data in both places, or render listview always according the table. This might be too complex for simple programs/data, but at some point when you do more complex programs, it might become handy to store data in a table with sub-tables when you can store more information for each item (more than is shown in the listview, for internal usage).
papiosaur
Posts: 161
Joined: Fri Mar 31, 2023 1:34 pm

Re: Writes entries of a lister in a variable

Post by papiosaur »

Thanks a lot plouf and jPV for your help, i will test that ;-)
papiosaur
Posts: 161
Joined: Fri Mar 31, 2023 1:34 pm

Re: Writes entries of a lister in a variable

Post by papiosaur »

Work perfectly !

Have a nice day !
Post Reply