AllAPI Network - The KPD-Team

Allapi Network

 API List

API Resources
 Tips & Tricks
 VB Tutorials
 Error Lookup
Misc Stuff
 VB examples
 VB Tools
 VB Links
 Top Downloads
This Site
 Search Engine
 Contact Form

Donate to

Parsing delimited text files

When reading data from a text file, you may find that it is in a format that needs seperating which could be Comma Seperated file which could use ',' as it's delimiter. To be able to seperate the different records you can create a function to parse the files that you read into your program. I have released a OCX Control on my web site which does this for you without any code.   Here Goes   1. Start a new Standard-EXE project, form1 is created by default   2. Add a module to your project. Project, Add Module. The code window is displayed by default. Add the following code :

Public Function ParseString(ByVal vsString As _
String, ByVal vsDelimiter As String, ByVal _
viNumber As Integer)

'Author: Steve Anderson
'Created : 13/08/98
'Purpose : Parses out a section
'from a delimited string

Dim iFoundat As Integer
Dim iFoundatold As Integer
Dim iCurrentSection As Integer
Dim sText As String
If Len(vsString) > 0 And InStr(vsString, _
vsDelimiter) > 0 And viNumber > 0 Then
  iFoundat = 1
  iFoundatold = 1
  Do While InStr(iFoundatold + 1, vsString, _
  vsDelimiter) > 0
  iFoundatold = iFoundat
  iFoundat = InStr(iFoundat + 1, vsString, _
  iCurrentSection = iCurrentSection + 1
  If viNumber > iCurrentSection Then
    Exit Function
  End If
  iFoundat = 1
  iCurrentSection = 0
    iFoundatold = iFoundat
    iFoundat = InStr(iFoundat + 1, vsString, _
    If Trim(sText) = "" Then
      sText = Mid(vsString, 1, iFoundat - 1)
      iCurrentSection = iCurrentSection + 1
      If iFoundat > 0 Then
        sText = Mid(vsString, iFoundatold + 1, _
        (iFoundat - 1) - iFoundatold)
        sText = Mid(vsString, iFoundatold + 1)
      End If
      iCurrentSection = iCurrentSection + 1
    End If
    If iCurrentSection = viNumber Then
      ParseString = sText
      Exit Do
    End If
End If
ParseString = sText
End Function

3. Open up form1's and add a command button. Open up the click even for the command button and type the following:

Msgbox ParseString("Visit - - for everything on Visual Basic", "-", 2)

4. Run the project (F5) and click on the command button and '' will be displayed in a message box.



Copyright © 1998-2007, The Team - Privacy statement
Did you find a bug on this page? Tell us!
This site is located at