Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Problem in reading and writing files in VB6

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 23-01-2010
Member
 
Join Date: Jun 2009
Posts: 1,518
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?

Reply With Quote
  #2  
Old 23-01-2010
Member
 
Join Date: Apr 2008
Posts: 1,947
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.

Quote:
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
Reply With Quote
  #3  
Old 23-01-2010
Member
 
Join Date: May 2008
Posts: 2,007
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.

Quote:
Dim txtstrmtr As String
Open FILNAM For Input As #1
txtstrmtr = Input(LOF(1), #1)
Close #1
Reply With Quote
  #4  
Old 23-01-2010
Member
 
Join Date: Apr 2008
Posts: 2,000
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

Quote:
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
Loop
Close #fileno
Reply With Quote
  #5  
Old 23-01-2010
Member
 
Join Date: May 2008
Posts: 2,290
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.

Quote:
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"
txtstrm.Close
If filsys.FileExistxtstrm("C:\test.txt") Then
Set txtstrm = filsys.OpenTextFile("C:\test.txt")
Do While Not txtstrm.AtEndOfilsystream
MsgBox txtstrm.ReadLine
Loop
txtstrm.Close
End If
Set txtstrm = Nothing
Set filsys = Nothing
End Sub
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Problem in reading and writing files in VB6"
Thread Thread Starter Forum Replies Last Post
"iPad, iPod Touch 4, iPhone 4 and iPod nano6 need network connection when reading and writing files" error with the ImTOO iTransfer Platinum Ashoka Windows Software 4 22-02-2012 11:08 PM
HP Pavilion p6126uk Desktop PC is not reading and writing any disk KKiran Hardware Peripherals 10 14-01-2012 09:13 AM
lsass.exe continuously reading and writing disk SmokiN Networking & Security 3 13-07-2009 11:29 AM
Lightscribe not writing files on otherside of the DVD Ashton5 Windows Software 5 25-03-2009 01:52 PM
Writing and reading from file structures with the help of C Janhavi4U Software Development 2 03-02-2009 08:40 PM


All times are GMT +5.5. The time now is 10:28 AM.