1. find() can't find ","???

Trying to use find() to find a comma in a comma-delimited ascii input file, but
with no success.  It's really essential
for me to know where the first object in the data ends. (I could use a 'get()'
loop, accessing each object, and then
length() for what I need, but that gets kind of kludgey.

Seems to me that gets() ignores the comma in the data, perhaps recognizing it as
the end-of-object marker, and Find()
can't find it.

I'm sure many others have encountered the problem and have devised a slick
solution. But, I'm at my wits end.

Hope some kind soul will offer a solution.

Program listing (not too big) is below, and includes a few lines of sample data
from the comma-delimitd file.

Thanks.

Jim

-- Update.ex
-- read Todays.txt as control to select table, and update table with the
-- Todays.txt record.
include get.e
include file.e
include misc.e
include database.e
include wildcard.e
include jimlib.e

with trace
-- without warning
allow_break(1)

sequence TableNames,TableNamesSorted,TableToRead,DataFile,FileName,
         ContCode,Date,Open,High,Low,Close,Volume,OpenInt,OutputRec,Data

integer  TableNo

atom     a,b,c,EOF

object   fn,Todays,UpdateRec,wait,InsertRec

constant SCREEN = 1,true = 1,false = 0, KEYBOARD = 0
---------------------------------------------------------------------------------

clear_screen()

if db_open("COMMDATA", DB_LOCK_EXCLUSIVE) != DB_OK then  -- if doesn't exist
   puts(SCREEN, "Could not open database COMMDATA.EDB. Aborting ...\n")
end if

TableNames = db_table_list()
-- sort table names
TableNamesSorted = sort(TableNames)
TableNames       = TableNamesSorted


fn = open("TODAYS.TXT","rb")
if fn = -1 then puts(SCREEN,"Could not open TODAYS.TXT.. aborting ...") 
abort(1)
end if
Todays = fn

while true do
UpdateRec = gets(Todays) --
      ContCode,Date,Open,High,Low,Close,Volume,OpenInt
      if equal(UpdateRec, -1) then
         exit
      end if
---------------------------------------------------------------------------
      -- SAMPLE DATA
      --  AD00U,20000913,55.45,55.70,55.42,55.56,3086,14492
      --  AD00Z,20000913,55.20,55.60,55.30,55.55,3285,17312
      --  C00U,20000913,183.50,183.75,180.25,180.50,7030,3679
      --  C00X,20000913,190.50,190.75,187.25,187.50,601,2791
      --  C00Z,20000913,195.25,195.25,191.25,191.50,51692,217958
      --  CC00U,20000913,796,798,793,798,28,36
      --  CC00Z,20000913,817,840,817,838,1536,52269
--------------------------------------------------------------------------

--        FileName = UpdateRec[1..find(",",UpdateRec)]      -- DOESN'T
      FIND IT
--        FileName = UpdateRec[1..find(44,UpdateRec)]       -- DOESN'T
      FIND IT
      --        object comma     comma = ','
--        FileName = UpdateRec[1..find(comma,UpdateRec)]    -- DOESN'T
      FIND IT

-------------      Below works OK, but only because of the uniqueness
            of the data       --------------
      FileName = UpdateRec[1..5]
      Date = UpdateRec[7..14]
      Data = UpdateRec[7..length(UpdateRec) -1]
if numeric(FileName[2..3])         then                  --  pos. 5 is a
      comma
         FileName = UpdateRec[1..4]
         Date = UpdateRec[6..13]
         Data = UpdateRec[6..length(UpdateRec) -1]
      end if
      TableToRead = upper(FileName)

      if db_select_table(TableToRead) != DB_OK then
         clear_screen()
         position(10,1)
         puts(1,"\n"&TableToRead&" not found. Aborting ...\n")  abort(1)
      end if

      -- update table

      InsertRec = db_insert(Date,Data)
      if equal(InsertRec, "DB_EXISTS_ALREADY")  then
         printf(1,"%s", {FileName}) puts(1,"  ") printf(1,"%s ",{Date})
         puts(1," already exists. Bypassing...\n")
      else
         printf(1,"%s", {FileName}) puts(1,"  ") printf(1,"%s \n",{Date})
      end if
end while

db_close()
close(Todays)

new topic     » topic index » view message » categorize

2. Re: find() can't find ","???

On Sun, 17 Sep 2000 15:02:58 -0400, Jim <futures8 at PCOLA.GULF.NET> wrote:

>Trying to use find() to find a comma in a comma-delimited ascii input
file, but with no success.  It's really essential

   Jim:

-- run this code

? find(",", "comma is here, somewhere")

? find(',', "comma is here, somewhere")

-- Bernie

new topic     » goto parent     » topic index » view message » categorize

3. Re: find() can't find ","???

Hi, Bernie.

Thanks for the advice, and the lesson. Problem solved, of course.

Much appreciated.

Regards, Jim

Bernie wrote:

> On Sun, 17 Sep 2000 15:02:58 -0400, Jim <futures8 at PCOLA.GULF.NET> wrote:
>
> >Trying to use find() to find a comma in a comma-delimited ascii input
> file, but with no success.  It's really essential
>
>    Jim:
>
> -- run this code
>
> ? find(",", "comma is here, somewhere")
>
> ? find(',', "comma is here, somewhere")
>
> -- Bernie

new topic     » goto parent     » topic index » view message » categorize

4. Re: find() can't find ","???

On 17 Sep 2000, at 17:13, Bernie wrote:

> On Sun, 17 Sep 2000 15:02:58 -0400, Jim <futures8 at PCOLA.GULF.NET> wrote:
>
> >Trying to use find() to find a comma in a comma-delimited ascii input
> file, but with no success.  It's really essential
>
>    Jim:
>
> -- run this code
>
> ? find(",", "comma is here, somewhere")
>
> ? find(',', "comma is here, somewhere")

Or, try:

? gettok("comma is here, somewhere,somehow" , 1 , ',' )
? gettok("comma is here, somewhere,somehow" , 2 , ',' )
? gettok("comma is here, somewhere,somehow" , 3 , ',' )

comma is here
somewhere
somehow

Kat

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu