July 02, 2024, 07:08:09 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


This is kind of basic

Started by oneplace2u, December 10, 2010, 05:35:15 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

oneplace2u

On each line of the birdhouse.txt there is a description of a birdhouse, this description is sometimes has over 400 charcters in it and it will only write about 250 to the birdhouse.sql file.
Is ther a way to have it read and write the full line?

openconsole
def sqlfile,ppname:file
def pn[800]:string
def b:int
def f:int
b = 0
f = 0
openfile(ppname,"C:\\test\\" + "birdhouse.txt", "R")
do
b = b + 1
read ppname,pn
until eof(ppname)
closefile ppname

openfile(sqlfile,"c:\\test\\birdhouse.sql", "W")
do

write sqlfile,   pn[f]

f = f + 1
until f >= b


closefile sqlfile
print "Press Any Key To Close"
closeconsole
END

LarryMc

you have to use ISTRING instead of STRING if you want to use strings longer than 255 characters.
openconsole
file sqlfile,ppname
istring pn[1000]
int count=0
openfile(ppname,"C:\\test\\birdhouse.txt", "R")
openfile(sqlfile,"c:\\test\\birdhouse.sql", "W")
WHILE EOF(ppname) = 0
READ ppname, pn
write sqlfile,pn
      count++
   ENDWHILE
closefile ppname
closefile sqlfile
print "There were"+str$(COUNT)+" lines read and written"
print
print "Press Any Key To Close"
waitcon
closeconsole
END


LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

oneplace2u


oneplace2u

If I wanted to write a certain row from the birdhouse.txt using the istring, how would I do that?
I used to beable to but the birdhouse.txt content into memory by using the:
openfile(ppname,"C:\\test\\" + "birdhouse.txt", "R")
do
b = b + 1
read ppname,pn[a]
until eof(ppname)
closefile ppname
f = 0
write sqlfile, pn[f+2]

I can do that any more becaause all it writes is numbers
is there another way of doing this using the istring










billhsln

Using Larry's code:

openconsole
file sqlfile,ppname
istring pn[1000]
int b=0, f=0
openfile(ppname,"C:\\test\\birdhouse.txt", "R")
openfile(sqlfile,"c:\\test\\birdhouse.sql", "W")
WHILE READ(ppname,pn) = 0
  b++
IF b = f+2 THEN write sqlfile,pn
ENDWHILE
closefile ppname
closefile sqlfile
print "There were"+str$(COUNT)+" lines read"
print
print "Press Any Key To Close"
waitcon
closeconsole
END


The above will only print when b = f+2.

Bill
When all else fails, get a bigger hammer.

oneplace2u

ok, that is good.
but in my birdhouse.txt I have four rows that needs to be written out and then the next four rows, so on until the file has been read and written out

like the following :

IF b = f+1 THEN write sqlfile,pn
IF b = f+2 THEN write sqlfile,pn
IF b = f+3THEN write sqlfile,pn
IF b = f+4 THEN write sqlfile,pn

but after this it needs to go and get the next four and so on until the file has been read and written

billhsln

December 11, 2010, 07:09:14 AM #6 Last Edit: December 11, 2010, 07:15:46 AM by billhsln
Based on what you are saying, it does not make any difference when it is read or written, you want to read the entire file and write it back out, more like doing a copy.  In which case, Larry's version does exactly what you are looking for.  Try and explain exactly what you are trying to do again.

It sounds like you want to read 4 records and the write 1 with all 4 read records on it with a delimiter?

Bill
When all else fails, get a bigger hammer.

billhsln

Based on what you are saying, it does not make any difference when it is read or written, you want to read the entire file and write it back out, more like doing a copy.  In which case, Larry's version does exactly what you are looking for.  Try and explain exactly what you are trying to do again.

It sounds like you want to read 4 records and the write 1 with all 4 read records on it with a delimiter?

Example:

Read:

a
b
c
d

Write:

a,b,c,d


Bill
When all else fails, get a bigger hammer.

oneplace2u

That is correct read 4 records and the write 1 with all 4 read records on it
a
b
c
d
Write:
a, b, c, d

and the same with the next four records that follow until all record are completed

oneplace2u

add comment:
I can get the four record on 1
but Iam not sure how to keep getting the next four record until the record is completed

billhsln

December 11, 2010, 09:22:28 AM #10 Last Edit: December 11, 2010, 09:24:24 AM by billhsln
Try this:
openconsole
file sqlfile,ppname
istring pn[400], ph1[400], ph2[400], ph3[400], ph4[400]
int b, ci, co
openfile(ppname,"C:\\test\\birdhouse.txt", "R")
openfile(sqlfile,"c:\\test\\birdhouse.sql", "W")
b = 0
WHILE READ(ppname,pn) = 0
  ci++
 b++
SELECT b
CASE 1
ph1 = pn
CASE 2
ph2 = pn
CASE 3
ph3 = pn
CASE 4
ph4 = pn
WRITE sqlfile, ph1, ph2, ph3, ph4
                        co++
ph1 = ""
ph2 = ""
ph3 = ""
ph4 = ""
b = 0
ENDSELECT
ENDWHILE
WRITE sqlfile, ph1, ph2, ph3, ph4
co++
closefile ppname
closefile sqlfile
print "There were ", ci, " lines read"
print "There were ", co, " lines written"
print
print "Press Any Key To Close"
waitcon
closeconsole
END


This is a fairly simple approach, but should do what you are looking for.  Also the last write is to make sure you get all the data, in case the file does not end up on an even multiple of 4.

Bill
When all else fails, get a bigger hammer.

oneplace2u

I have a question about "pn"
like
IF b = f+4 THEN write sqlfile,pn
that record is a price like 23.50
is it possible muliply that by two
and write the total 47.00 in place of the 23.50
I have tried to using
numbers = val(pn)
price = numbers * 2
write sqlfile, price

but it just writes 23.50

or in the code by bllhsln

using ph4 = pn

LarryMc

This should do it.
CASE 4
    ph4 = str$(val(pn)*2)
    WRITE sqlfile, ph1, ph2, ph3, ph4
    co++
    ph1 = "":ph2 = "":ph3 = "":ph4 = ""
    b = 0


LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

oneplace2u

Yes, I just figure that out, also in billhsln code I change the
WRITE sqlfile, ph1, ph2, ph3, ph4 to
WRITE sqlfile, ph1 + ph2 + ph3 + ph4

the , made it have and syntax error

Thank all of you for the help