Erdenemandal Posted September 14, 2004 Posted September 14, 2004 Hi , All I have a problem . I want to save every operation into Log file. I have "Start", "working" form. But strange thing is from "Start" form it writes into Log file and from "Working" form it does not write anything, Can somebody help me- this is a code in module WriteLog function declared PUBLIC Public Sub WriteLog(ByVal text1 As String, ByVal Text2 As String) If Not System.IO.Directory.Exists(CurDir() + "\sources\Logs\") Then System.IO.Directory.CreateDirectory(CurDir() + "\sources\Logs\") End If Dim myLogName As String = CurDir() + "\sources\Logs\Running.log" If System.IO.File.Exists(myLogName) Then Dim FI As New System.IO.FileInfo(myLogName) If FI.Length > 100000 Then Dim dS As String = Date.Now.Today.ToShortDateString dS = dS.Replace(".", "") Dim dT As String = DateTime.Now.ToLongTimeString dT = dT.Replace(":", "") System.IO.File.Move(myLogName, CurDir() + "\sources\Logs\Log_" + dS + dT + ".bak") End If End If Try Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter(myLogName, True) sw.WriteLine(Date.Now.Today.ToShortDateString + " " + DateTime.Now.ToLongTimeString + " : " + text1 + ControlChars.Tab + ControlChars.Tab + Text2) sw.Close() Catch ex As Exception MsgBox(ex.Message) End Try End Sub in Start form WriteLog("Patient " & mPersonID & " has Logged in ", "DONE") in Working form WriteLog("Basci stimulation Started", "Done") Quote
Erdenemandal Posted September 14, 2004 Author Posted September 14, 2004 solution At the end I found a problem . Because of "Curdir" function . It gives me a current directory. But In "Working" form I use openFileDiaglog. It changes current folder name . So that after "working" form "Curdir" retunrs me openned folder name. Therefore Please be careful use "CurDir" after FileOPenDialogBox Thanks, Erdenemandal Quote
Administrators PlausiblyDamp Posted September 14, 2004 Administrators Posted September 14, 2004 You may be better of using the .Net version of CurDir anyway System.IO.Directory.GetCurrentDirectory() 'or Environment.CurrentDirectory If the folders are always going to be relative to the running application's path then Application.ExecutablePath maybe a better choice. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Wile Posted September 14, 2004 Posted September 14, 2004 What also helps is setting the RestoreDirectory property of the file dialog. It ensures that the current directory, after the dialog is closed, is restored to the location it was pointing before the dialog was opened. Quote Nothing is as illusive as 'the last bug'.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.