Help with scripting

Hello,

I would like to write a VBS script that basically reads a file (only first line) and put it in a string and then display this string in DOpus title bar, it should be done periodically every X seconds. I tried to put the following lines inside a script but the script immediately disappeared from the script list. Can I mix VBS code and DOpus code in a script? Any information regarding this task will be highly appreciated.

Thank you

filePath = "C:\Temp\vblist.txt"
Set ObjFso = CreateObject("Scripting.FileSystemObject")
Set ObjFile = ObjFso.OpenTextFile(filePath)
StrData = ObjFile.ReadLine

DOpus.Create.Command.RunCommand( 'Set LISTERTITLE="'+strdata '"');

The last line:

DOpus.Create.Command.RunCommand( 'Set LISTERTITLE="'+strdata '"');uses JScript syntax, while the first three are looking like VBScript, you cannot mix these two languages.

A VBScript version of that line would probbaly look like this (not tested, I'm not fond of VBScript o):

DOpus.Create.Command.RunCommand("Set LISTERTITLE=""" & StrData & """")

Regarding your idea to update the lister title periodically, this is something that may yield specific issues and really needs perfect understanding of DO and scripting in general, you might wanna take a look at "ListerClock", a demonstrational attempt to update the lister title with a clock: Command: ListerClock (show a simple clock in lister title)
It's not perfect in it's current state though, and I didn't manage to upload a fixed version yet, so be careful.

I have tried to put the following in a button but when I press the button nothing happen.

filePath = "C:\vblist.txt"
Set ObjFso = CreateObject("Scripting.FileSystemObject")
Set ObjFile = ObjFso.OpenTextFile(filePath)
StrData = ObjFile.ReadLine
DOpus.Create.Command.RunCommand("Set LISTERTITLE=""" & StrData & """")

Make sure to open the console output pane (utilities -> other logs) and watch for errors, also make sure to wrap your code into an OnClick() function and that your buttion is of type "script function" or what it's called.

[code]@script vbscript
Option Explicit

Function OnClick(ByRef ClickData)
'//code here
End Function
[/code]

Sorry but it still does not work. Could you please tell me where to find the console utility log. If it is an option in the lister menu I just can't find it.

Thanks

Please rtfm! o)

Help (Menu) -> Logs -> Other Logs

You should also notice a little red blinking exclamation mark in the bottom right of the current lister if a script errors occured.
You can click that to open the scriptconsole.

The error is "variable FilePath is undefined|. If I remove the line with the FilePath it says "ObjFso variable is undefined".
It is strange because it will run ok (the VBS codes) if I run it directly from a VBS file, it will read the first line from a file. Is there a possibility that the compiler inside DOpus is buggy?

I found the problem. It seems that DOpus VBS compiler is more strict than of Windows.
It needs to initialize all the variables prior to using tham:

Dim filePath
Dim objfso
Dim objfile
Dim strdata

Now it is working.
tbone thank you very much for your help.

You're welcome! o)

Consider adding "Option Explicit" to the top of your vbs code wherever you execute it, it raises strictness and helps finding/avoiding errors like the one you encountered.

Opus doesn't have it's own version of VBS. The VBS used in Opus isn't more strict than the Windows one; it is the Windows one. :slight_smile:

You must have "option explicit" at the top of the script, which makes it so you have to Dim variables before using them (to prevent typos in variable names silently creating new variables instead of telling you about the error). (TBone is suggesting you add it, but I think you have it already, and it's why you need the Dim statements.)