| View previous topic :: View next topic |
| Author |
Message |
Que Valued Newbie

Joined: 25 Aug 2001 Posts: 38 Location: Newaygo, MICH
|
Posted: Wed Aug 14, 2002 1:37 pm Post subject: Count of delimited items in a single list item |
|
|
I wondered if anyone may have already tackeled this one. I have a list of comma delimited items. If this list were in a standard datasheet, @count(1) would tell me how many rows. What will tell me how many columns?
Any help would be... well... cool  _________________ Que |
|
| Back to top |
|
 |
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1753 Location: Space and Time
|
Posted: Wed Aug 14, 2002 1:40 pm Post subject: |
|
|
This should work
| Code: |
:Unknown Parse
rem %o = Old String
rem %n = New Strin
rem %%item = search string
%%item = "1,2,3,4,5,6,7,8,9"
%o = ","
%n = @chr(13)@chr(10)
if @greater(@pos(%o,%%item), 0)
%s = %%item
repeat
if @greater(@pos(%o, %s), 0)
%p = @pos(%o, %s)
%s = @strdel(%s, %p, @sum(%p, @pred(@len(%o))))
%s = @strins(%s, %p, %n)
end
until @equal(@pos(%o, %s), 0)
%%item = %s
end
list create,1
list assign,1,%%item
info %%item
info @count(1)
exit
|
_________________ Chris
Http://theblindhouse.com |
|
| Back to top |
|
 |
Que Valued Newbie

Joined: 25 Aug 2001 Posts: 38 Location: Newaygo, MICH
|
Posted: Wed Aug 14, 2002 2:11 pm Post subject: |
|
|
Thanks.... I'm still working on the rest but that'l sure save me some time. _________________ Que |
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Wed Aug 14, 2002 5:01 pm Post subject: |
|
|
Here's a slightly different approach. It assumes
there's a minimum of one column, and no commas
in the data entries themselves...
| Code: |
%%item = "1,2,3,4,5,6,7,8,9"
%%fieldsep = ","
%%columns = 1
%x = 1
REPEAT
if @equal(@substr(%%item, %x), %%fieldsep)
%%columns = @succ(%%columns)
end
%x = @succ(%x)
UNTIL @greater(%x, @len(%%item))
INFO Columns = %%columns
|
Cheers, Mac  _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
 |
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Wed Aug 14, 2002 6:22 pm Post subject: |
|
|
More thoughts...
Standard delimited enclosed the data entries in quotes,
so it really uses these "," (two quotes and a comma)
as the data separators. And if the data entries include
commas, you're gonna need a more drastic approach
than either Liquidcode's or mine.
Assigning commas and quotes to VDS variables requires
using @chr(), so do this instead...
CREATE A TEXT FILE named "delimited.txt" in your VDS
folder, and save these 4 lines in it (include the blank line):
"1 "," 2 "," 3 "," 4 "," 5 "," 6 "," 7 "," 8 "," 9"
"1"
"1,0 "," 2,0 "," 3,0 "," 4,0 "," 5,0 "," 6,0 "," 7,0 "," 8,0 "," 9,0"
This code will load and display the column count for each entry.
NOTE: Don't load a large database into this "as is", unless ya
wanna be closing INFO windows for a while. Also, remove any
trailing spaces when ya copy/paste this code.
| Code: |
LIST CREATE, 1
rem -- May need the path here if you don't save this code to a file --
LIST LOADFILE, 1, delimited.txt
%%fieldsep = @chr(34)@chr(44)@chr(34)
%x = 0
REPEAT
%s = @item(1, %x)
if %s
%%columns = 1
else
%%columns = 0
end
REPEAT
%p = @pos(%%fieldsep, %s)
if @greater(%p, 0)
%s = @strdel(%s, %p, @sum(%p, 2))
%%columns = @succ(%%columns)
end
UNTIL @equal(%p, 0)
INFO Item %x Columns = %%columns
%x = @succ(%x)
UNTIL @equal(%x, @count(1))@greater(%x, @count(1))
|
EDIT - Added "@greater(%x, @count(1))" to prevent
continous loop if the "delimited.txt" file doesn't exist...
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
 |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|