August 24th, 2005, 05:13 AM
|
#1 (permalink)
| | Member
Join Date: Jul 2005 Location: Cavite, Phil.
Posts: 94
| How to create, edit, and delete a text file using Visual Basic 6?
hi pips!
i'm working on a vb6 project right now and there's a part in it where i need to create a log file. anybody knows how 2 create a text file and then later on, edit or delete it?
i made some research and this is what i produced, so far: Sub GenerateLog(vValue As Variant, sField As String) Dim iFileNumber As Integer
Static iErrCtr As Integer
iErrCtr = iErrCtr + 1
iFileNumber = FreeFile
Open App.Path & "\HCFA_LOG.txt" For Append As #iFileNumber
If bLogCreated = False Then
Write #iFileNumber, "DATE: " & Format(Date, "MM/dd/yyyy")
Write #iFileNumber, "TIME: " & Format(Time, "hh:mm AMPM")
Write #iFileNumber,
Write #iFileNumber, End If
bLogCreated = True
Write #iFileNumber, "Error #: " & iErrCtr
Write #iFileNumber, "GUID: " & sDocGUID
Write #iFileNumber, "Error in field: '" & sField & "'"
Write #iFileNumber, "Data: " & vValue
Write #iFileNumber,
Close #iFileNumber End Sub
this works fine but i don't really like how the output looks (notice the quotation marks?). and everytime i call this sub, it doesn't overwrite the old one.
any kind of help is welcome.... thanks! 
__________________
keep 'em comin...
|
| |
August 25th, 2005, 12:26 AM
|
#2 (permalink)
| | Member
Join Date: Jul 2005 Location: Cavite, Phil.
Posts: 94
|
anybody?  |
| |
August 26th, 2005, 01:13 PM
|
#3 (permalink)
| | Banned
Join Date: Jan 2004 Location: Earth
Posts: 420
| |
| |
August 27th, 2005, 03:08 AM
|
#4 (permalink)
| | Member
Join Date: Jul 2005 Location: Cavite, Phil.
Posts: 94
| |
| |
August 14th, 2008, 05:27 AM
|
#5 (permalink)
| | Junior Member
Join Date: Aug 2008
Posts: 1
|
Ahh, I recently had the same problem as you, but in reverse.
I wanted to add data to my file every time, without overwriting what data already existed, as I was making a highscores list.
I was using the "OUTPUT" command instead of the "APPEND". If you're making a log file, you want the "OUTPUT" command. Just replace the word "APPEND" with "OUTPUT".
However, for the output command, your log file, HCFA_LOG.txt will need to already exist. If this is a problem, then perhaps you could use APPEND but also use the "kill" command to delete your text file upon opening your program each time?
EDIT: Oh yeah, and if you don't like the look of that the "write" command produces, use the "print" command in place of it. The print command doesn't store any data about strings or variables of any kind, so there are no quotations to separate variables. So, if it's just for the sake of its looks, use print.
Last edited by kid_headshot : August 14th, 2008 at 05:31 AM.
Reason: Adding more to my answer
|
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |
Posting Rules
| You may post new threads You may post replies You may not post attachments You may not edit your posts HTML code is Off | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |