[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

parse file

Posted on 2004-11-02
5
Medium Priority
?
314 Views
Last Modified: 2010-05-02
I have a file that looks like ISA*00**00*27*00523*ZZ*M4788
Could you give me example code on how to parse this file that has * seperating elements?





0
Comment
Question by:lindapat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 12475351
Private Sub Command1_Click()
Dim ff As Integer, Ln As String, arrLn() As String
ff = FreeFile
Open "C:\Myfile.txt" For Input As #ff
Do Until EOF(ff)
Line Input #ff, Ln
' split line into array by "*"
arrLn = Split(Ln, "*")

' loop through array
Dim i As Integer
For i = 0 To UBound(arrLn)
    If arrLn(i) <> "" Then MsgBox arrLn(i)
Next i

DoEvents
Loop
Close #ff

End Sub
0
 
LVL 4

Expert Comment

by:learning_t0_pr0gram
ID: 12475361
TheFile = your file

'==code==
Dim tmp() as string

tmp() = split(TheFile, "*")

For a = 0 to ubound(TheFile)
   Debug.Print tmp(a)
Next
0
 

Author Comment

by:lindapat
ID: 12475604
I am new at VB.net so please excuse me.  Will this code work? If not would you correct it for me? I want to show each element in label I have created on a form.
Private Sub read835()
        Dim isaLine As String
        Dim elementSep, compositeSep, segmentSep As String
        Dim x As Integer
        Dim tmp() As String
        isaLine = "ISA*00*          *00*          *27*00523          *ZZ*M4788          *040414*2351*U*00401*410500028*0*P*:~"
        elementSep = isaLine.Substring(103, 1)

        For x = 0 To isaLine.Length
            tmp = Split(isaLine, "*")

        Next
        lblMsg.Text = tmp(x)
0
 
LVL 1

Accepted Solution

by:
Allpax earned 2000 total points
ID: 12477547
For x = 0 To isaLine.Length
            tmp = Split(isaLine, "*")
Next
^
This is wrong because the split function acts like a loop itself and parses the string.  All you would need is

    tmp() = Split(isaLine, "*")
       
0
 
LVL 4

Expert Comment

by:learning_t0_pr0gram
ID: 12478529
yes but then there will be blank lines.. for instance..

if you split it by * it will look like this:

tmp(0) = "ISA"
tmp(1) = "00"
tmp(2) = "          "
tmp(3) = "00"
tmp(4) = "          "
tmp(5) = "27"
tmp(6) = "00523"
tmp(7) = "ZZ"

etc...

so which lines do you want to get out??  if you do it like i had it, u could get all the information out and check if it's all spaces, and if it is skip it.. such as:


Dim tmp() as string

tmp() = split(TheFile, "*")

For a = 0 to ubound(TheFile)
   if Trim(tmp(a)) <> "" Then MsgBox tmp(a)
Next

ubound fwould be the uppermost index in the array, and trim replaces spaces on the ends of the string, so trim("       ") would be the same as ""
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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

649 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