?
Solved

VB.Net string parse

Posted on 2004-11-02
3
Medium Priority
?
292 Views
Last Modified: 2012-05-05

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
Comment
Question by:lindapat
3 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 12475947
Are you thinking about strtok?  If so, then you are a little off there:

tmp = Split(isaLine, "*") will return the ISA, 00, <blank>, 00, <blank>, 27, 00523...  

You only need to do this one, and then reference the element that you need.

Bob
0
 
LVL 27

Expert Comment

by:Dabas
ID: 12478208
Hi lindapat,
You say you want to show each element in the label you have created on a form.
Sounds like a contradiction to me.
How can you show multiple elements in one label?

Otherwise I agree with Bob:
Take split out of the loop.
Maybe display the label with the loop.
Something like:

tmp = Splig(isaLine,"*")

For x = 0 to UBound(tmp)
    MessageBox.Show(tmp(x))
Next

Dabas
0
 
LVL 7

Expert Comment

by:J_Mak
ID: 12478527
One of you problems is that you are attempting to show all items in just the one label. THis will have the effect of placing each string into the label in a very quick manner, in which case you will probably not even notice any of them, except the last one which will remain as the label's text. You could iterate through each element of your resultant array and put them in a list box or something, so that it is clear which elements have been split. Otherwise, just use a messagebox. Cheers.
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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

621 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