I am writing a quick log function and am trying to use some variables (specifically: lLogDir and lLogFile) outside of the function to actually create the file. I wanted the Logit function to not only log entries but also handle creating the directory the log files will reside in.
Using
Code: Select all
put Logit("HEADER") into URL ("file:" & lLogDir & lLogFile)
I even tried giving the variables a global scope in the function (thinking this would allow them to be accessed outside of the function) but that didn't work either. Please help show a new guy the way...

Code: Select all
on mouseUp
--put the defaultfolder & "\Logs\" into lLogDir
--put the long date & ".log" into lLogFile
put Logit("HEADER") into URL ("file:" & lLogDir & lLogFile)
end mouseUp
function Logit pType, pMessage
switch
case pType = "HEADER"
Global tLogDir, tLogFile
put "=================================================" into tHeaderLine1
put "Application started on:" && the short system date && "at:" && the short system time into tHeaderLine2
put "Operating System:" && $OS into tHeaderLine3
put "User:" && $USERDOMAIN & "\" & $USERNAME into tHeaderLine4
get the defaultfolder
put the defaultfolder & "\Logs\" into lLogDir
create folder lLogDir
put "Application directory:" && it into tHeaderLine5
put "Log directory:" && it & slash & "Logs" into tHeaderLine6
put the long date & ".log" into lLogFile
put "=================================================" into tHeaderLine7
return lLogDir & lLogFile & tHeaderLine1 & CRLF & tHeaderLine2 & CRLF & tHeaderLine3 & CRLF & tHeaderLine4 & CRLF & tHeaderLine5 & CRLF & tHeaderLine6 & CRLF & tHeaderLine7 & CRLF
break
case pType = "INFO"
return pType & ":" && pMessage
break
case pType = "ERROR"
return pType & ":" && pMessage
break
end switch
end Logit
end mouseUp