Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Building a string
Message
From
05/04/2010 14:24:57
 
 
To
05/04/2010 13:23:15
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01458765
Message ID:
01458785
Views:
49
>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform