VW Scripting

DGS Manager has a scripting engine built into it. The syntax is based off of VB Script with a few minor changes. It is currently in its early developments and is used in our calculator, views, inputs and DGS.net.

Core Functions

Core functions are available anywhere the scripting engine is used.

Function Description
ABS(Value) Absolute value will always return a positive number.
AVG(Value,[Condition]) Average will take a column or calculation over a table and return the arithmetic mean.
ex.
x = AVG(Value) ''Average of all values
x = AVG(Value,"Value>5") ''Average of value where value is greater_then 5
Beep() Preforms a system beep
Ceiling(Value) Rounds a value up
ex. Ceiling(4.3)=5
Date(Year,Month,Day,Hour,Min,Sec,mSec) Creates a Date time from values
ex. Date(1981,5,5,15,30,0,0) = May 5th, 1981 3:30pm
MCSecToDate(Millisec)
DateAdd(Interval,Number,Date) Adds the number to the date based on the interval type.
yyyy=year, q=qurter, m=month, y=day of year, d=day, w=weekday, ww=week of year, h=hour, n=minute, s=second
ex. dt=DateAdd(“d”,5,dt) 'Adds five days to dt
DateDiff(Interval,Date,Date2) Gets the difference between two dates based on the interval
yyyy=year, q=quarter, m=month, y=day of year, d=day, w=weekday, ww=week of year, h=hour, n=minute, s=second, ms=millisecond
ex. iDiff=DateDiff(“s”,dt1,dt2) 'will return the difference in seconds between dt1 and dt2
DatePart(Interval,Date1) Returns a Integer containing the specified interval of a given date.
yyyy=year, q=quarter, m=month, y=day of year, d=day, w=weekday, ww=week of year, h=hour, n=minute, s=second
ex. i=DatePart(“yyyy”,“1981-05-05 11:00:00”) 'i is set to 1981
Decode(Value) Decodes a string that has been encoded with the encode function.
ex. Decode(“VHV4”)=Tux
Decrypt(Value,Key) Decrypts a string with a provided key that has been encrypted with the encrypt function.
ex. decrypt(“juzIYgF0Ghk=”,“Password”) = Hello
Encode(Value) Encodes a string that can be decoded with the decode function
ex. Encode(“Tux”)=VHV4
Encrypt(Value,Key) Encrpyts a string with a provided key that can be decrypted with the decrpyt fuction.
ex. Encrypt(“Hello”,“Password”) = juzIYgF0Ghk=
Floor(Value) Rounds a value down
ex. Floor(4.99) = 4
Format(Value,FormatString) Returns a string formatted according to instructions contained in a format String.
ex. Format(3.234,“#,##0.0”) = 3.2
GetStringHeight(Text,Font,MaxWidth)
GetStringWidth(Text,Font) Returns the width in pixel of a string using a font. ex.
iStringWidth=GetStringWidth(fld.Text,fld.Font) 'will return the width in pixels of the text in fld 
IIF(Value,IfTrue,IfFalse) Returns one of two objects, depending on the evaluation of an expression. ex.
Report.Fields("NAME").Visible = IIF((Param2="Value"), "False", "True")
ImageToBytes(Image)
InputBox(Text,[Title],[Default Value])
IsDate(Value) Returns a true or false indicating whether an expression represents a valid Date ex.
t=IsDate("adsflkj") 't=false
t=IsDate("1981/05/05") 't=true
IsNull(Value,ValueIfNull) Replaces NULL with a replacement value. ex.
t=IsNull(Null,5) 't=5
t=IsNull(2,5) 't=2
IsNumeric(Value) Returns a true or false indicating whether an expression represents a valid Number ex.
t=IsNumeric("adsflkj") 't=false
t=IsNumeric("42") 't=true
MAX(Value,[Value2]) Returns the maximum value out of a set of expressions.
MAXF(Value,[Condition])
MIN(Value,[Value2]) Returns the minimum value out of a set of expressions.
MINF(Value,[Condition])
MsgBox(Message) Displays a message box.
ex. MsgBox(“Test”)
Pow(Value,Exponent) Returns a specified number raised to the specified power. ex
s = Pow(5,2) 's=25
RGB([Alpha],Red,Green,Blue) Creates a Color from four 8-bit ARGB components (alpha, red, green, and blue). If only 3 parameters are passed in alpha will be given the value of 255.
ex. txt.BackColor = RGB(255,0,0) - Sets the back color to of txt to red
Round(Value,[Precision]) Returns a numeric value, rounded to the specified precision.
ex. ROUND(5.724,1) = 5.7
ScaleImage(Image,Width,Height,[Image Format])
ShowOpenFile(Filter) Returns a file path if successful or empty string if fails.
ex. sFile=ShowOpenFile(“Image Files (*.bmp, *.jpg, *.png, *.gif)|*.bmp;*.jpg;*.png;*.gif”)
ShowSaveFile(FileData,[FileName],[Filter])
Sqrt(Value) Returns the square root of a specified number. ex
s = Sqrt(25) 's=5
Start(Path) Opens file, URL or executable at path provided
ex. Start(“http://google.ca”)
SUM(Value,[Condition]) Summation will take a column or calculation over a table and return the values added together.
ex. SUM(Value) or SUM(Value,Value>5) - Summation of all values greater then 5
FOR loop
FOR i = 1 TO 15 
  Report.Fields("dt"&i).Width = BoxWidth 
NEXT 

File Functions

Function Description
FileExists(FilePath) Returns true if file exists
ex.
f=FileExists("C:\Test.txt") ''f will be True if C:\Test.txt is there False if not there
GetCreationTime(FilePath) Returns date time file was create
ex.
f=GetCreationTime("C:\Test.txt") ''f will be date and time C:\Test.txt was created
GetFile(FilePath) Returns the content of a file usually used with function ShowOpenFile
ex.
sFile=ShowOpenFile("Image Files (*.bmp, *.jpg, *.png, *.gif)%%|%%*.bmp;*.jpg;*.png;*.gif")
IF sFile<>"" THEN
  img = GetFile(sFile)
END IF
GetFileName(FilePath) Returns the file name from a file path
ex.
sFileName=GetFileName("C:\Temp\Test.txt") 'sFileName has been set to text.txt
GetLastWriteTime(FilePath) Returns date time file was last modified
ex.
f=GetLastWriteTime("C:\Test.txt") ''f will be date and time C:\Test.txt was last modifed

String Functions

Function Description
InStr([start,]string1,string2) The InStr function returns the position of the first occurrence of one string within another. ex
i = InStr(" Test ","Test") 'i=2
InStrRev(string1,string2,[start]) Returns the position of the first occurrence of one string within another. The search begins at the last character of the string. ex
i = InStrRev(" Test ","Test") 'i=2
LCase(String) Converts a specified string to lowercase. ex
s = LCase("Test") 's=test
Left(String,Length) The Left function returns a specified number of characters from the left side of a string. ex
s = Left("Test",2) 's=Te
Len(String) Returns the length of a string. ex
s = Len(" Test ") 's=6
LTrim(String) Removes spaces on the left side of a string. ex
s = LTrim(" Test ") 's="Test  "
RTrim(String) Removes spaces on the right side of a string. ex
s = RTrim(" Test ") 's="  Test"
Mid(String,Start,[Length]) The Mid function returns a specified number of characters from a string. ex
s = Mid(" Test ",2,4) 's=Test
Trim(String) Returns a string with white space removed from ends. ex
s = Trim(" Test ") 's="Test"
Replace(String,Find,Replace) Returns a new string in which all occurrences of a specified String in the current string are replaced with another specified String. ex
s = replace("Test %u%","%u%","Bob") 's = Test Bob
Right(String,Length) The Right function returns a specified number of characters from the right side of a string. ex
s = Left("Test",2) 's=st
Space(Number) The Space function returns a string that consists of a specified number of spaces. ex
s = Space(4) 's="    "
StrReverse(String) Reverses a string. ex
s = Len("Test") 's=tseT
UCase(String) Converts a specified string to uppercase. ex
s = Len("Test") 's=TEST

Input Functions

Input Function Description
AcceptChanges(InputName) Commits all changes on input without saving them to the database.
AddNewRow(InputName,[SelectFirstControl]) Adds a new row to an input. SelectFirstControl is defaulted to True if not set. It controls where or not to select a control for user entry after the row has been added.
ex. AddNewRow(“Input1”) or AddNewRow(“Input1”, False)
BuildRowFilter(InputName,LocalCol,RemoteCol,CheckCol)
ClickButton(ButtonName) Preforms a click on a button.
ex. ClickButton(“btnSave”)
ClickInputButton(InputName,ButtonName) Preforms a click on a button inside a sub input. Useful for changing context of a script
ex. ClickInputButton(“Input1”,“btnReset”)
CloseDlg(State) When input is in dialog mode closes it and returns the state to the parent control.
ex.
CloseDlg(true) 'Return true to parent control.
Debug(Message) Writes a message out to the debug window during design.
ex. Debug(“Message Out”)
EvaluateOn(InputName,Statment)
sReturnValue = EvaluateOn("Input1", "Value1") 
EvaluateOnWithFilter(InputName,Filter,Statment)
sReturnValue = EvaluateOnWithFilter("Input1", "Description = 'test'", "Value1")
ExecuteScalar(SQL) Returns a the first column / row from a sql query.
ex. iCount = ExecuteScalar(“SELECT 1,2”) 'Would set iCount=1
Invalidate() Forces the control to redraw
RefreshFilterList(FilterList,SelectLast) Reloads values in a filter list and inputs attached to list. Select last determains if the filter list selects the last row or the first.
RequiresSave(InputName) Returns true if sub has changes that require saving.
ex. IF RequireSave(“Input1”) THEN : RETURN : END IF
ResetRow(InputName) Hides controls and adds new rows to dataset if need on input sent in.
RunDGSFunction(StationID,Function,Shiftnum,Runnum,Message)
SaveInput(InputName) Runs insert and update commands on input if required.
ex. SaveInput(“Input1”)
ShowReport(ReportID,Param2,[SendTables])
SetInputFilter(InputName,Filter) Does NOT filter the list using a variable, filters the input like a filterlist using the {2} parameter. If you want to filter the list with a variable set property inputScreenName.RowFilter
SetInputValue(InputName,ItemName,Value,[Filter])
SetInputValue("Input1", "Description = ""test""", "Value1", "1=1")

Setting [Filter] to “1=1” changes all. No filter changes selected row.

Sub Input Functions Description
AcceptChanges() Commits all changes without saving them to the database.
AddNewRow([SelectFirstControl]) Adds new row to input screen. Select First Control is a boolean that if set true will select the first editable field after the row as been added for user input, default is true.
ex. AddNewRow() or AddNewRow(False)
DeleteRow() Deletes the current selected row on input. If none is selected does nothing.
DeleteRows(Filter) Deletes rows based on filter. Returns count of rows deleted
ClickButton(ButtonName) Preforms a click on a button.
ex. ClickButton(“btnSave”)
ClickParentButton(ButtonName) Preforms a click on a button on the parent control.
ex. ClickButton(“btnSave”)
Debug(Message) Writes a message out to the debug window during design.
ex. Debug(“Message Out”)
EditImage(Image) Pops up a window for basic markup of an image. Returns edited image or unedit image if cancel was pressed
ex. img = EditImage(img)
EvaluateOnParent(Statment) Can grab a value from a parent control with in script.
ex. iMode=EvaluateOnParent(“iMode”) 'Brings the varable iMode into scope
Invalidate() Forces the control to redraw
MultiList(Column,Delimiter) Pops up a window to create a list with out the user having to enter a delimiter. Uses drop down list setup on column
sTemp = MultiList(Col1,";")
IF sTemp <> Col1 THEN
  Col1 = sTemp
END IF
ResetRow() Hides controls and adds new rows to dataset if needed.
Reload() Reloads the input any unsaved changes will be lost.
SelectRow(RowNum) Will select the specified row in the subinput based on the passed in parameter RowNum. First row is RowNum 0.
SetAll(ItemName,Value) Sets all values of a column in an sub inputs data table to a single value.
ex. SetAll(“ID”,2) 'Sets all of the column ID to the value of 2. Doesn't seem to work anymore… can use Parent SetInputValue with a filter of “1=1” for same result
SetControl(FieldName) Sets a controls focus for user entry on the current selected row.
ex. SetControl(“DTEvent”) 'Sets the field DTEvent for editing.
SetInputValue(InputName,ItemName,Value)
SetShiftRange(P0,P1) Sets the shift range on a input when shift selector set to Manual.
P0=0
P1=0
 
input1.SetShiftRange(P0,P1)

Input Properties

Sub Input Property Description
RowChanged Indicates that the row has changed. Useful when adding multiple new rows via scripting so it goes to a new row instead of overwriting an old row
RowCount Returns the current number of rows in the subinput
IsRowSelected Determines if there is a row selected in the subinput or not. Returns True or False. EX. inpTest.IsRowSelected
Username Returns the currently logged in username

View Functions

View Functions Description
ClickButton(ButtonName) Preforms a click on a button. ex. ClickButton(“btnSave”)
CreateStarGauge() Add later
ExecuteScalar(SQL) Returns a the first column / row from a sql query.
ex. iCount = ExecuteScalar(“SELECT 1,2”) 'Would set iCount=1
SaveViewImage(FileOutPath) Saves a screen shot of the current view as jpg. returns true on success and false on failure
ex. SaveViewImage(“C:\Temp\Screen.jpg”)
SetRefreshRate(Milliseconds) Overrides the user set refresh rate allowing for faster updates. Use with caution
ex.
SetRefreshRate(1000) 'View will attempt to update every second now
SetScrollerVisible(Visible) Show/hide real time ticker at bottom of view
ex.
SetScrollerVisible(False) 'Hides Scroller
SetScrollerVisible(True) 'Shows Scroller
SetToolbarVisible(Visible) Show/hide toolbar
ex.
SetToolbarVisible(False) 'Hides toolbar
SetToolbarVisible(True) 'Shows toolbar

Important Notes on Inputs

  • When using variables in user functions, variables declared within functions are GLOBAL. You will get very strange results if you use the same variable name in two different functions, try not to do this.
  • If a dropdown field is blank, Evaluate on will return NULL if it is an integer, but not if it is a string. If it is a string it will return the empty string “”.
  • When you pass a parameter into a function this parameter seems to be constant. If you try to change it by incrementing it, it will just remain the same number. You can get around this by assigning the parameter to a new variable and using that instead.
  • You cannot use 0 and 1 for booleans, you must use true and false
  • If you are using subinput links on a column that is auto-incrementing (identity column) it will not work unless you take that column and do +0 (example: KPI_ID should be selected out like SELECT KPI_ID + 0 KPI_ID)

DGS.net VW Script Functions

DGS.Net Functions Description
AddCommandFromDB(Command #,TimeOut,[New Cmd #]) Loads a command from station base on command number
Bail([Msg]) Will cause current command group to stop after script has completed
CreateCommand(Command #, CommandType, TimeOut) Creates empty command at end of current command group
Delay(Milliseconds) Suspends the current thread for a specified time
DeleteCommand(Command #) Removed a command by command number from command group
DisableEventLog() Turns off the event log write for current command group. This was added to allow keeping high frequency events out of the event log.
ex.
DisableEventLog() 'Current function group will not be saved to aManager_EventLog
ExecuteScalar(SQL) Returns a the first column / row from a sql query.
ex.
iCount = ExecuteScalar("SELECT 1,2") 'Would set iCount=1
GetCommandParameter(Command #, Parameter, [Default]) Will retrieve parameter from command of current command group
MsgOut(Msg,[OK/Warning/Error]) Outputs a message to DGS.net station Log
ReadPLC(Model,VWPLCAddress) Returns the first value from a PLC Address.
ex.
iVal = ReadPLC("PLC5","VW;;[192.168.1.2]N17:100") 'Would set iVal=value in N17:100
SetCommandParameter(Command #, Parameter, Value) Set Command Parameter for command in current command group

DGS TV VW Script Functions

DGS.Net Functions Description
ExecuteScalar(SQL) Returns a the first column / row from a sql query.
ex.
iCount = ExecuteScalar("SELECT 1,2") 'Would set iCount=1
ReadPLC(Model,VWPLCAddress) Returns the first value from a PLC Address.
ex.
iVal = ReadPLC("PLC5","VW;;[192.168.1.2]N17:100") 'Would set iVal=value in N17:100

VW Packager

VW Packager Functions Description
AddTable(Table,[CopyData],[BackupTableOut]) Creates / Updates table based on table definition in package.
CopyData will attempt to transfer data if table already exists is set to true by default.
BackupTableOut will set a the variable passed into it to the name of the backup table created if one was required.
Returns False if fails
ex.
rv = AddTable(tbl_Test,False,sBackup_tbl_Test) 'Will create table if table exists will not transfer data and will set the 
                                               'variable sBackup_tbl_Test to name of backup table if table recreated
if rv=false then 'Bail from script if failed to create table
  return false
end if
CreateInput(Input, InputName, [InputID]) Adds / Updates input in database returns InputID. ex.
IF IsUpdate THEN 'Run update flag set when updating
  iInputID = CreateInput(inpTest,"Test Input",iInputID) 'Save ID in case it changes for future updates
ELSE
  iInputID = CreateInput(inpTest,"Test Input") 'Save ID of input for update
END IF
CreateReport(Report, ReportName, ScheduleID, [ReportID]) Adds / Updates report in database returns ReportID. ex.
IF IsUpdate THEN 'Run update flag set when updating
  iReportID = CreateReport(rptTest,"Test Report",0,iReportID) 'Save ID in case it changes for future updates
ELSE
  iReportID = CreateReport(rptTest,"Test Report",0) 'Save ID of report for update
END IF
CreateView(View, ViewName, [ViewID]) Adds / Updates view in database returns ViewID. ex.
IF IsUpdate THEN 'Run update flag set when updating
  iViewID = CreateView(vwTest,"Test View",iViewID) 'Save ID in case it changes for future updates
ELSE
  iViewID = CreateView(vwTest,"Test View") 'Save ID of view for update
END IF
ExecuteScalar(SQL) Returns the first column / row from a sql query. ex.
iCount = ExecuteScalar("SELECT 1,2") 'Would set iCount=1 
MsgOut(Message) Outputs a message to the install log. Returns true on success. ex.
MsgOut("Message to user") 
RemoveTable(Table) Removes a table based on table definition in package. Only checks if the table names matched to be used on an uninstall. Returns true on success
ex.
rv = RemoveTable(tbl_Test) 'Will drop table if exists in the database
RemoveInput(InputID) Removes a input based on Input ID. Use return value from CreateInput used during install. Returns true on success
ex.
rv = RemoveInput(iInputID) 'Will remove input if exists in the database
RemoveReport(ReportID) Removes a report based on ReportID. Use return value from CreateReport used during install. Returns true on success
ex.
rv = RemoveReport(iReportID) 'Will remove report if exists in the database
RemoveView(ViewID) Removes a view based on ViewID. Use return value from CreateView used during install. Returns true on success
ex.
rv = RemoveView(iViewID) 'Will remove View if exists in the database
ReportFieldPropertyUpdate(ReportID,FieldName,Property,Value) Updates a property value on a report. Returns true on success
ex.
iRptID = CreateReport(rptTest,"Test Report",0)
rv = ReportFieldPropertyUpdate(iRptID,"Label1","BackColor",RGB(100,100,200)) 'Updates Label1 BackColor on report
ShowInputDlg(Input, Width, Height, InputHandle) Pops up an input as a dialog for entering data. Returns true on success
ex.
IF ShowInputDlg(inpDLG,400,400, OutData) THEN
  Msgbox(OutData.inpMain.ID) 'Will display a message box with the contents of ID from the input on the input form inpDLG
END IF
ViewFieldTagUpdate(ViewID,FieldName,Tag,Value) Updates a Tag value on a view. Can be used to update buttons on views. Returns true on success
ex.
iViewID = CreateView(vwTest,"Test View")
iRptID = CreateReport(rptTest,"Test Report",0)
rv = ViewFieldTagUpdate(iViewID,"btnTestReport","btnReport",iRptID) 'Updates view with new report ID

[] Parameters in square brackets are optional

 
vw_scripting.txt · Last modified: 2018/04/03 13:03 by darryll