Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Building a string
Message
De
05/04/2010 14:24:57
 
 
À
05/04/2010 13:23:15
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Divers
Thread ID:
01458765
Message ID:
01458785
Vues:
50
>Hi All,
>
>I need to build a string of tab delimited fields from a table. I have been using something similar to:
>
>
>cMyString = ""
>
>SCAN 
>
>  cMyString = m.cMyString + myTable.Field1 + CHR(9) + myTable.Field2 + CHR(9) + CHR(13)
>
>ENDSCAN
>
>
>Is there a faster way such as, for example, using TEXTMERGE?
>
>TIA


If the output is large and you don't want to write to a file, you can use ado stream
function do_it()

	&&  http://msdn.microsoft.com/en-us/library/ms678086(VS.85).aspx
	
	

#ifndef adTypeBinary
	&& ADO
	&& StreamType
	#define adTypeBinary			(1)
	#define	adTypeText				(2)


	&& saveToFile
	#define	adSaveCreateNotExist	(1)
	#define	adSaveCreateOverWrite	(2)

	&& ReadText
	#define	adReadAll	(-1)
	#define adReadLine	(-2)
	
	&& StreamWriteEnum
	#define adWriteChar	(0)
	#define	adWriteLine	(1)	&& appends a CRLF
#endif
	local streamObj
	
	streamObj = createObject('ADODB.Stream')
	streamObj.Type = adTypeText
	=m.streamObj.Open()
	
	&& write without CRLF
	=m.streamObj.WriteText('Part of a line', adWriteChar)
	
	&& write with CTLF
	
	=m.streamObj.WriteText('Line 1', adWriteLine)
	
	=m.streamObj.WriteText('Line 2', adWriteLine)
	
	
	
	&& get the contents
	
	local s
	streamObj.Position = 0
	
	s = m.streamObj.ReadText(adReadAll)
	
	
	?s
	
	&& read line by line
	streamObj.Position = 0
	do while ( !m.streamObj.EOS )
		s = streamObj.ReadText(adReadLine)
		?s
	enddo
	
	=m.streamObj.Close()
	
	
endfunc
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform