• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 159
  • Last Modified:

Shared file access

What is the best way to log information to a text file from a vb app?  My log file will set on a network where multiple users of the app will access the file, possibly simulteously, just long enough to write a record and then close.  I've struggled with the OPEN command with print, write and put.  Any suggestions?  
0
rrh0561
Asked:
rrh0561
  • 5
  • 2
  • 2
  • +2
1 Solution
 
cable4096Commented:
This might be an easier way for you, it is a bit of a hack:

shell "echo " & s_text & " >> myfile.log"

Where s_text is the line to shell into the text file. The ">>" symbols will append to the end of the file.
0
 
TimCotteeCommented:
Here is an easier way still that isn't a hack! If you put

App.StartLogging "LogFile.TXT",vbLogToFile

In your form_load script, you can then use the following at any point to add a line to the log:

App.LogEvent "My Log Message"

To end logging use

App.StartLogging "",vbLogOff

You can also use this to log to the NT event log by using

App.StartLogging "",vbLogToNT
0
 
rondeaujCommented:
I agree with Tim answer. That is the best to create a log file in vb. The other way, which would be much harder is to open the file for Append.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
rrh0561Author Commented:
Here is my code and it doesn't work. Whats up?Option Explicit

Private Sub cmdGo_Click()
    App.LogEvent "test line"
    App.StartLogging "", vbLogOff
End Sub

Private Sub Form_Load()
    App.StartLogging "c:\temp\testlog.txt", vbLogToFile
End Sub


0
 
rondeaujCommented:
I think you should put this line of code in the start of your app

app.startloging "Logfile.txt",VbLogToFile


when you want to add an entry
App.LogEvent "Whatever you want here"

when you exit your prog

app.startloging "",VbLogOff

PLEASE NOTE: if this is an acceptable answer please note that the credit for this question should goto TimCottee



0
 
corvanderlindenCommented:
VbLogToFile Forces logging to a file. If no valid filename is present in LogPath, logging is ignored, and the property is set to vbLogOff.
0
 
rrh0561Author Commented:
How or where do you set LogPath.  I get the error "Can't assign read-only property" and help describes it as read-only at run time.  
0
 
rrh0561Author Commented:
How or where do you set LogPath.  I get the error "Can't assign read-only property" and help describes it as read-only at run time.  
0
 
rrh0561Author Commented:
Adjusted points to 150
0
 
corvanderlindenCommented:
Sorry for the inconvienience. You are right.

This code works for me, i tested it in the form_load event

Kill App.Path & "\debug.log"
App.StartLogging App.Path & "\debug.log", 2
Debug.Print "test"
App.LogEvent "test", vbLogEventTypeInformation

REMEMBER App.Logging is only active when you run your prog. as an EXE (it is not active in the IDE)
0
 
rrh0561Author Commented:
Thank You for your help it works great!
Bob
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 5
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now