Results 1 to 20 of 20

Thread: Basic help

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    7

    Basic help

    Hello all,

    I'm new to programing and I need a little jump start.
    I have a flat text file delimited by "|". I want to count a certin number of "|" and print to the next "|". then go to the next line.

    I can read the file without a problem, I just need some basic help on how to work with it. If I can get an idea, I can figure it out from there.

    Here is an example of data:

    COL_OMC | DAP_ACG_LINK | NOH3384R_IESOSU |

    print to the first "|"
    skip to the third "|" then print to the next "|"

    read the next line

    any ideas?

    Thanks

  2. #2
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    If you read the whole line into a string, there is a Split Command that let's you determine the "split" character, that outputs into a string array. Just do that an step through the array by 2.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Is this too simple?

    Enter the string you want to add into a textbox.
    Loop through the string until the "|" is found.
    Note the location of the "|"

    If you want to overwrite the contents up to that point, make the string = to textbox.text & the right remaining contents of the string.

    If you want to add characters make the string = it's left X characters + textbox.text + the right characters.

    To go to the third "|" (if it is the last just concant the string with the textbox.text + "|") just use an integer to record the number of "|" found and do something similar to the above.

    There is also the Regex class which will work quickly, but is quite involved to learn - see MSDN Help.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    7

    More detail?

    Thanks for your help on this hwoever, could I get a little more detail? An example perhaps? Like I said, I'm a beginner....


    Thanks

  5. #5
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Please don't think me rude when I say: go read a book.

    Seriously (this is rapidly becoming my catchphrase around here) go to a library and take out a book about VB.net. "Tips and Tricks in VB.net" is a good one to look at and easily covers this kind of question in full detail.

    Having a book to learn from is better (and faster) than asking on a forum.
    I don't live here any more.

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    7
    I don't think your rude. However I did specify that I was a beginner. I have VB.net 2003 AND VB.net step by step. Neither of which teach much about dealing with text files. I do try to figure this out on my own, sometimes you just need a starting point. I thank you for your help.

    In fact I have made some progress with the SPLIT function. I would like some help with REading the next line.

    I am using ReadLine in about a tousand line file. Once I am done with the first line, how do I proceed to the next?

    Thanks

  7. #7
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: More detail?

    Originally posted by flhartley
    Thanks for your help on this hwoever, could I get a little more detail? An example perhaps? Like I said, I'm a beginner....


    Thanks
    I agree with Wossname as several people are using this forum to crib their complete assignments fro educational establishments (a polite word for cheating!!). What you should do is to make a coding attempt and then come to the forum with a specific coding problem.

    However, just this once, the following is a beginner's way to find out where the "|"'s are. Now see if you can work out how to add, or replace if that is the case, other strings.

    VB Code:
    1. Dim strTarget As String = "This is a | test of this | problem to see what happens|"
    2.         Dim strFind As String = "|"
    3.         Dim strArray(Len(strTarget)) As Integer  'to hold string position of "|"
    4.         Dim iCount As Integer   'To control loop
    5.         Dim iCount1 As Integer  'To control number of  "|",s
    6.         For iCount = 1 To Len(strTarget)
    7.             If Mid(strTarget, iCount, 1) = strFind Then
    8.                 iCount1 = iCount1 + 1
    9.                 strArray(iCount1) = iCount ' Record string position of "|"
    10.             End If
    11.         Next
    12.         For iCount = 1 To iCount1
    13.             MessageBox.Show("The number " & iCount & "  |  is at stringTarget position  " & strArray(iCount))
    14.  
    15.         Next
    16.         MessageBox.Show("There are no more |,s")

    I emphasise that the above is a beginner's approach. There are specific string manipulation functions which can make the code shorter.

    Best of luck.
    Last edited by taxes; Jul 15th, 2004 at 10:30 AM.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    7
    Thanks a lot! Below is how I did it if you want an example. A assure you, I have been messing with this and reading books for quite a while getting nowhere.

    I am doing this project for my job and to learn. I'm NOT try to get someone to do my work for me.

    I know how much it's a pain for someone who had done this for a long time to answer simple questions. Believe me, I appreciate your time, I know it's valuable.

    I hope to be on here answering someone elses questions someday.

    Thanks

    If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
    strFileName = OpenFileDialog1.FileName

    Dim objReader As StreamReader = New StreamReader(strFileName)

    dataBin = objReader.ReadToEnd()

    arrayTest = Split(dataBin, "|")
    If arrayTest(12) > 4000 Then
    Else : MessageBox.Show("No Record", "TEST")

    OMC.Text = arrayTest(0)
    evType.Text = arrayTest(1)
    sName.Text = arrayTest(2)
    Nelement.Text = arrayTest(3)
    eVents.Text = arrayTest(8)
    sImpacted.Text = arrayTest(9)
    pDuration.Text = arrayTest(12)

    objReader.Close()
    objReader = Nothing
    End If
    End If

  9. #9
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hmmm..

    I am now not clear on what you want to do. You have put each one of the string segments into an element of the array so if you want to alter or append you can replace that element easily.

    What is your precise problem?
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  10. #10

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    7
    OK,

    Please note the following 2 lines of raw data in a text file.

    COL_OMC | RslSap | NOH5638R_IFLiberty | CIBSC34 (RSLSAP 14 0) | Wed Jun 09 00:00:00 2004 | 20124.67 | Uncla:: | Up | 1 | IC;VMS;SMS | | 18463 | 463 | 18000 | 504.67 | 19620.00 | 18463 | FromJun 9, 2004 00:00:00) ToJun 9, 2004 05:07:43) |

    COL_OMC | RslSap | NOH3384R_IESOSU | COBSC91 (RSLSAP 23 0) | Wed Jun 09 00:00:00 2004 | 1363.20 | Uncla:: | Up | 1 | IC;VMS;SMS | | 1043 | 0 | 1043 | 0.00 | 1363.20 | 1043 | FromJun 9, 2004 00:00:00) ToJun 9, 2004 00:17:23) |

    What I am trying to do is enter a line into a variable, anaylize the 13th (logical 12) field and IF it is greater than a given number, displany fields 0, 1, 2, 3, 8, 9, and 12 into text boxs.

    Eventually I will have a button the will say "Write Data?" that if clicked the entire line will right to a file. (I have not started on this part yet)

    Then evaluate the next line and the process starts again.

    Basically I want to filter this text file based on the number in the 13th field but a human has to decide if the want to keep it. Currently we have to "eyeball" the entire file to find these numbers and there are hundreds of lines.

    I know this is simple, I am making progress. Thanks for any help you can provide!

  11. #11
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    OK. I'm still not entirely sure of what you want as your reference to a number in the 12th logical field (by which I take you to be starting at a Zero logical field), does not tie up with the strings you posted. So adjust the following accordingly if necessary.
    Put the textboxes used to display the text, into a panel and make sure they are ordered sequentially.
    VB Code:
    1. Dim strTarget As String   'Here fill with your string
    2.         Dim strFind As String = "|"
    3.         Dim strArray(Len(strTarget)) As Double  'to hold string position of "|"
    4.         Dim iCount As Integer   'To control loop
    5.         Dim iCount1 As Integer  'To control number of  "|",s
    6.         For iCount = 1 To Len(strTarget)
    7.             If Mid(strTarget, iCount, 1) = strFind Then
    8.                 iCount1 = iCount1 + 1
    9.                 strArray(iCount1) = iCount ' Record string position of "|"
    10.             End If
    11.         Next
    12.  
    13.         Dim ctl As Control
    14.         Dim iCount As Integer = 0
    15.         Dim iNum As Double    '  to hold value you require to be
    16.                                               exceeded
    17.         If Val(Trim(Mid(strTarget, CInt(strArray(11)), CInt(strArray(12) - strArray(11))))) > iNum Then
    18.             For Each ctl In Me.Panel1.Controls
    19.                 If TypeOf ctl Is TextBox Then
    20.                     ctl.Text = Trim(Mid(strTarget, CInt(strArray(iCount)), CInt(strArray(iCount + 1) - strArray(iCount))))
    21.                     iCount = iCount + 1
    22.                     If iCount>12 then Exit For
    23.                     If iCount = 4 Then iCount = 8
    24.                     If iCount = 10 Then iCount = 12
    25.          
    26.  
    27.                 End If
    28.             Next
    29.         End If

    I have not checked for bugs but it compiles OK.

    See if that does what you want so far and the we will proceed from there. But I'm going to bed shortly.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  12. #12
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    I'm getting nervous. There are too many people looking at this thread
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  13. #13
    Lively Member
    Join Date
    Nov 2003
    Location
    Iowa
    Posts
    96
    I'm not thinking your getting the answer what you want, and I think that this is what you are looking for I hope this helps

    Code:
    'This makes it so you don't have to drop the OpenFileDialog to your form...(if program doesnt work...then drop the OpenFileDialog to your form ;-))
    Dim OpenFileDialog1 As New OpenFileDialog
    'Delegate which types of files will be opened !!!Change this!!!
            OpenFileDialog1.Filter = "txt files (*.txt)|*.txt"
        'Show the OpenFileDialog, and make sure the user clicked OK
            If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
    'Dim some stuff, and open the file selected
                Dim sr As New System.IO.StreamReader(OpenFileDialog1.FileName)
    'Allocate a variable that will become the text of the file
                Dim line As String
    'The LOOP (dun dun dun...)
                Do
    'Start writing the lines of the file to the String Variable
                    line = sr.ReadLine()
            'Keep going until there are no lines left
                Loop Until line = Nothing
            End If
    'NOW DO THE PARSING !!! This is the code that the other people gave you about how to split the stuff!!!

    I hope this helps...this is probably the first time i've answered a question instead of asked! Good luck to you!
    It is like wiping your ass with silk, I love it!

  14. #14
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi thurston,

    Looks Good

    The reason why I thought he was OK on that was in his first post was

    "I can read the file without a problem, I just need some basic help on how to work with it. If I can get an idea, I can figure it out from there."

    I assumed he could get the string into a variable OK. But then, I also assumed that he was a complete beginner doing an early homework assignment
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  15. #15

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    7
    Folks,

    Thanks so much for all of your help so far. You guys are GREAT! I have really learned a lot. As far as being a beginner, I have had some practice modifying PERL scripts. I'm still playing with this thing and I've made some good progress. Here is what I have done so far:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Public Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
    'Set the Open Dialog Properties...
    With OpenFileDialog1
    .Filter = "Text files (*.txt) |*.txt|All files (*.*) |*.*"
    .FilterIndex = 1
    .InitialDirectory = "c:\"
    .Title = "Demo Open File Dialog"
    End With
    ' Show the open file dialog and if the user clicks the OK button,
    ' load the file....
    If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
    strFileName = OpenFileDialog1.FileName
    fileName.Text = strFileName


    End If
    End Sub


    Public Sub Run_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Run.Click

    Try

    Dim objReader As StreamReader = New StreamReader(strFileName)

    Dim thresVal As Int32
    Dim prompt As String


    thresVal = InputBox("Input Threshold", "Test")


    Do
    dataBin = objReader.ReadLine()

    arrayTest = Split(dataBin, "|")

    If arrayTest(12) > (thresVal) Then

    OMC.Text = arrayTest(0)
    evType.Text = arrayTest(1)
    sName.Text = arrayTest(2)
    Nelement.Text = arrayTest(3)
    NeVents.Text = arrayTest(8)
    sImpacted.Text = arrayTest(9)
    pDuration.Text = arrayTest(12)
    End If

    Loop Until arrayTest(12) > (thresVal)


    objReader.Close()
    objReader = Nothing

    Catch Z As Exception
    MessageBox.Show(Z.Message)

    End Try



    End Sub

  16. #16
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    OK. Your main problem here is that you are using VB6 thinking.

    In VB.NET, the TextBox.Text property is solely a string, so when you check for arithmetic values you must cast correctly.

    Also, to check the string for arithmetic values, you have to devise code to ignore the "|" and the spaces.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  17. #17
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi my previous post needs a correction. It appears that arrayTest(?) although declared as a string will allow arithmetic operations and, in fact, concanting results in an arithmetic result, i.e. if the contents of arrayTest(4) is "30000" you can perform

    arrayTest(4) + 999 and you get the result 30999 without any casting errors.

    Can anyone comment on this please?
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  18. #18

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    7
    Hi,

    I actually declared arrayTest as an "object", my understanding is that can be anything.

    Thanks

  19. #19
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by flhartley
    Hi,

    I actually declared arrayTest as an "object", my understanding is that can be anything.

    Thanks
    Ah! I'm puzzled. I thought declaring a variable as an Object simply prepared it for being a reference to an object. In this case you have referenced it to a string variable and I would have assumed it took on all the properties of a string.

    You are trying to compare values on a string to string basis which will produce peculiar results with the >.

    We will have to see what some experts say.
    Last edited by taxes; Jul 17th, 2004 at 06:03 AM.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  20. #20
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Re: More detail?

    Originally posted by taxes
    I agree with Wossname as several people are using this forum to crib their complete assignments fro educational establishments (a polite word for cheating!!).
    Just to clear things up a bit. I wasn't accusing flhartley of cheating . Everyone has to start somewhere Books do vary in quality and I was referring flhartley to a book that I know to be great for beginners. It helped me a great deal in my transition to .net from vb6.

    Good luck anyway.
    I don't live here any more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width