Solved

Parsing text in VB6

Posted on 2003-11-20
2
181 Views
Last Modified: 2010-05-01
I'm new to VB and need a suggestion about how to parse this text file.
I'm using VB6.

The text file has multiple records,
Each record begins with "GIGISA"

The record has many fields with different names and formats but
each field ends with a Tilde ~
each field element is seperated by astricks  "*"
The fields that show  city state and Zip looks like this:

N1*CompanyName~
N2*Business 2ndName~
N3*Main Street~
N4*Carthage*MO*64836~


The record is not carriage returned, it all runs together.
Someone mentioned to me I may want to use a Regular expression.  Is that a good idea in this situation?


0
Comment
Question by:vb_learner
2 Comments
 
LVL 15

Accepted Solution

by:
SRigney earned 80 total points
ID: 9790273
You could use a regular expression, but that would get very complicated,  you'll probably be better parsing it yourself if its as consistent as your example makes it sound.

Private Sub ParseData()
   Dim strRecords As String
   strRecords = "GIGISA~N1*CompanyName~N2*Business 2ndName~N3*Main Street~N4*Carthage*MO*64836~GIGISA~N1*AnotherCompanyName~N2*2nd Business 2ndName~N3*Center Street~N4*Carthage*MS*64831"
   
   Dim aRecords
   Dim aFields
   Dim aSubFields
   Dim intRecords As Integer
   Dim intFields As Integer
   Dim intSubFields As Integer
   
   aRecords = Split(strRecords, "GIGISA")
   ' I use 1 to skip the empty first item.
   ' If the first GIGISA isn't until after the first record then use a 0 here.
   For intRecords = 1 To UBound(aRecords)
      Debug.Print aRecords(intRecords)
      aFields = Split(aRecords(intRecords), "~")
      ' I use a 1 to skip the empty first item.
      ' if there is no ~ between GIGISA and the first field then use 0.
      For intFields = 1 To UBound(aFields)
         Debug.Print aFields(intFields)
         aSubFields = Split(aFields(intFields), "*")
         For intSubFields = 0 To UBound(aSubFields)
            Debug.Print aSubFields(intSubFields)
         Next intSubFields
      Next intFields
   Next intRecords
End Sub
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now