FabyaVisionUser Manual
/

VBScript scripts

8 min readScripts

The structure of a VBS script (Module and Action), supported language features, access to tags and screen objects, and the known differences from real VBScript.

Scope of the language

VBS scripts run in the product's own VBScript engine; Windows Script Host is not required. The engine has been tested side by side with the real Windows VBScript engine (operators, conversions, strings, dates, formatting, arrays, error behavior, loops, procedures, classes). The deliberately retained differences are listed at the end of this topic.

Supported structures

GroupStructures
DeclarationDim, ReDim (including Preserve), Erase, Const, Option Explicit, Public / Private
ConditionIf … Then … ElseIf … Else … End If, Select Case (Case 1, 2, Case Else)
CycleFor … Next (Step), For Each, Do … Loop (While / Until), While … Wend, Exit For / Exit Do
ProcedureSub, Function, Call, ByVal / ByRef, Exit Sub / Exit Function
ObjectSet, Nothing, Is, With, Class (Property Get / Let / Set, Class_Initialize)
ErrorOn Error Resume Next, On Error GoTo 0, Err object (Number, Description, Source, Clear, Raise)
WritingLine continuation (_), several statements on the same line with :, ' and Rem comments, &h hexadecimal numbers, #tarih# constants

Built-in functions

The Functions tab in the Reference panel gives the complete list. Groups:

  • Conversion: CStr, CInt, CLng, CDbl, CBool, CDate, Round, Hex
  • Math: Abs, Sqr, Sin, Log, Rnd; operators \, Mod, ^
  • Text: Len, Left, Mid, InStr, Replace, Split, Join, UCase, Trim, Chr, FormatNumber
  • Date and time: Now, Timer, Year, Hour, Weekday, DateAdd, DateDiff, DateSerial
  • Type checks: IsEmpty, IsNull, IsNumeric, IsArray, TypeName, VarType
  • Array: Array, UBound, LBound, Filter
  • Interaction: MsgBox, InputBox (a centered window that matches the theme), RGB, CreateObject

Constants: MsgBox constants such as vbCrLf, vbTab, vbYes / vbNo, vbYesNo, vbQuestion and predefined colors such as vbRed.

Objects that can be created with CreateObject

ProgIDWhat forPermission
Scripting.DictionaryKey → value listNot required
System.Collections.ArrayListGrowable listNot required
VBScript.RegExpRegular expression (Pattern, Test, Execute, Replace)Not required
ADODB.Connection, ADODB.Recordset, ADODB.CommandDatabase query via ODBCDatabase connection
WScript.ShellStarting a program (Run)Program execution
Scripting.FileSystemObjectFile and folder operationsFile access
WScript.NetworkComputer and Windows user nameNot required

If a different ProgID is given, an error occurs at run time; Studio also warns about it during compilation.

Script types

Module

Holds the procedures (Sub, Function). The procedures of all VBS modules and the module-level variable / constant declarations share a common namespace: a procedure defined in one module is called by name from another module. For this reason the same procedure name cannot be used in two modules (Studio reports an error). In the same module, the second definition silently takes effect (Studio issues a warning).

If no procedure is selected in the event or task, the procedure with the same name as the module runs; to run a different one, select it from the Procedure list. Lines outside a function run once when the project is opened.

' T-101 şerbet tankı seviye denetimi (Tanıtım_Tesisi)
Const ALT_SINIR = 40
Const UST_SINIR = 88

Function Seviye_Durumu(seviye)
    If seviye < ALT_SINIR Then
        Seviye_Durumu = "DÜŞÜK"
    ElseIf seviye > UST_SINIR Then
        Seviye_Durumu = "YÜKSEK"
    Else
        Seviye_Durumu = "NORMAL"
    End If
End Function

Sub Tank_Seviye_Denetimi()
    Dim seviye, durum
    seviye = SmartTags("T101_Seviye")
    durum = Seviye_Durumu(seviye)
    If durum = "NORMAL" Then
        SmartTags("T101_Uyari") = 0
    Else
        SmartTags("T101_Uyari") = 1
    End If
End Sub

Action

This is code that runs from the beginning on every call. If the code contains Function Action() (or Sub Action), that one runs; otherwise the whole code is regarded as the body and can be ended with Exit Sub. No procedure is selected in an action. Helper Function procedures in an action are visible only inside that action.

Option Explicit
Function Action()
    If SmartTags("Tank1_Seviye") >= 80 Then
        SmartTags("Tank1_Durum") = "Yüksek"
    Else
        SmartTags("Tank1_Durum") = "Normal"
    End If
    Action = 0
