Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Code not working part2
Message
From
09/07/2004 04:55:47
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00922340
Message ID:
00922426
Views:
11
>Hi all-
>
>I haVE THIS PIECE OF CODE THAT IS NOT WORKING? IT IS SUPPPOSE TO GIVE ME A THE BOOK NUMBER AND ALL THE CHAPTER IN THAT BOOK. THERE ARE 12 BOOKS AND BETWEEN 12 AND 30 CHAPTERS IN EACH BOOK
>
>the programs runs through only once and I get no output. it should run 12 times for the 12 books
>
>
>THANKS.
>
>LOCAL s1, s2, t_file, t_read, f, nchap, nbook
>LOCAL ARRAY aword[2], aword2[2]
>s1 = SECONDS()
>t_open = FOPEN("family.txt") && open test file WarandPeace.txt
>t_read = FREAD(t_open,6000000) && read text file
>s2 = SECONDS()
>?s2-s1, "Seconds"
>?LEN(t_read)
>FCLOSE(t_open)
>
>aword[1] = " the "
>aword[2] = " CHAPTER "
>
>
>
>f = FILETOSTR("FAMILY.txt")
>LOCAL lBook
>
>
>t_sec = 1
>lBook = getbook(f, t_sec)
>DO WHILE !EMPTY(lBook)
> ?"Book", t_sec
> nchap = ALINES(aword, lBook, " CHAPTER ")
> FOR x =1 TO nchap
> t_andcnt = occurs(" the ", aword[x])
> ?"Chapter ",x, ":", t_andcnt, "occurrences"
> ENDFOR
> t_sec= t_sec + 1
> lBook = getbook(f,t_sec)
>ENDDO
>
>FUNCTION getbook
> lparameters t_text, t_book
> LOCAL lsecstart, lsecend, llength, lBook
> lsecstart = AT("sec"+LTRIM(STR( t_book)), t_text)
> lsecend = AT("sec"+LTRIM(STR( t_book+1)), t_text)
> llength = IIF( lsecend=0,LEN( t_text), lsecend- lsecstart)
> lbook = SUBSTR( t_text, lsecstart, llength)
> RETURN SUBSTR( lbook,LEN("sec"+LTRIM(STR( t_book)))+1)
>ENDFUNC
As per your original message on this subject sections are named as 'sec1, sec2,...secN'. Here is a sample text :

sec1Introduction CHAPTER 1:Code works.
If it doesn't work refer to chapter 2. CHAPTER 2:Be sure sections are named as secN where N is the section number.
Using _CHAPTER_ (_ denote a space) as a parameter to alines is dangerous as it'd miss the CHAPTERs beginning on a new line.
sec2It's a good idea to provide some sample text to the audience.
sec3Shouting at people might distract them from trying to help.


And its output :
          0.016 Seconds
       413
Book          1
Chapter           1 :          0 occurrences
Chapter           2 :          0 occurrences
Chapter           3 :          2 occurrences
Book          2
Chapter           1 :          1 occurrences
Book          3
Chapter           1 :          0 occurrences
So what's that not working here ?
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform