<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Life...as it relates to Technology. &#187; text files</title>
	<atom:link href="http://www.hobbub.com/tag/text-files/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hobbub.com</link>
	<description>Technology, Internet and Real World Product Reviews.</description>
	<lastBuildDate>Wed, 14 Jul 2010 04:45:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Text File to String VB Function</title>
		<link>http://www.hobbub.com/vba-vb-vsto/text-file-to-string-vb-function/</link>
		<comments>http://www.hobbub.com/vba-vb-vsto/text-file-to-string-vb-function/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 22:35:51 +0000</pubDate>
		<dc:creator>scott</dc:creator>
				<category><![CDATA[VBA/VSTO]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[text files]]></category>

		<guid isPermaLink="false">http://www.hobbub.com/vba-vb-vsto/text-file-to-string-vb-function/</guid>
		<description><![CDATA[Here is a quick little VB/VBA function to turn text files (or html files or xml files) into string variables.
Text File to String Variable Function (xml file to string variable, html file to string variable)
There are numerous Internet Programming situations where large pieces of text need to be populated with variable values. On other occasions [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a quick little VB/VBA function to turn text files (or html files or xml files) into string variables.<br />
<h4>Text File to String Variable Function (xml file to string variable, html file to string variable)</h4>
<p>There are numerous Internet Programming situations where large pieces of text need to be populated with variable values. On other occasions the task could be parsing html files to retrieve SEO information. Yet another common situation is working with XML as a string inside VB. The Microsoft XML objects consume a lot of memory. Sometimes it is more efficient to work with XML as a string instead of consuming the overhead necessary to create XMLHTTP or MSXML objects.</p>
<p>You can also use a xml file as a template for SOAP calls. Simply retrieve the xml as a string, populate some predefined placeholder text and you are ready to call inline webservices. As you&#8217;ll see, turning text into a string is easy &#8211; it doesn&#8217;t matter whether it is <b>xml to string</b> or <b>html to string</b> either.<br />
<h4>The TextToString Function</h4>
<p>The function below is short and relatively straightforward &#8211; feel free to customize it to suit your individual needs. It contains some rudimentary error trapping, but it should be enough to catch common errors and display enough information for easy troubleshooting.</p>
<p>The function contains two variables: the <i>strPath </i>variable is the argument parameter that will contain the absolute path to the file. You may want to implement file extension validation if your project requires a little more &#8216;tightness&#8217; in the code. <i>strBuff </i>acts as a temporary buffer to hold the results until they can be assigned back to the function&#8217;s result.</p>
<p>also called:<br /><font face="monospace">Public Function XMLToString(strPath As String) As String<br /></font><font face="monospace">Public Function HTMLToString(strPath As String) As String<br /></font><br /><font face="monospace">Public Function TextToString(strPath As String) As String<br />&nbsp;&nbsp;&nbsp; Dim strBuff As String<br />&nbsp;&nbsp;&nbsp; On Error GoTo ErrTrap<br />&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; Open strPath For Binary As #1<br />&nbsp;&nbsp;&nbsp; strBuff = Space(LOF(1))<br />&nbsp;&nbsp;&nbsp; Get #1, , strBuff<br />&nbsp;&nbsp;&nbsp; </font><font face="monospace">TextToString </font><font face="monospace">= strBuff<br />&nbsp;&nbsp;&nbsp; Close #1<br />ErrTrap:<br />&nbsp;&nbsp; If Err Then Err.Raise Err.Number, , &#8220;Error from Functions.TextToString &#8221; &amp; Err.Description<br />End Function</font></p>
<p>In a later project, we&#8217;ll be combining this <b>Text to String Function</b> with the <a href="http://www.hobbub.com/vba-vb-vsto/iterating-over-a-directory-with-a-dir-loop-loop-through-directory-vb/" title="Loop Through Directory With Dir">Loop Through Director</a>y routine in order to build content for a Wordpress blog. We&#8217;ll examine how to create upload files by manipulating data in Excel.</p>
<p>Wise Man Say, <a href="http://www.hobbub.com/aphorisms/dont-run-your-head-against-a-stone-wall/" title="Dont Run Head Against Wall">Don&#8217;t Run Your Head Against a Stone Wall</a></p>
<img src="http://www.hobbub.com/?ak_action=api_record_view&id=1056&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.hobbub.com/vba-vb-vsto/text-file-to-string-vb-function/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
