;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       Msg() / LMsg() / EMsg() / Abend() / Dbg() - DEPRECATED in ITCG CODING-See fMsg() 
;;               - See fMsg() for combined/enhanced functionality 
;; 
;;ACTION         Writes message text to the console and/or a defined logfile 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION	 2.0  - 2009/10/19 
;; 
;;HISTORY        1.0  - 2004/08/11 - Initial Release 
;;               2.0  - 2009/10/19 - Added optional timestamping to Msg/LMsg functions 
;; 
;;SYNTAX         Msg(text,[NoNL] [,TFlag]) 
;;               LMsg(text,[NoNL] [,TFlag]) 
;;               EMsg(text) 
;;               Abend(text,[err]) 
;;               Dbg(text [,Lvl]) 
;; 
;;PARAMETERS     Text    - Message to be displayed 
;;               NoNL    - Suppress newline if true 
;;		 TFlag	 - Adds a timestamp to the ouput if true 
;;               Err     - Exit code for Abend(), default is 1 
;;		 Lvl	 - Display debug message only if $DEBUG is set and <= $Lvl 
;; 
;;REMARKS        Basic output for optional logging of screen status messages 
;;		 Error and Debug messages are date/time stamped 
;; 
;;RETURNS        nothing 
;; 
;;DEPENDENCIES   Requires a GLOBAL variable to define the log file name - $Msg_Log_ 
;;               A GLOBAL variable allows independent functions to use the  
;;               Msg function without being aware of the log file. If this  
;;               var is null or not defined, output will be sent to the console. 
;; 
;;TESTED WITH    NT4, W2K, WXP 
;; 
;;EXAMPLES       Msg("Loading data...") 
;; 
; 
 
Function Msg($_Text, OPTIONAL $_NoNL, OPTIONAL $_TStamp)
 
  Dim $_
 
  ; add optional timestamp, if requested 
  If $_TStamp $_Text = @DATE + ' ' + @TIME + ':' + $_Text EndIf
 
  ; Add CRLF if not suppressed 
  If Not $_NoNL $_Text = $_Text + @CRLF EndIf
 
  $_ = RedirectOutput($MSG_LOG_)
    $_Text
  $_ = RedirectOutput('')
  Exit 0
  
EndFunction
 
 
;Secondary Function - always display AND log (if log is defined) 
Function LMsg($_Text, OPTIONAL $_NoNL, OPTIONAL $_TStamp)
 
  Dim $_
 
  ; add optional timestamp, if requested 
  If $_TStamp $_Text = @DATE + ' ' + @TIME + ':' + $_Text EndIf
 
  ; Add CRLF if not suppressed 
  If Not $_NoNL $_Text = $_Text + @CRLF EndIf
 
  $_Text
 
  If $MSG_LOG_
    $_ = RedirectOutput($MSG_LOG_)
    $_Text
    $_ = RedirectOutput('')
  EndIf
  Exit 0
 
EndFunction
 
 
;Secondary Function - write to ERROR log, display only if DEBUG is active 
; Always timestamp and add Newline 
Function EMsg($_Text)
 
  Dim $_
 
  $_Text = @DATE + ' ' + @TIME + ':' + $_Text + @CRLF
 
  ; display on console if debugging 
  If $DEBUG
    $_Text
  EndIf
 
  If $ERR_LOG_
    $_ = RedirectOutput($ERR_LOG_)
    $_Text
    $_ = RedirectOutput('')
  EndIf
  Exit 0
 
EndFunction
 
 
; secondary function - outputs via Msg() only if global DEBUG is true 
; If Lvl is specified, messages will display only if $DEBUG <= $_Lvl, otherwise 
; all messages will display. Timestamps and newlines are always added. 
Function Dbg($_Text, OPTIONAL $_Lvl)
 
  $_Lvl = IIf($_Lvl, $_Lvl, 99)
 
  if $DEBUG > 0 And $DEBUG <= $_Lvl
    $_Text = @DATE + ' ' + @TIME + ':' + '-DEBUG-' + $_Text
    Msg($_Text)
  EndIf
  Exit 0
 
EndFunction
 
 
; Secondary function - Outputs via Msg() only if $MSG_LOG_ is defined 
; Always outputs to the console, then aborts all processing 
; Terminates script with 1 unless ErrCode is specified 
Function Abend($_Text, OPTIONAL $_ErrCode)
 
  $DEBUG = 1			; turn on to force console error 
  If Not $ERR_LOG_ And $MSG_LOG_
    $ERR_LOG_ = $MSG_LOG_	; write to MSG LOG if ERR_LOG is not defined 
  EndIf
  EMsg($_Text)			; display & log error message 
  $_ErrCode = IIf($_ErrCode = '', 1, $_ErrCode)
  Quit $_ErrCode
 
EndFunction