Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to store numbers in a prg file?
Message
From
10/09/2002 20:12:20
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
10/09/2002 18:27:55
Henry Ravichander
RC Management Systems Inc.
Saskatchewan, Canada
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00699107
Message ID:
00699143
Views:
15
>Hi All:
>
>I have a table from which I would like to traverse down thru the table and store the number from field1 in that table to a prg file. e.g
>. the prg file after numbers are stored would look like:
>
>111
>112
>113
>114 etc
>
>I would also like to programatically insert each of the numbers form a prg file which will be stored as shown above, into a table that will be programatically created.

This piece of code I wrote long ago (look at the dates in the comments, no matter that you don't understand the text)... save it as a .prg and call it while having a table (cursor, view) open. It will generate a .prg with the insert statements for all non-empty fields in all the records.

Optional parameters: prg file name (defaults to the current alias + ".prg"), table name (defaults to current alias).
*+ sadr¾aj baze u .PRG
* Generi¹e program koji puni bazu sadr¾ajem zateèenim u;
	bazi u trenutku generisanja, preskaèuæi prazna polja. ;
	Generisani program mo¾e da ispadne dugaèak, ali æe da radi.
* Parametri:
*	_txt	-	ime fajla u koji se pi¹e, difolt ekstenzija .prg
*	dbf	-	ime baze iz koje se èita i za koju se kreira program za;
	punjenje
*
* Istorija: v1.0 24.09.94, bio potreban da bi se napravili;
	 gen_scx i gen_repo
* 6.3.95 doteran da prihvata cr u memo poljetu
* 2002.01.20 added some defaults.
*
* klasa: generator
*
*-
para _txt,dbf, fldno
IF !EMPTY(dbf)
	use (dbf)
ELSE
	IF EMPTY(ALIAS())
		=alert("no table open")
	ENDIF
ENDIF
IF !EMPTY(_txt)
	_txt=defaultext(_txt,'prg')
ELSE
	_txt=FORCEEXT(DBF(),"prg")
ENDIF

if type('fldno')#"N"
	fldno=1
endif
set text to (_txt)
set text on
\ #define cr chr(13)
\ #define nul chr(0)
n=afiel(_st)
scan
	sp=''
	sv=''
	zz=''
	for i=fldno to n
		if !empty(eval(_st(i,1)))
			_add=all2str(i)
			if !empt(_add)
				sp=sp+zz+_st(i,1)
				sv=sv+zz+_add
				zz=', '
			endif
		endif
	endf
	if !empt(sp)
		\Insert into <<alias()>> (<<sp>>);
		\	Value (<<sv>>)
	endif
ends
set text off
set text to

func all2str
para _i
do case
	case inlist(_st(_i,2),'N','F')
		retu allt(str(eval(_st(_i,1))))
	case inlist(_st(_i,2),'C','M')
		_txt=eval(_st(_i,1))
		do case
			case '"'$_txt
				_txt= "'"+_txt+"'"
			case "'" $ _txt
				_txt= '"'+_txt+'"'
			case _txt=chr(0)
				_txt= 'Nul'
		endc
		_txt=strt(_txt,chr(13),'"+cr+"')
		retu '"'+_txt+'"'
	case _st(_i,2)='L'
		retu '.T.'
	case _st(_i,2)='D'
		retu '{'+dtoc(eval(_st(_i,1)))+'}'
	other
		retu ''
endc

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform