
November 7th, 2003, 09:52 AM
|
|
Contributing User
|
|
Join Date: Jun 2003
Posts: 245
Time spent in forums: 11 m 27 sec
Reputation Power: 6
|
|
|
Write to a file in a certain format
Visual Basic 5.0
I write to a file and its output is as follow
"Some Text","A Date:",#2003-11-06#,"A number:",100
-----------------------------------------------
I would like to have a file output as below. The file below has
no double quotes around the data, and they are not separated
by a comma. Also, how do I write a blank line with a TAB on it ?
Code:
Some Text <-- the data, then a new line
A Date: <-- a TAB then the data, then a new line
2003-11-06 <-- a TAB then the data, then a new line
A number: <-- a TAB then the data, then a new line
100 <-- a TAB then the data, then a new line
=================================
Code:
Private Sub Command1_Click()
Dim strFile As String
Dim Program_Name As String
strFile = "C:\test5.txt"
Call dhWriteAndInput(strFile)
End Sub
Private Sub dhWriteAndInput(strFile As String)
On Error GoTo ErrorHandler
Dim hFile As Long
ReDim varData(1 To 5) As Variant
Dim i As Integer
'Open a file for output, write to it and close it
hFile = FreeFile
Open strFile For Output Access Write As hFile
Write #hFile, "Some Text", "A Date:", Date, "A number:", 100
Close hFile
'Now open it back up for reading
hFile = FreeFile
Open strFile For Input Access Read As hFile
Input #hFile, varData(1), varData(2), varData(3), varData(4), varData(5)
Close hFile
ErrorHandler:
Select Case Err.Number ' Evaluate error number.
Case 53 ' "File NetManage.ini does not exist on C:\"
MsgBox "File NetManage.ini does not exist on C:\"
Case 55 ' "File already open" error.
Close #1 ' Close open file.
Case Else
' Handle other situations here...
End Select
Resume Next
End Sub
|