Putting CSV items into a listbox

Putting CSV items into a listbox

Post by Ken Pawlu » Sun, 31 Dec 1899 09:00:00



I have a fields in a table which contains items separated by commas (except
the last item).  I want to put these into a list box.  I need some ideas.

ie.

Item1,Item2,Item3

needs to be

Item1
Item2
Item3

Ken

 
 
 

Putting CSV items into a listbox

Post by Bruce Robert » Sun, 31 Dec 1899 09:00:00


If what you have is something like

Field = "option1, option2, option3"

then

ListBox1.Items.CommaText := field.value

will produce a list box with the following lines
    option1
    option2
    option3

However, CommaText uses spaces or comma as a delimiter unless enclosed in
double quotes. Thus 'option 1, option 2, "option 3"' will produce
    option
    1
    option
    2
    option 3

If this is a problem, then the following should work (it won't handle
embedded commas)

procedure BreakUpOnCommas (str : string; list : tStrings);

var    i    : integer;

begin
if list <> nil
then begin
    list.clear;
    if str <> ''
    then begin
        i := pos (',', str);
        while i > 0 do
            begin
            list.add (trim (copy (str, 1, i - 1)));
            delete (str, 1, i);
            i := pos (',', str);
            end;
        // test is incase the line ends in a comma,
        // remove the test if this means an empty entry - but leave the
list.add (trim (str))
        if str <> ''
        then list.add (trim (str));
        end;
    end;
end;


Quote:> I have a fields in a table which contains items separated by commas
(except
> the last item).  I want to put these into a list box.  I need some ideas.

> ie.

> Item1,Item2,Item3

> needs to be

> Item1
> Item2
> Item3

> Ken


 
 
 

Putting CSV items into a listbox

Post by Ken Pawlu » Sun, 31 Dec 1899 09:00:00


Wow.  That's exactly what I needed. Thanks.
Ken


Quote:> If what you have is something like

> Field = "option1, option2, option3"

> then

> ListBox1.Items.CommaText := field.value

> will produce a list box with the following lines
>     option1
>     option2
>     option3

> However, CommaText uses spaces or comma as a delimiter unless enclosed in
> double quotes. Thus 'option 1, option 2, "option 3"' will produce
>     option
>     1
>     option
>     2
>     option 3

> If this is a problem, then the following should work (it won't handle
> embedded commas)

> procedure BreakUpOnCommas (str : string; list : tStrings);

> var    i    : integer;

> begin
> if list <> nil
> then begin
>     list.clear;
>     if str <> ''
>     then begin
>         i := pos (',', str);
>         while i > 0 do
>             begin
>             list.add (trim (copy (str, 1, i - 1)));
>             delete (str, 1, i);
>             i := pos (',', str);
>             end;
>         // test is incase the line ends in a comma,
>         // remove the test if this means an empty entry - but leave the
> list.add (trim (str))
>         if str <> ''
>         then list.add (trim (str));
>         end;
>     end;
> end;

 
 
 

1. Put URL based csv data into an *.mdb

Hi All...

I thought I had this thing partially cracked but then found the more I
persued the solution, the more I am convinced I am going about it all
wrong... thanks for you previous help on this ("Import test file into an
*.mdb, adding in a field..." - posted to microsoft.public.vb.database on 21
December) - but as stated, I need big picture help rather than bitsy...

I wanna download info from (the full URL...)
"http://chart.yahoo.com/table.csv?s=MSFT&a=1&b=1&c=1999&d=12&e=25&f=19...
&q=q&y=0&z=MSFT&x=.csv"

Into an access table with a schema of
Symbol, Text(20)
Date, Date/Time(Meduim Date)
Open, Single
High, Single
Low, Single
Close, Single
Vol, Single

As previously stated, I need to add in the first field. I understand how to
do this now (HUGE thanks Jim in Cleveland) but the rest would be an absolute
godsend...

Very many thanks in advance and Merry Christmas (and a problem free Y2K)

Nigel Kelly

2. Tracing changes

3. Prolly easy question: putting values in listbox

4. ADOX Keys Manipulation

5. Can you put field labels on a CSV file

6. Looking for a more capable QBE editor

7. putting the results of a query into a listbox

8. thread doesn′t run

9. VFP:listbox - select item

10. Adding items in to columns in a listbox

11. LISTBOX ITEMS.. PLEASE HELP

12. Multiple items in ListBox

13. choosing the right DB by listbox item