Results 1 to 4 of 4

Thread: I need help with VB (visual basic)

  1. #1
    Member Member Kaatar's Avatar
    Join Date
    Jan 2004
    Location
    Dublin, Ireland
    Posts
    251

    Question

    I'm making a tool but I need to a few things in VB before I can do it. I know a little bit in VB but I can't figure out how to do this:

    1. Open a text file and scan it for one line of code. When this code is found I want to put two lines of information into the next available blank line.

    2. Open a text file and scan it for one line of code. When this code is found I want to go up one line and put in two lines of information.

    Anyone know how to do this? I would REALLY appreciate any help. Thank you
    May your first child be a masculine child.

  2. #2
    Member Member Lord Xelous's Avatar
    Join Date
    Jan 2004
    Location
    Nottingham, England
    Posts
    85

    Default

    I've got to go out in a a moment, but when I come back I'll write you this code.

    Lord "Programmer" Xelous.



    If Mountains and Oceans can be overcome, anything built by man can be overcome - General George S Patton.

  3. #3
    Member Member Lord Xelous's Avatar
    Join Date
    Jan 2004
    Location
    Nottingham, England
    Posts
    85

    Default

    *This code is MS-Visual Basic 6 compliant* (I hope)

    Function FindLineAndAddTwoAfter (FileName As String, NewFilename As String, FindMe As String, AddLine1 As String, AddLine2 As String)
    Open Filename For Input As #1
    Open NewFilename For Output As #2

    Do Until EOF (#1)
    Line Input #1, A$
    Print #2, A$
    If A$ = FindMe Then
    Print #2, AddLine1
    Print #2, AddLine2
    EndIf
    Loop

    Close #1
    Close #2
    End Function

    After this you will have 2 files.. the original and a new one with your 2 add lines added in after the fineme string.

    You can use the Change function to change the names of the orignal file to somethign else then rename your new one for
    use to replace into the MTW engine.

    The second function you want is similar we just defer the Print #2, A$ until after we've compared the current read line

    Function FindLineAndAddTwoBefore (FileName As String, NewFilename As String, FindMe As String, AddLine1 As String, AddLine2 As String)
    Open Filename For Input As #1
    Open NewFilename For Output As #2

    Do Until EOF (#1)
    Line Input #1, A$
    If A$ = FindMe Then
    Print #2, AddLine1
    Print #2, AddLine2
    EndIf
    Print #2, A$
    Loop

    Close #1
    Close #2
    End Function



    I think these should work for you, but I've not tried them.... any troubles give me a shout.

    Lord Xelous



    If Mountains and Oceans can be overcome, anything built by man can be overcome - General George S Patton.

  4. #4
    Member Member Kaatar's Avatar
    Join Date
    Jan 2004
    Location
    Dublin, Ireland
    Posts
    251

    Default

    Thanks I'll give that a go after dinner.
    May your first child be a masculine child.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Single Sign On provided by vBSSO