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?  
rrh0561Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
TimCotteeHead of Software ServicesCommented:
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 Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rrh0561Author Commented:
Thank You for your help it works great!
Bob
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.