home *** CD-ROM | disk | FTP | other *** search
/ ftp.tcs3.com / ftp.tcs3.com.tar / ftp.tcs3.com / DRIVERS / Audio / Office2010 / InfoPath.en-us / InfLR.cab / FL_ReadaDelimitedTextfile_snippet_142684_ENU____.3643236F_FC70_11D3_A536_0090278A1BB8 < prev    next >
Extensible Markup Language  |  2008-09-17  |  2KB  |  45 lines

  1. <?xml version="1.0"?>
  2. <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  3.   <CodeSnippet Format="1.0.0">
  4.     <Header>
  5.       <Title>Read a Delimited Text File</Title>
  6.       <Author>Microsoft Corporation</Author>
  7.       <Description>Returns the values in each column and row from a text file with comma-delimited data. Other delimiters may be used.</Description>
  8.       <Shortcut>filParseText</Shortcut>
  9.     </Header>
  10.     <Snippet>
  11.     <Imports>
  12.           <Import>
  13.             <Namespace>Microsoft.VisualBasic.FileIO</Namespace>
  14.           </Import>
  15.   </Imports>
  16.       <Declarations>
  17.         <Literal>
  18.           <ID>Filename</ID>
  19.           <Type>String</Type>
  20.           <ToolTip>Replace with the file name of the text file.</ToolTip>
  21.           <Default>"C:\Test.txt"</Default>
  22.         </Literal>
  23.         <Literal>
  24.           <ID>Delimiter</ID>
  25.           <Type>String</Type>
  26.           <ToolTip>Replace with the delimiter strings.</ToolTip>
  27.           <Default>","</Default>
  28.         </Literal>
  29.       </Declarations>
  30.       <Code Language="VB" Kind="method body"><![CDATA[Dim filename As String = $Filename$
  31.         Dim fields As String()
  32.         Dim delimiter As String = $Delimiter$
  33.         Using parser As New TextFieldParser(filename)
  34.             parser.SetDelimiters(delimiter)
  35.             While Not parser.EndOfData
  36.                 ' Read in the fields for the current line
  37.                 fields = parser.ReadFields()
  38.                 ' Add code here to use data in fields variable.
  39.  
  40.             End While
  41.         End Using]]></Code>
  42.     </Snippet>
  43.   </CodeSnippet>
  44. </CodeSnippets>
  45.