File Logging Module

By | 2018-06-15

This is a simple module that will allow you to log events from within your program to a text file. This is more of a string handling demo, but could be useful as a starting point for something bigger.

If you’re like me, you like to know what is going in your application. This information comes in handy if and when something goes wrong. You’ll have some idea where execution stopped, and why.

I popped this together more as a demonstration of how to work with strings and variables, but it does perform a useful function.

Some high points of this script are:

  • One log file for each day.
  • Shows two methods for creating an ISO8601 compliant date and date/time.
  • How to write to a text file.
  • Usage of functions to extend functionality.

It should be noted (and it is in the comments inside the module) that there is a simpler way of creating ISO8601 date and time data. By using the built-in Format$ function of VB6, the string can be built in one line.

The syntax for creating and ISO8601 date is:

ISO8601Date = Format$(Now, "yyyy-mm-dd")

If you want to create a date/time string, simply extend it:

ISO8601DateTime = Format$(Now, "yyyy-mm-dd") & " " & Format$(Now,"hh:mm:ss")

Can you find other cool ways of using the format$ function? Or maybe you have a better method? Give a shout in the comments, or start a thread in the forums!

Attachments

FileUploadedSize
389-20180615-095553-LogIt.zip6/15/2018 9:55:53 AM1408
Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.