Solved

Parse text file

Posted on 1998-09-08
4
125 Views
Last Modified: 2012-05-07
I have huge text file and I want to export it to database
I have text(row) delimiters ///
I probably want 3 fields  1.identity-number 2.name-first line of text following ///  3.actual data between ///...///
Suppose I open file and save it into variable(variant), it is huge
Can I parse variant
using InStr Left and right functions
What is your best solution to this
Access and MSSQL data transformation services cannot understand
/// delimiters.
0
Comment
Question by:mativare
  • 2
4 Comments
 
LVL 1

Author Comment

by:mativare
ID: 1433764
Edited text of question
0
 
LVL 14

Accepted Solution

by:
waty earned 50 total points
ID: 1433765
You can use the following function :

Public Function GetTokens(sTxt As String, sToken As String) As Variant
   ' *** Returns an array to tokenized values
   ' ***  Ex:  GetTokens("Field1///Field2///Field3///", "///") = ({ "Field1", "Field2", "Field3" })

    Dim iTokenLen As Integer
    Dim iTokenCnt As Integer
    Dim lOffset As Long
    Dim lPrevOffset As Long
    Dim aTokens() As String

    iTokenLen = Len(sToken)
    lOffset = InStr(sTxt, sToken)
   
    Do While lOffset > 0
        ReDim Preserve aTokens(iTokenCnt)
        If lOffset - lPrevOffset > 1 Then
            aTokens(iTokenCnt) = Mid$(sTxt, lPrevOffset + 1, lOffset - 1 - lPrevOffset)
        Else
            aTokens(iTokenCnt) = ""
        End If
       
        lPrevOffset = lOffset
        lOffset = InStr(lOffset + iTokenLen, sTxt, sToken)
        iTokenCnt = iTokenCnt + 1
    Loop
   
    ReDim Preserve aTokens(iTokenCnt)
    aTokens(iTokenCnt) = Mid$(sTxt, lPrevOffset + 1)
    GetTokens = CVar(aTokens)

End Function

0
 
LVL 1

Author Comment

by:mativare
ID: 1433766
Thanks waty
This piece of code is platinum
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1433767
Bought This Question.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question