Changing data in text file using VB 6.0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • varsha desai
    New Member
    • Mar 2007
    • 7

    Changing data in text file using VB 6.0

    Hello there,

    I want to change some data(which is in one line only) of text file using VB 6.0. Which is the best method for it? Another question is I want to delete last two, three lines of text file using VB 6.0. Which method can be best method for it?
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by varsha desai
    Hello there,

    I want to change some data(which is in one line only) of text file using VB 6.0. Which is the best method for it? Another question is I want to delete last two, three lines of text file using VB 6.0. Which method can be best method for it?
    Hello there, varsha desai!

    Use the replace command to changes things 'round:

    Comment

    • mailderemi
      New Member
      • Jun 2007
      • 14

      #3
      VB6: Open Command

      Originally posted by varsha desai
      Hello there,

      I want to change some data(which is in one line only) of text file using VB 6.0. Which is the best method for it? Another question is I want to delete last two, three lines of text file using VB 6.0. Which method can be best method for it?
      Hi
      This is my first reply
      This way is one of old ways that VB6.0 got it from QBasic
      I think the easy way is:
      Open:
      [CODE=vb] Dim s as String
      Open "C:\test.tx t" For input As #1
      Input #1, s
      Close #1[/CODE]

      Save:
      [CODE=vb] Open "C:\test.tx t" For output As #1
      Print #1, "Test"
      Write #1, "Test"
      Close #1[/CODE]

      Append:
      [CODE=vb] Open "C:\test.tx t" For Append As #1
      Print #1, "Test"
      Write #1, "Test"
      Close #1[/CODE]

      these are for Text file but if you wanna use it for a binary file:
      1. use "Binary" instead of "Output" or "Input" or "Append"
      2. use "Get" and "Put" instead of "Input" and "Print" or "Write"

      .:!M!LDEREMi:.

      Comment

      • mailderemi
        New Member
        • Jun 2007
        • 14

        #4
        Originally posted by Dököll
        Hello there, varsha desai!

        Use the replace command to changes things 'round:
        Hi
        If you use RichTextBox there is a command that load the file in the easiest way and also a command for Replacement but if you wanna do it in the best way don't use it. The best way is opening file in Binary mode and get the data from file directly... in this way you won't need ActiveX of rich text box.

        Also this way is the best way in VB.NET faster and easier than VB6.

        Comment

        • danp129
          Recognized Expert Contributor
          • Jul 2006
          • 323

          #5
          If opening more than one file at a time you need to find a free file handle to use

          [CODE=vb]Dim s as String, lngFile as long
          lngFile=FreeFil e
          Open "C:\test.tx t" For input As #lngFile
          Input #lngFile, s
          Close #lngFile[/CODE]

          Comment

          Working...