|
Debugging vbscript in datalinks can be hard. I've implemented a logging function that lets you log into a file. This function is turned on by either setting a User Option ( Vision Setup - Profile - Products - Options ) or by logging in with Logging enabled ( on the Options tab of the login Window ). Each output to the log has a timestamp. Put this code at the start of your main Control Tag script. It will create a Control Tag showing if logging is enabled which is then used to switch out the logging instructions if they aren't used - so there is no performance overhead in having logging code in your datalink. The logfile is located in your Temp folder and is called Captains_Log_ with a timestamp on the end
An example of logging some diagnostic information -
{TagLogging=1} Log_Message "C_Name " + CStr(C_Name) + " C_Server " + CStr(C_Server) + " C_Database " + CStr(C_Database) {TagLoggingEnd}
/* CODE STARTS HERE */
select 'UserOption03',0,'Logging Enable - if set ignores Vision Logging - Captains_Log in %temp%' {OracleStart}From Dual{OracleEnd} GO
/*VBSCRIPT=10000 GLOBAL*/ dim WshShell dim tempdir dim objFSO dim objLogFile dim LogFileName Dim objLog Dim LsEngine_info Dim Logging_Enabled
' Extract the location of the System temporary folder ( same place Vision puts its logfiles
Set WshShell = CreateObject("WScript.Shell") tempdir = WshShell.ExpandEnvironmentStrings("%temp%") LogFileName = "Captains_Log_" + cstr(year(now)) + right( "00" + cstr(month(now)),2) + right( "00" + cstr(day(now)),2)+ right( "00" + cstr(hour(now)),2)+ right( "00" + cstr(minute(now)),2)
Set objFSO = CreateObject("Scripting.FileSystemObject")
{TagUserOption03=1} If 1 = 1 then {TagUserOption03Else} If objFSO.FileExists(tempdir+"\LsEngine.log") OR {TagUserOption03} = 1 Then Set objLog = objFSO.GetFile(tempdir+"\LsEngine.log") LsEngine_info = objLog.DateLastModified If Mid(LogFileName,14,4) = Mid(LsEngine_info,7,4) AND Mid(LogFileName,18,2) = Mid(LsEngine_info,4,2) AND Mid(LogFileName,20,2) = Mid(LsEngine_info,1,2) Then {TagUserOption03End}
Log_Message "############################################# Logging Started #############################" Log_Message "###" + cstr(LogFileName) +"###"
Log_Message "{FilterKey1ProductAuthorProductRegistration} " Log_Message "{FilterKey1ProductCode} " Log_Message "{FilterKey1ProductDescription}" Log_Message "{FilterKey1ProductVersion}" Log_Message "{FilterKey1ProductDemoMode}" Log_Message "UserOption01 = {TagUSerOption01}" Log_Message "UserOption02 = {TagUSerOption02}" Log_Message "UserOption03 = {TagUSerOption03}" Logging_Enabled = 1 oAlchemyControlTags.ADD "Logging","1" Else Logging_Enabled = 0 oAlchemyControlTags.ADD "Logging","0" End If {TagUserOption03=0} Else Logging_Enabled = 0 oAlchemyControlTags.ADD "Logging","0" End If {TagUserOption03End}
Sub Log_Message ( Text_Message ) Set objLogFile = objFSO.OpenTextFile(cstr(tempdir) +"\" + cstr(LogFileName) +".log", 8, True) objLogFile.Writeline Date & " " & Time & " " & Text_Message
objLogFile.Close
end sub
GO
|