End Function

VBS code written in the event

In the Run VBS code function, the code is written directly into the event (it runs like an action body). Here, Item (the object of the event; the screen for a screen event), ScreenItems, Layers, DataSet and Parent (the screen of the event) are available.

' Tıklanan nesnenin rengini değiştirir
Item.BackColor = RGB(255, 0, 0)

How tag values appear in VBS

  • A Bool tag arrives in VBS as a "binary" value: = 1, = True, If x Then, Not x and And / Or all work. CInt returns 1 or 0, CStr returns "1" or "0", and TypeName returns Boolean. When writing, True, 1 and every number other than zero are written as 1.
  • The logical properties of objects (Visible, Enabled, FontBold …) are not tags; they return a real Boolean (True / False).
  • Converting numbers and dates to text follows the Windows regional settings of the Live computer: if the decimal separator is a comma, CStr(1.5) becomes "1,5" and CDbl("1,5") becomes 1.5. If a fixed format is required, use Day, Month, Year, Hour … and join the parts.
  • Quality: the value of HMIRuntime.Tags("Ad").QualityCode means: 192 good, 84 tag outside its limits, 8 no connection.
  • A non-existent tag or a value that cannot be written does not stop the script. If a tag that is not in the project is read, the value returned is Empty, LastError is filled and the warning Tag bulunamadı (okuma): Ad is written to the event log; for writing, Tag bulunamadı (yazma): Ad is written. A value that cannot be converted to the type of the tag (e.g. text written to a numeric tag) is written to the log in the same way, and the tag does not change. To catch these cases, check the values of Tag.LastError (0 = no error) and Tag.QualityCode.
  • Tag names are not case-sensitive.

Error handling

Only On Error Resume Next and On Error GoTo 0 are supported. Errors are checked with Err.Number.

Sub Hata_Yakalama()
    Dim sonuc
    On Error Resume Next
    sonuc = SmartTags("Toplam_Miktar") / SmartTags("Parti_Adedi")   ' adet 0 ise hata 11
    If Err.Number <> 0 Then
        SmartTags("Hata_Metni") = "Hata " & Err.Number & ": " & Err.Description
        sonuc = 0
        Err.Clear
    Else
        SmartTags("Hata_Metni") = ""
    End If
    On Error GoTo 0
    SmartTags("Parti_Ortalama") = sonuc
End Sub

An unhandled error stops the script and is written to the event log in the format Modül / Prosedür, satır N: ileti (hata numarası). The program keeps running.

Database, file and program

These objects depend on the Script permissions. The database connection is stateless: each command opens and closes its own connection; there are no transactions, no temporary #tablo tables and no updates through a recordset (AddNew, Update, Delete). Records are added and changed with conn.Execute "INSERT …". WScript.Shell.Run starts the program but does not wait for it to finish. Details: Database access.

Known differences from real VBScript

TopicFabyaVision
Execute, ExecuteGlobal, Eval, GetObject, GetRefNot available. If used, the script stops with an error such as 'Eval' bu sürümde desteklenmiyor.
On Error GoTo etiket, ResumeNot available; produces a syntax error.
Number subtypesNot available. Numbers are kept in a single type; TypeName returns a name based on the value (Integer for 5, Double for 1.5). CSng rounds to 7 significant digits, but no Single type is created.
Class_TerminateNot called (it cannot be known when the object is released).
Names with Turkish lettersLetters such as ş, ğ and ı are accepted in variable and procedure names (real VBScript accepts only ASCII letters).
ByRefWorks by copying the value and writing it back.
Variables used without DimA name declared at module level is global to every procedure. If you use Option Explicit, an undefined name causes the error Değişken tanımlı değil.

Limitations and points to note

  • A call can compute for at most 30 seconds; only the time the code itself runs is counted (tag writes, database access and waiting for MsgBox are not counted). VBS has no wait function; a Do While loop that checks the time difference counts as the code's own time and is interrupted. For long waits, use a cyclic task.
  • HMIRuntime.Alarms, AlarmLogs, DataLogs, Logging and MenuToolBarConfig are not available in this version.
  • For the same task or event row, a call that arrives while the previous call is still running is skipped.
  • Scripts do not run in monitoring mode from a browser or the TV.

Related topics

FabyaVision 0.1.0 User Manual · 18 October 2026© Fabyatek Yazılım Bilişim Teknolojileri Ltd. Şti.