Scripting: vbCrLf stopped working in Output Window?

Not sure when this broke... but somewhere along the way vbCrLf just stopped working in Opus output window messages:

Sample OnAfterFolderChange Event Handler Script - just to log messages:

[code]Option Explicit

' Called by Directory Opus to initialize the script
Function OnInit(ByRef initData)

DOpus.Output("Initializing..." & vbCrLf)
' Provide basic information about the Script
initData.name = "OnAfterFolderChange_vbtest"
initData.desc = "Adds a test 'OnAfterFolderChange' event handler to Directory Opus."
initData.copyright = "(c) 2014 steje"
initData.version = "v1.0.0 (vb)"
initData.default_enable = True

'////////////////////////////////////////////////
' Set DEBUG flag below to true in order to enable logging messages to the Opus Output Window
initData.config.DEBUG = True

End Function

' Called after a folder has been opened
Function OnAfterFolderChange(ByRef afterFolderChangeData)

logMsg("")
logMsg("------------Begin------------" & vbCrLf)

logMsg("Sourcetab: " & afterFolderChangeData.tab)
logMsg("Path: " & afterFolderChangeData.tab.path & vbCrLf & vbCrLf)

logMsg("Desttab: " & afterFolderChangeData.tab.lister.desttab)
logMsg("Path: " & afterFolderChangeData.tab.lister.desttab.path & vbCrLf)

logMsg("-------------End-------------" & vbCrLf)

End Function

' Subroutine to allow toggling of the global VT_BOOL variable to control whether logging is performed or not
Sub logMsg(message)

If (Script.config.DEBUG) Then DOpus.Output(message)

End Sub[/code]

Seems to work here:


Leo,

You are using the CLI while he is using the LOGMSG function. Not knowing the innards of Dopus, I cannot say, for sure, that they are not the same. But I would be more convinced if yours worked running his script (of the applicable part of it). Not that I have a dog in this fight - just saying.

The screenshot shows both the CLI and the script log panel.

My logMsg function is just a wrapper for DOpus.Output that lets me control logging via a debug flag... but to simply everything I dropped it and from some quick testing have found the dropping of the vbCrLf is very specific to when no other data appears after the vbCrLf for output. So... only TRAILING vbCrLf codes are being dropped by Opus.

But maybe more odd is that it's not consistently the case across the different methods of calling a script in Opus...

For instance, this bit of code works fine in both the Script Interpreter and in a Script function button:

DOpus.Output("Line 1" & vbCrLf & "Line 2" & vbCrLf & vbCrLf) DOpus.Output("Line 5")
But the same code in a Script Add-In (I tested both as a Script Command and an event handler) dropped the trailing vbCrLf's in the first output message (while the one between the Line 1 and Line 2 strings go through fine):

[code]Option Explicit
' Called by Directory Opus to initialize the script
Function OnInit(ByRef initData)

DOpus.Output("Initializing...")
' Provide basic information about the Script
initData.name = "ScriptCommand_vbtest"
initData.desc = "Adds the 'VBtest' script command to Directory Opus."
initData.copyright = "(c) 2014 steje"
initData.version = "v1.0.3 (vb)"
initData.default_enable = True

' Initialise the command that this script adds
Dim cmd
Set cmd = initData.AddCommand()
cmd.name = "VBtest"
cmd.icon = "script"
cmd.method = "OnVBtest"
cmd.desc = "VBtest - a test script for checking my slop code..."
cmd.label = "VBtest"
cmd.template = "STRING/O"

End Function

' Implement the VBtest command
Function OnVBtest(ByRef commandData)

DOpus.Output("Line 1" & vbCrLf & "Line 2" & vbCrLf & vbCrLf)
DOpus.Output("Line 5")

End Function[/code]

If there is a NULL character in a text string VB will not handle it correctly. That may explain why some lines work (show CR/LF) and others don't.

There are no NULL chars here... just valid text and CR/LF. And I think where that problem pops up often is when reading text from a file in vbscript, but happy to believe there are other cases where it's a problem as well.

In any case, the point of the last post was to illustrate that the SAME output messages work when run from some parts of Opus but not others (as mentioned - the same messages work fine from both the script interpreter and when run from a script function button - but fail when run from either an event handler or script command).

Following Leo's example of what worked - adding a single space after the last vbCrLf ( & " ") then allows the two CR/LF that are being dropped to be displayed as expected.

Hardly a critical issue but just the same, it's wrong - and inconsistently so...