How to read and write text files?

My question is how to read the content of a text file into my programme, and write it into another text file created by the programme. Could anybody tell me the most common method of doing that Thanks in advance!
By the way, where can I find a good online tutorial for VB6


Answer this question

How to read and write text files?

  • Ecrofirt

    I have downloaded VB.NET Express, but it runs extremely slow because of the lack of RAM on my laptop. But it is indeed much more powerful, thank you for your recommendation!

    I have some other questions:

    1. Is it possible to build hyperlinks in GUI using VB.

    2. How to highlight some words displayed in a label or textbox

    3. How to measure the time spent in executing the programme and display it in "hour:minute:second" format to the user.


  • JaysonM

    Is fora correct English I'm assuming that it is, but I'd never seen it before I saw you using it :-)

  • Vinzcenzo

    I'm wondering if there is much difference between VB6 and VB.NET. If yes, well, would you please let me know how to do the following tasks in VB.NET.

    1. Is it possible to build hyperlinks in GUI using VB.

    2. How to highlight some words displayed in a label or textbox

    3. How to measure the time spent in executing the programme and display it in "hour:minute:second" format to the user.

    Thanks very much.


  • ManuKarthink

    It's stated explicitly in the forum descriptions on the main page that these fora are not for VB6.



  • piotrfe

    Although VB6 is not supported:

    I hope I am not too late on answering this

    Private Sub TextFileHandling()
    'To write to file overwriting contents
    Open "c:\temp\test.txt" For Output As #1
    Print #1, "Some line of text"
    Close #1

    'To write to file appending contents
    Open "c:\temp\test.txt" For Append As #2
    Print #2, "Another line of text"
    Close #2

    'Reading a file is a little different
    '(At least how I do it)
    Dim handle As Integer

    ' ensure that the file exists
    If Len(Dir("c:\temp\test.txt")) = 0 Then
    Err.Raise 53 ' File not found
    End If

    'Note: Keep track of numbers. You can also make them variables
    'of type integer
    MsgBox FileText("c:\temp\test.txt")

    End Sub
    Function FileText(ByVal filename As String) As String
    Dim handle As Integer

    ' ensure that the file exists
    If Len(Dir$(filename)) = 0 Then
    Err.Raise 53 ' File not found
    End If

    ' open in binary mode
    handle = FreeFile
    Open filename$ For Binary As #handle
    ' read the string and close the file
    FileText = Space$(LOF(handle))
    Get #handle, , FileText
    Close #handle
    End Function

    From a VB.NET newbie, I have to tell you that whatever learning curve you experience going from VB6 to VB.NET is totally worth it. Having learned Java, C++ and C# but being more acustomed to VB, the upgrade to full OOP among other features is great.



  • pweyzen1

    I said the other day that I wasn't sure if it was OK to post VB6 messages here, but I've since noticed that other mods are locking them and suggesting people find other forums. I guess you need to do the same, find a forum that is for users of VB6.



  • iparkin

    The File System Object is still the way to do this

    Why have you decided to stick with VB6 instead of downloading VB.NET Express VB6 is unsupported, out of date, and IMO hideous...

    http://www.google.com.au/search hl=en&q=VB6+file+system+object&meta=

    tons of tutorials on the file system object :-)



  • yhong

    1. Is it possible to build hyperlinks in GUI using VB.

    A hyperlink is absolutely nothing special. It's simply a string.

     

    Take a label, put in url in it, set the font color to ble and underline it. In the double click routine, shell to explorer with that url as the argument.

    That's what a hyperlink is.

     



  • TahoePete

    Well....

    No, it's not English in origin at all. It's Latin. Forum is singular and fora is the plural forum.

    fo·rum ( P ) Pronunciation Key (form, fr-)
    n. pl. fo·rums, also fo·ra (for, fr)



  • ERK33136

    Yes, they are totally, utterly different. And most of your questions relate to the controls library, which is definately compeletely different.

    For example, that answer to question 3 is to use DateTime.Now to get the start and end dates, and subtract one from the other. You don't have that class in VB6.



  • How to read and write text files?