Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Parse text file

Posted on 1998-09-08
4
Medium Priority
?
131 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 200 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

916 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