Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying a Text File in VB6

Status
Not open for further replies.

GolfBoy

MIS
Sep 5, 2001
35
0
0
GB
When errors occur in my application I would like record these in a Log file (Log.TXT).
I was going to use the FileSystemObject to do this.
Could anyone tell me if this is the correct way to do this and if so what is the best way to view the log file,
I was hoping to make the error log to look like the NT error log, so if anyone has any code/ideas I would be most thankful.

Yours Ian........

 
Hi,

Yes I think that's the way to do it. Use the FileSystemObject or standard VB command to write your log file and format it anyway you want it.
To view the file I guess that you have 2 basic options:
1) show the file in a (Rich)Textbox on a form:
--------------------------------------------------
Dim TmpStr As String, InFile As Byte
InFile = FreeFile
Open "c:\tmp\MyLog.txt" For Binary Access Read As #InFile
TmpStr = Space(LOF(InFile))
Get #InFile, , TmpStr
Close #InFile
Text1.Text = TmpStr
TmpStr = ""
--------------------------------------------------

2) Use an editor to show the logfile
--------------------------------------------------
Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
Public Sub OpenFile(file As String, Optional state As VbAppWinStyle = vbNormalFocus)
Dim sExec As String * 255
Dim lRetVal As Long
Dim iFN As Integer
Dim sTemp As String
sExec = Space(255)
' Then find the application associated with it.
lRetVal = FindExecutable(file, sTemp, sExec)
' If an application return the name
If lRetVal <= 32 Or IsEmpty(sExec) Then ' Error
Stop
Else
Shell Left(Trim$(sExec), Len(Trim$(sExec)) - 1) & &quot; &quot; & file, state
End If
End Sub

Private Sub Command1_Click()
OpenFile &quot;c:\tmp\test.txt&quot;
End Sub
--------------------------------------------------

Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top