Jump to content
UBot Underground

Populate List With Text


Recommended Posts

i have a csv file with dept names in separate lines lik

MOVIES

BEAUTY

BOOKS

 

i have a variable called list count which gets randomly generated with a value btwen 0 and 5. no based on this number i m trying to create a new list and repeat the dept above in different rows on the list . 

e.g

listcount=3

 

%dept= [0]->dept

             [1]->MOVIES

             [2]->MOVIES

 

listcount=4

 

            [3]->BEAUTY

            [4]->BEAUTY

            [5]->BEAUTY

 

and so on but it doesnt add the items to create the list as above ...instead it creates he list as

 

%dept [0]->dept

           [1]->MOVIES

           [2]->BEAUTY

           [3]->BOOKS

 

ui open file("file", #myfile)
create table from file(#myfile, &mydb)
set(#totalcategories, $table total rows(&mydb), "Global")
set(#row, 0, "Global")
clear list(%dept)
add item to list(%dept, "dept", "Delete", "Global")
set(#listpos, 1, "Global")
loop while(#row < #totalcategories) {
    set(#dept, $table cell(&mydb, #row, 0), "Global")
    set(#listcount, $rand(1, 5), "Global")
    set(#totallist, $eval($add(#listpos, #listcount)), "Global")
    loop while(#listpos < #totallist) {
        set(#tmpdept, $next list item(%dept), "Global")
        set list position(%dept, #listpos)
        add item to list(%dept, #dept, "Delete", "Global")
        increment(#listpos)
    }
    increment(#row)
}
alert("done")
stop script
Edited by littledevil
Link to post
Share on other sites

I am a bit lost on what you are trying to do, maybe you can break it down a bit more and add some sample data to explain a bit more?

 

Anyways, I noticed you want to repeat something, and in your code you are removing duplicate items from the list. This may be part of your problem so I made a slight tweak to change that. I don't know if it will help - since I'm unclear what you are trying to do - but it may help:

ui open file("file",#myfile)
create table from file(#myfile,&mydb)
set(#totalcategories,$table total rows(&mydb),"Global")
set(#row,0,"Global")
clear list(%dept)
add item to list(%dept,"dept","Delete","Global")
set(#listpos,1,"Global")
loop while(#row < #totalcategories) {
    set(#dept,$table cell(&mydb,#row,0),"Global")
    set(#listcount,$rand(1,5),"Global")
    set(#totallist,$eval($add(#listpos,#listcount)),"Global")
    loop while(#listpos < #totallist) {
        set(#tmpdept,$next list item(%dept),"Global")
        set list position(%dept,#listpos)
        add item to list(%dept,#dept,"Don\'t Delete","Global")
        increment(#listpos)
    }
    increment(#row)
}
alert("done")
stop script
  • Like 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...