home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

How to create, edit, and delete a text file using Visual Basic 6?

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2437
Discussions: 200,941, Posts: 2,379,276, Members: 246,304
Old August 24th, 2005, 05:13 AM   Digg it!   #1 (permalink)
Member
 
Acid_ICE24's Avatar
 
Join Date: Jul 2005
Location: Cavite, Phil.
Posts: 94
Question
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 #iF
ileNumber, "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!
Attached Files
File Type: txt HCFA_LOG.txt (1.3 KB, 2243 views)
__________________
keep 'em comin...
Acid_ICE24 is offline   Reply With Quote
Old August 25th, 2005, 12:26 AM     #2 (permalink)
Member
 
Acid_ICE24's Avatar
 
Join Date: Jul 2005
Location: Cavite, Phil.
Posts: 94
anybody?
Acid_ICE24 is offline   Reply With Quote
Old August 26th, 2005, 01:13 PM     #3 (permalink)
Banned
 
Iturea's Avatar
 
Join Date: Jan 2004
Location: Earth
Posts: 420
Look Here: http://www.garybeene.com/code/visual%20basic.htm
Iturea is offline   Reply With Quote
Old August 27th, 2005, 03:08 AM     #4 (permalink)
Member
 
Acid_ICE24's Avatar
 
Join Date: Jul 2005
Location: Cavite, Phil.
Posts: 94
hey, thanks! :-)
Acid_ICE24 is offline   Reply With Quote
Old August 14th, 2008, 05:27 AM     #5 (permalink)
Junior Member
 
Join Date: Aug 2008
Posts: 1
Lightbulb

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
kid_headshot is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual Basic Help? redfoxstorm Webmastering and Programming 1 February 14th, 2005 11:39 AM
HELP!! - Visual Basic darssus Webmastering and Programming 1 October 6th, 2004 02:40 PM
Scan Text (Visual Basic .NET question) firewolf Applications and Operating Systems 2 October 4th, 2003 03:23 PM
Visual Basic .Net - DLL file question firewolf Applications and Operating Systems 15 September 17th, 2003 11:25 PM
Visual Basic HELP!!!!!!!!!!!!!!!!!!!!!!!!!!!!! George VII Webmastering and Programming 8 May 18th, 2002 06:46 PM


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (2916)
windows 7 problem (7)
CPU fan stops spinning randomly (8)
Wireless Televisions. (8)
California Passes Anti-Flat-HDTV Le.. (43)
Regular Build (6)
Obama the Muslim (14)
Is the PSU I received dead? (11)
HIS HD5770 graphic card question (15)
windows vista security holes (9)
Install XP pro and a Vista laptop ?.. (11)
Print spooler problem (13)
Foreign voltage (10)
Dept. of HS: NSA 'Helped' Develop V.. (15)
Recent Discussions
radeon x850xt platinum & shader 3 (4)
screen resolution vs monitor size (1)
sms storage to PC (0)
Regular Build (6)
Open With ..... Win7 (0)
java code for fibonacci (1)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (35)
windows 7 problem (7)
CPU fan stops spinning randomly (8)
Partition Magic caused HDD problem (3)
Is the PSU I received dead? (11)
Have you switched yet? (85)
Point and Shoot Camera Suggestions. (2)
Modern Warfare 2 freeze (13)
Wireless Televisions. (8)
wireless user (1)
World's largest Monopoly Game using G.. (332)
Ideal cheap graph card for PC-Gaming? (17)
BIOS won't read disk when I try to fl.. (0)
Install XP pro and a Vista laptop ?? (11)
Graphics Card Upgrade Question (1)
favorit (1)
solutions for virtical white lines on.. (1)
Fire in DVD (2)
Modern Warfare For the PC (33)


All times are GMT -4. The time now is 02:40 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28