Results 1 to 5 of 5

Thread: Problem in reading and writing files in VB6

  1. #1
    Join Date
    Jun 2009

    Problem in reading and writing files in VB6

    Hey I am writing program in VB, in that I try to open and edit the text file, I am not getting any problem till it opening also there is no problem in closing also but there is problem started when I edit this file and click to save the changes that time I face this problem I am not able to save any changes in this files, can anyone give me code or example code to solve this problem, and also tell me why I face problem in reading and writing files in VB6?

  2. #2
    Join Date
    Apr 2008

    Re: Problem in reading and writing files in VB6

    Use following I use this in my project also. It will solve your problem just copy past this code in VB and as code design your GUI.

    Private Sub Getmem_Click()
    Dim varone As String
    Open " enter your text file path " For Input As #1
    Input #1, varone
    Text1.Text = varone
    Close #1
    End Sub
    To write to a file, try this:
    Private Sub writefile_Click()
    Dim strmsg As String
    Dim Sname As String
    Open " enter your text file path " For Output As #1
    strmsg = MsgBox("File sample.txt opened")
    Sname = InputBox("Enter Name")
    Print #1, Sname
    strmsg = MsgBox("Writing a" & Sname & " to sample.txt ")
    Close #1
    strmsg = MsgBox("File sample.txt closed")
    End Sub

  3. #3
    Join Date
    May 2008

    Re: Problem in reading and writing files in VB6

    Hey I give you short but sweet code to use it and enjoy your project, it will help you to reduce the compile time and also reduce the code of line, every time write short but useful code it will help you to decreasing the compile time of your application.

    Dim txtstrmtr As String
    Open FILNAM For Input As #1
    txtstrmtr = Input(LOF(1), #1)
    Close #1

  4. #4
    Join Date
    Apr 2008

    Re: Problem in reading and writing files in VB6

    Here Open statement gives you to opening access and writing access to any of the file, here you can specify if you want to read it as text, write to it as binary, and so on. In this code you can set locking options, to stop other programs from opening the file.
    Use this code it work fine, without any modification

    Dim filnam as String
    Dim fileno as Integer
    fileno = FreeFile
    Open "C:\Test.txt" For Input As #fileno
    Do While Not EOF(fileno)
    Input #fileno, filnam
    MsgBox filnam
    Close #fileno

  5. #5
    Join Date
    May 2008

    Re: Problem in reading and writing files in VB6

    Reading/writing files can also be acheived using FILSYSO (FileSystemObject) as shown below. Please note that using FILSYSO requires an extra reference (under "Project"->"References"), and therefore extra files to be installed with your application.

    Option Explicit
    Dim filsys As FileSystemObject
    Dim txtstrm As Textxtstrmtream
    Set filsys = New FileSystemObject
    Set txtstrm = filsys.OpenTextFile("C:\test.txt", ForWriting, True)
    txtstrm.WriteLine "This is"
    txtstrm.WriteLine "VB Form"
    If filsys.FileExistxtstrm("C:\test.txt") Then
    Set txtstrm = filsys.OpenTextFile("C:\test.txt")
    Do While Not txtstrm.AtEndOfilsystream
    MsgBox txtstrm.ReadLine
    End If
    Set txtstrm = Nothing
    Set filsys = Nothing
    End Sub

Similar Threads

  1. Replies: 4
    Last Post: 22-02-2012, 11:08 PM
  2. Replies: 10
    Last Post: 14-01-2012, 09:13 AM
  3. lsass.exe continuously reading and writing disk
    By SmokiN in forum Networking & Security
    Replies: 3
    Last Post: 13-07-2009, 11:29 AM
  4. Lightscribe not writing files on otherside of the DVD
    By Ashton5 in forum Windows Software
    Replies: 5
    Last Post: 25-03-2009, 01:52 PM
  5. Writing and reading from file structures with the help of C
    By Janhavi4U in forum Software Development
    Replies: 2
    Last Post: 03-02-2009, 08:40 PM

Posting Permissions

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