Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VFP6 OK in dev. mode, .exe clanks 1

Status
Not open for further replies.

Headwinds

Programmer
Feb 6, 2001
38
0
0
US
I've got a function that searches a text file, locates strings that appear to be acronyms, and outputs a spreadsheet listing the candidate acronyms. It runs fine in development mode, but when I compile it and run it from the .exe file on the same PC on which I have VFP installed, it hangs.

When it gets stuck, it's at the end of a line in the text file and keeps reading the same CRLF over and over (even though it has already successfully processed lots of prior lines. I've inspected the point at which it clanks and don't see anything special there: the 0D0A (CRLF) there looks like all the others. I've even tried starting processing after that point, and it just runs down and goes into an infinite loop somewhere else.

So why does this work before I compile it but not after--on the same machine?

Thanks,

Jim
 
Code:
FUNCTION find_acro_work2
CREATE CURSOR acrolist (acronym C(9))
CREATE CURSOR holder_lb (thistext C(254))
SELECT holder_lb
m.target_file = GETFILE("Text:TXT")
m.target_path = LEFT(m.target_file, RAT("\", m.target_file))
IF NOT(EMPTY(m.target_file))
	m.dostring = "SET ALTERNATE TO '" + m.target_path + "acro_log.txt'"
	&dostring
	m.dostring = "APPEND FROM '" + m.target_file + "' TYPE SDF"
	&dostring
ELSE
	MESSAGEBOX("Can't find the file you want to work on.", 0, "No File!")
	RETURN
ENDIF
m.new_one = "x"		&& Working string, might turn out to be an acronym
m.maybe = .F.		&& If .T., maybe m.new_one is a good acronym
m.start = .F.		&& If .T., m.new_one has only a single character
SCAN  
	m.this_string = RTRIM(holder_lb.thistext)
*!*	Skip empty strings
	IF EMPTY(m.this_string)
		LOOP
	ENDIF
*!*	Iterate through each string
	m.knt = 1
	DO WHILE m.knt <= LEN(m.this_string)
*!*	Save acronyms between 2 and 9 characters long, if they're new
		IF BETWEEN(LEN(m.new_one), 2, 9) AND m.maybe = .T. AND !ISDIGIT(RIGHT(m.new_one, 1)) ;
				AND RIGHT(m.new_one, 1) != "'" AND RIGHT(m.new_one, 1) != "/" AND ;
				!(LEN(m.new_one) = 2 AND LEFT(m.new_one, 1) == "V") AND ;
				m.new_one != "ALL" AND ;
				m.new_one != "AND" AND ;
				m.new_one != "APPENDIX" AND ;
				m.new_one != "AUGUST" AND ;
				m.new_one != "CATALOG" AND ;
				m.new_one != "CLEAN" AND ;
				m.new_one != "COMMENT" AND ;
				m.new_one != "CROSS" AND ;
				m.new_one != "DOCUMENT" AND ;
				m.new_one != "DOCUMENTS" AND ;
				m.new_one != "DRAFT" AND ;
				m.new_one != "FORMS" AND ;
				m.new_one != "FUNCTION" AND ;
				m.new_one != "GENERAL" AND ;
				m.new_one != "IDEA" AND ;
				m.new_one != "IMMEDIATE" AND ;
				m.new_one != "INTERFACE" AND ;
				m.new_one != "LOGTEC" AND ;
				m.new_one != "NEAR" AND ;
				m.new_one != "NO" AND ;
				m.new_one != "NOT" AND ;
				m.new_one != "NOTE" AND ;
				m.new_one != "OBJECTIVE" AND ;
				m.new_one != "OF" AND ;
				m.new_one != "OR" AND ;
				m.new_one != "ORDERS" AND ;
				m.new_one != "PLANNING" AND ;
				m.new_one != "PRINCIPAL" AND ;
				m.new_one != "PROVIDED" AND ;
				m.new_one != "REFERENCE" AND ;
				m.new_one != "ROLE" AND ;
				m.new_one != "SNAPSHOT" AND ;
				m.new_one != "SOURCE" AND ;
				m.new_one != "SUMMARY" AND ;
				m.new_one != "SYSTEMS" AND ;
				m.new_one != "TABLE" AND ;
				m.new_one != "TERM" AND ;
				m.new_one != "TOS" AND ;
				m.new_one != "UP" AND ;
				m.new_one != "WITH" AND ;
				m.new_one != "WORKFLOW"
			SELECT acrolist
			LOCATE FOR RTRIM(acrolist.acronym) == m.new_one
			IF !FOUND('acrolist')
				INSERT INTO acrolist (acronym) VALUES (m.new_one)
			ENDIF
			m.maybe = .F.
		ENDIF
		IF ISUPPER(SUBSTR(m.this_string, m.knt, 1)) AND ISALPHA(SUBSTR(m.this_string, m.knt, 1))
*!*	Mark as a candidate acronym and start watching to see if it is an acronym
			m.new_one = SUBSTR(m.this_string, m.knt, 1)	
			m.start = .T.
*!*	Loop until you reach something that wouldn't be in an acronym
			DO WHILE ISUPPER(SUBSTR(m.this_string, m.knt, 1)) OR ;
					(!ISALPHA(SUBSTR(m.this_string, m.knt, 1)) AND ;
					SUBSTR(m.this_string, m.knt, 1) != " " AND ;
					SUBSTR(m.this_string, m.knt, 1) != "." AND ;
					SUBSTR(m.this_string, m.knt, 1) != "!" AND ;
					SUBSTR(m.this_string, m.knt, 1) != "," AND ;
					SUBSTR(m.this_string, m.knt, 1) != "[" AND ;
					SUBSTR(m.this_string, m.knt, 1) != "]" AND ;
					SUBSTR(m.this_string, m.knt, 1) != "(" AND ;
					SUBSTR(m.this_string, m.knt, 1) != ")" AND ;
					SUBSTR(m.this_string, m.knt, 1) != ":" AND ;
					SUBSTR(m.this_string, m.knt, 1) != '"' AND ;
					SUBSTR(m.this_string, m.knt, 1) != "*" AND ;
					SUBSTR(m.this_string, m.knt, 1) != "-" AND ;
					SUBSTR(m.this_string, m.knt, 1) != ";" AND ;
					SUBSTR(m.this_string, m.knt, 1) != CHR(9) AND ;
					SUBSTR(m.this_string, m.knt, 1) != CHR(10) AND ;
					SUBSTR(m.this_string, m.knt, 1) != CHR(13) AND ;
					SUBSTR(m.this_string, m.knt, 1) != "_")
				IF m.start = .T.
					m.start = .F.
				ELSE
					m.new_one = m.new_one + SUBSTR(m.this_string, m.knt, 1)
				ENDIF
				m.knt = m.knt + 1
			ENDDO
*!*	If the next character is a word terminator, maybe m.new_one is an acronym.
			IF (SUBSTR(m.this_string, m.knt, 1) != " " OR ;
					SUBSTR(m.this_string, m.knt, 1) != "." OR ;
					SUBSTR(m.this_string, m.knt, 1) != ";" OR ;
					SUBSTR(m.this_string, m.knt, 1) != CHR(9) OR ;
					SUBSTR(m.this_string, m.knt, 1) != CHR(10) OR ;
					SUBSTR(m.this_string, m.knt, 1) != CHR(13) OR ;					
					SUBSTR(m.this_string, m.knt, 1) != ",")
				m.maybe = .T.
			ELSE
				m.maybe = .F.
			ENDIF
		ELSE
			m.knt = m.knt + 1
		ENDIF
	ENDDO
	SELECT holder_lb
ENDSCAN
SELECT * FROM acrolist ORDER BY acronym INTO CURSOR acrolist1
SELECT acrolist1
BROWSE
SET SAFETY OFF
m.dostring = "COPY TO '" + m.target_path + "acrolist.xls' TYPE XL5"
&dostring
SET SAFETY ON
ENDFUNC
 

Jim,

I can see what you are doing, but I'm not clear on which line the code is hanging. Could you clarify.

One point: I wonder if you are hitting a problem with the length of some of your lines of code. They don't look like they are approaching the limit, but it might be worth checking, and simplifying them where possible.

For example, the long construct that includes m.new_one != could be comnsiderably shortened and simplified by using the INLIST() function. Similarly, in the DO WHILE that has those SUBSTR(m.this_string, m.knt, 1) != , you could store SUBSTR(m.this_string, m.knt, 1) in a variable outside the loop, then use that in a INLIST() as well.

As I say, this probably won't solve the problem, but it might be interesting to see if it has any effect.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Mike--

Thanks for your suggestion about INLIST(). If definitely helped clean up my nasty scrawl. (Eventually, I'll put that list of words to skip out into a text file to make it easier to maintain.)

The problem was in the inner DO WHILE loop, where I kept advancing the counter even after I'd hit the end of the string being evaluated. Once you go past the end, the value of SUBSTR(mystring, 1, way-out-counter) becomes CHR(0) (=.NULL.), and the execution goes wandering off into Neverland.

I had thought that the condition in the outer DO WHILE loop would take care of that for me. Evidently it does take care of it when running in the development mode, but not in the compiled form.

Here's a working version:

Code:
FUNCTION find_acro_work2
CREATE CURSOR acrolist (acronym C(9))
CREATE CURSOR holder_lb (thistext C(254))
SELECT holder_lb
m.target_file = GETFILE("Text:TXT")
m.target_path = LEFT(m.target_file, RAT("\", m.target_file))
IF NOT(EMPTY(m.target_file))
	m.dostring = "SET ALTERNATE TO '" + m.target_path + "acro_log.txt'"
	&dostring
	m.dostring = "APPEND FROM '" + m.target_file + "' TYPE SDF"
	&dostring
ELSE
	MESSAGEBOX("Can't find the file you want to work on.", 0, "No File!")
	RETURN
ENDIF
m.knt = 1
m.new_one = "x"		&& Working string, might turn out to be an acronym
m.maybe = .F.		&& If .T., maybe m.new_one is a good acronym
m.start = .F.		&& If .T., m.new_one has only a single character
SCAN 
	m.this_string = RTRIM(holder_lb.thistext)
	DO WHILE ISNULL(RIGHT(m.this_string, 1))
		m.this_string = LEFT(m.this_string, LEN(m.this_string) - 1)
	ENDDO
*!*	Skip empty strings
	IF EMPTY(m.this_string)
		LOOP
	ENDIF
*!*	Iterate through each string
	DO WHILE m.knt <= LEN(m.this_string)
*!*	Save acronyms between 2 and 9 characters long, if they're not already recorded.
*!*	Ignore known troublemakers that end in apostrophe or slash. Ignore two-character 
*!*	codes beginning with "V".  Ignore words that are capitalized in headings.
		IF BETWEEN(LEN(m.new_one), 2, 9) AND m.maybe = .T. AND !ISDIGIT(RIGHT(m.new_one, 1)) ;
				AND RIGHT(m.new_one, 1) != "'" AND RIGHT(m.new_one, 1) != "/" AND ;
				!(LEN(m.new_one) = 2 AND LEFT(m.new_one, 1) == "V") AND ;
				!INLIST(m.new_one, "ALL", "AND", "APPENDIX", "AUGUST", "CATALOG", ;
					"CLEAN", "COMMENT", "CROSS", "DOCUMENT", "DOCUMENTS", "DRAFT", ;
					"FORMS", "FUNCTION", "GENERAL", "IDEA", "IMMEDIATE", "INTERFACE", ;
					"LOGTEC", "NEAR", "NO", "NOT", "NOTE", "OBJECTIVE", "OF") AND ;
				!INLIST(m.new_one, "OR", "ORDERS", "PLANNING", "PRINCIPAL", "PROVIDED", ;
					"REFERENCE", "ROLE", "SNAPSHOT", "SOURCE", "SUMMARY", "SYSTEMS", ;
					"TABLE", "TERM", "TOS", "UP", "WITH", "WORKFLOW")
			SELECT acrolist
			LOCATE FOR RTRIM(acrolist.acronym) == m.new_one
			IF !FOUND()
				INSERT INTO acrolist (acronym) VALUES (m.new_one)
			ENDIF
			m.new_one = "x"
		ENDIF
		IF ISUPPER(SUBSTR(m.this_string, m.knt, 1)) AND ISALPHA(SUBSTR(m.this_string, m.knt, 1))
*!*	Mark as a candidate acronym and start watching to see if it really is an acronym
			m.new_one = SUBSTR(m.this_string, m.knt, 1)	
			m.start = .T.
*!*	Loop until you reach something that wouldn't be in an acronym
			DO WHILE m.knt <= LEN(m.this_string) AND ;
				(ISUPPER(SUBSTR(m.this_string, m.knt, 1)) OR ;
					(!ISALPHA(SUBSTR(m.this_string, m.knt, 1)) AND ;
					!INLIST(SUBSTR(m.this_string, m.knt, 1), " ", ;
						".", "!", ",", "[", "]", "(", ")", ":", '"', ;
						"*", "-", ";", CHR(9), CHR(10), CHR(13), CHR(0), "_")))
				IF m.start = .T.
					m.start = .F.
				ELSE
					m.new_one = m.new_one + SUBSTR(m.this_string, m.knt, 1)
				ENDIF
				m.knt = m.knt + 1
			ENDDO
*!*	If the next character is a word terminator, maybe m.new_one is an acronym.
			IF !INLIST(SUBSTR(m.this_string, m.knt, 1), " ", ;
					".", ";", CHR(10), CHR(13), CHR(0), ",")
				m.maybe = .T.
			ELSE
				m.maybe = .F.
			ENDIF
		ELSE
			m.knt = m.knt + 1
		ENDIF
	ENDDO
	m.knt = 1
	SELECT holder_lb
ENDSCAN
SELECT * FROM acrolist ORDER BY acronym INTO CURSOR acrolist1
SELECT acrolist1
SET SAFETY OFF
m.dostring = "COPY TO '" + m.target_path + "acrolist.xls' TYPE XL5"
&dostring
SET SAFETY ON
ENDFUNC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top