Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Program not working
Message
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Program not working
Miscellaneous
Thread ID:
00923486
Message ID:
00923486
Views:
49
hi everyone-

I need some help..
I have 2 problem. The first is the program does not seem to count the first chapter of every book so chapter1 is aways equal to zero.

The second problem I have is I have is have have appendix sections after the book and I need to reset the chapters so the strta over again for the appendix and not include the appendix chapters in the last book.

example:
book12 25 chapters
i want the results to look like
book12 10 chapters
appendix1 8 chapters
appendix2 7 chapters

Thanks


LOCAL s1, s2, t_file, t_read, f, nchap, nbook, book, outfile
LOCAL ARRAY aword[5]
s1 = SECONDS()
t_open = FOPEN("warandpeace.txt") && open test file WarandPeace.txt
t_read = FREAD(t_open,6000000) && read text file
s2 = SECONDS()
?s2-s1, "Seconds" && number of seconds to read text file (war and peace)
?
?


CREATE TABLE wandp(book i, chapter i , wtext m) && create table

f = FILETOSTR("warandpeace.txt")
LOCAL lBook
nbook = 1
book = 1
num = 0
nchap = 0
lBook = getbook(m.f, m.nbook)

DO WHILE !EMPTY(m.lBook)
?' Book ', m.nbook
nchap = ALINES(aword, m.lBook, " CHAPTER ")
? "BOOK", nbook, "has ", nchap, " chapters.... "
FOR x =1 TO nchap
t_andcnt = occurs(" and ", aword[x])
?"Chapter ",x, ":", t_andcnt, "occurrences of the word....and"
ENDFOR
nbook = nbook + 1
lBook = GETBOOK(m.f,nbook)
ENDDO



DO WHILE !EMPTY(m.lBook)
?' Book ', m.nbook
nchap = ALINES(aword, m.lBook, " CHAPTER ")
* num = num + 1
FOR x =1 TO nchap
t_andcnt = occurs(" and ", aword[x])
?"Chapter ",x, ":", t_andcnt, "occurrences of the word....and"

i = AT(" CHAPTER ", f, 2)
IF i > 0
t_chapter = LEFT(f, i-1)
f = SUBSTR(f,i)
ELSE
t_chapter = f
f = ""
ENDIF
INSERT INTO wandp VALUES (nbook, x, t_chapter) && inserts book number, chapter, and text of each chapter into seperate entries
IF (chapter%2) =1
outfile = "w&p-" + transform(nbook) + "-" + transform(x)+".txt" && formats output name for text file
* COPY MEMO wtext TO (m.outfile) && copies memo field to text file
ENDIF
ENDFOR
nbook = nbook + 1
lBook = GETBOOK(m.f,nbook)
ENDDO

=Fclose("warandpeace.txt") && close text file

CLOSE DATABASES
SELECT * FROM wandp WHERE (chapter%2) =1 INTO TABLE wandp_odd && copy odd chapters to table


****** function for finding the word BK for each book
******------------------------------------------------
FUNCTION GETBOOK
lparameters t_text, t_book
LOCAL lsecstart, lsecend, llength, lBook
lbookstart = AT('BK'+LTRIM(STR( m.t_book)), m.t_text)
lbookend = AT('BK'+LTRIM(STR( m.t_book+1)), m.t_text)
llength = IIF( lbookend=0,LEN( m.t_text), m.lbookend- m.lbookstart)
lbook = SUBSTR( m.t_text, m.lbookstart, m.llength)
RETURN SUBSTR( m.lbook,LEN('BK'+LTRIM(STR( m.t_book)))+1)
ENDFUNC
Next
Reply
Map
View

Click here to load this message in the networking platform