Converting VBScript Scripts to Basic Scripts

<< Click to Display Table of Contents >>

Navigation:  Using SyncBackPro > Technical Reference > Scripting >

Converting VBScript Scripts to Basic Scripts

 

SyncBackPro V8 introduced a new scripting engine that supports both Basic and Pascal. Although the new Basic scripting language is very similar to VBScript, it is not identical. Although 32-bit SyncBackPro still supports the old VBScript scripting, the 64-bit version of SyncBackPro cannot use VBScript scripting due to limitations in the 64-bit versions of Windows. Therefore if you want your Basic scripts to work in both the 32-bit and 64-bit versions of SyncBackPro then they need to be converted to the new Basic scripting language (or the new Pascal scripting language). Also, VBScript was deprecated by Microsoft in October 2023.

 

The example scripts that are distributed with SyncBackPro have already been converted to the new Basic scripting language.

 

Below are some tips on how to convert your VBScript scripts to the new Basic language scripts:

 

Change the script filename extension from .VBS to .BAS

 

In the header of the script change SBLang=VBScript to SBLang=Basic

 

You cannot use ForEach. Instead you must use TEnumVariant.Create, e.g.:
 
FoldersEnum:=TEnumVariant.Create(Folder.SubFolders);
try
 while FoldersEnum.ForEach(SubFol) do begin
   If not SBLocation.AddDirEx2(SubFol.Name, SubFol.Attributes, SubFol.DateLastModified, SubFol.DateCreated, '') then
     Exit;
 end;
finally
 FoldersEnum.Free;
end;
 

You must use brackets with calls to sub-routines that have arguments (just as you must already do with functions).

 

When declaring functions or sub-routines, and there are no arguments, then don't use brackets, e.g.
 
Sub RunAfterConfig() - This is wrong
Sub RunAfterConfig   - This is correct
 

When declaring functions or sub-routines, and there are variable arguments (non-constant), then prefix them with var, e.g.
 
Sub RunAfterConfig(constvar1, variablevar2)                - This is wrong
Sub RunAfterConfig(constvar1, var variablevar2)        - This is correct
 

When calling functions or sub-routines that have no parameters, don't use empty brackets, e.g.:
 
RunAfterConfig() - This is wrong
RunAfterConfig   - This is correct
 

Variables do not need to be declared first but you must declare (or initialize) a variable if it is first set in the parameters on a call to a function or sub-routine.
 

You cannot combine lines using an underscore (_)  on the end of the line. Simply delete the underscores at the end of lines.
 

You can't have:
 
DO
 ' Code
LOOP
 
You must end with LOOP WHILE 1=1, for example.
 

Don't put comments after IF statements on the same line:
 
If SBProfile.GetCheckbox(3) Then ' THIS WILL CAUSE AN ERROR
 
If SBProfile.GetCheckbox(3) Then
' THIS IS OK

 

For integer division (\) you must instead use normal division (/) and cast the result with Int():

 

X = 100 \ 33                ' THIS WILL NOT COMPILE
X = Int(100 / 33)        ' THIS IS OK

 

 

VBScript functions

 

To help with compatibility with VBScript, the following functions are available in Basic scripts (refer to the MSDN documentation for the explanation of each function):

 

Asc

Atn

CBool

CByte

CCur

CDate

CDbl

Cint

CLng

CreateObject

CSng

CStr

DatePart

DateSerial

DateValue

Day

Fix

FormatCurrency

FormatDateTime

FormatNumber

Hex

Hour

InputBox

InStr

Int

IsArray

IsDate

IsEmpty

IsNull

IsNumeric

LBound

LCase

Left

Len

Log

LTrim

Mid

Minute

Month

MonthName

MsgBox (use SBSystem.ShowMessage instead)

Replace

Right

Rnd

RTrim

Second

Sgn

Space

StrComp

String

Timer

TimeSerial

TimeValue

UBound

UCase

Weekday

WeekdayName

Year

 

 

 

All Content: 2BrightSparks Pte Ltd © 2003-2024