Press ESC to close · Ctrl+K to open

VBScript Library WinCC

VBScript Library WinCC

I am creating an external library in C# to extend the options of WinCC and use them in VBScript, others simply to facilitate the source code work. Currently, all the available ones can be used in both WinCC / WinCC RT Professional (TIA Portal).

If you are interested, you can download the library from the Siemens Forum, where I will be updating the different versions.

https://support.industry.siemens.com/tf/ww/en/posts/library-vb-net-c-com-vbscript-wincc/187312/?page=0&pageSize=10

 

string :GetUserGroup (string DataSourceRT, string CurrentUser)

Dim CurrentUser, DatasourceNameRT, Obj, return
Set CurrentUser = HMIRuntime.Tags("@CurrentUser")
Set DatasourceNameRT = HMIRuntime.Tags("@DatasourceNameRT")
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.GetUserGroup(DatasourceNameRT.Read, CurrentUser.Read)
HMIRuntime.Trace "User Group: " & return & vbNewline

 

string :GetUserGroupLogon(string DataSourceRT, string CurrentUser)

Dim CurrentUser, DatasourceNameRT, Obj, return
Set CurrentUser = HMIRuntime.Tags("@CurrentUser")
Set DatasourceNameRT = HMIRuntime.Tags("@DatasourceNameRT")
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.GetUserGroupLogon(DatasourceNameRT.Read, CurrentUser.Read)
HMIRuntime.Trace "User Group: " & return & vbNewline

 

string :GetMaxLimitTag (string DataSourceRT, string TagName)

Dim Obj, return, DatasourceNameRT
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
Set DatasourceNameRT = HMIRuntime.Tags("@DatasourceNameRT")
return = Obj.GetMaxLimitTag(DatasourceNameRT.Read, "TagName")
HMIRuntime.Trace "Max Limit: " & return & vbNewline

 

string :GetMinLimitTag (string DataSourceRT, string TagName)

Dim Obj, return, DatasourceNameRT
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
Set DatasourceNameRT = HMIRuntime.Tags("@DatasourceNameRT")
return = Obj.GetMinLimitTag(DatasourceNameRT.Read, "TagName")
HMIRuntime.Trace "Min Limit: " & return & vbNewline

 

string :GetDateTime() 'With Milliseconds

Dim Obj, return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.GetDateTime()
HMIRuntime.Trace "System Date: " & return & vbNewline

 

string :GetDateTimeFormat(string format) '(HH:mm:ss.fff) ; (MMMM dd, yyyy) ; (yyyyMMddHHmmss)

Dim Obj, return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.GetDateTimeFormat("HH:mm:ss.fff")
HMIRuntime.Trace "System Date: " & return & vbNewline

 

int :Sleep(int Milliseconds) 'Return 1 when the time is finished

Dim Obj, return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
HMIRuntime.Trace "System Date: " & Obj.GetDateTime() & vbNewline
Obj.Sleep(500)
HMIRuntime.Trace "System Date: " & Obj.GetDateTime() & vbNewline

 

int :GetRandon()' By default 0-100

Dim Obj, return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.GetRandon()
HMIRuntime.Trace "Random Number: " & return & vbNewline

 

int :GetRandonNumber(int MinNumber, int MaxNumber)

Dim Obj, return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.GetRandon(10,1000)
HMIRuntime.Trace "Random Number: " & return & vbNewline

 

float :GetRandonFloat(int MinNumber, int MaxNumber)

Dim Obj, return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.GetRandon(10,1000)
HMIRuntime.Trace "Random Number: " & return & vbNewline

 

int :StartProgram(string PathProgram, out string Message)

Dim Obj, msg
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.StartProgram("C:\\xxx\\MyExportFile.csv", msg)
If return = -1 Then
HMIRuntime.Trace msg & vbNewline
End If

 

int :CloseProgram(string Program, out string Message) 'Program = Name of the process

Dim Obj, msg
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.CloseProgram("firefox", msg)
If return = -1 Then
HMIRuntime.Trace msg & vbNewline
End If

 

void :Login()

Dim Obj
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
Obj.Login()

 

void :Logout()

Dim Obj
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
Obj.Logout()

 

void :SilentLogin(string login, string password)

Dim Obj
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
Obj.SilentLogin("User", "Passwords")

 

bool :LoggedInByCard()

Dim Obj, ret
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
ret = Obj.LoggedInByCard()

 

void :GetCursorPosition(out int x, out int y)

Dim Obj, x, y
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
Obj.GetCursorPosition x, y
HMIRuntime.Trace "X: " & x & vbNewline
HMIRuntime.Trace "Y: " & y & vbNewline

 

void : NormalWinCC()

Dim Obj
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
Obj.NormalWinCC()

 

void : MinimizeWinCC()

Dim Obj
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
Obj.MinimizeWinCC()

 

void : MaximizeWinCC()

Dim Obj
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
Obj.MaximizeWinCC()

 

Thanks to WkHtmlToPdf, I have created this function that serves to convert an online web page to pdf or an html file to pdf. If you want to try it, you need to install WkHtmlToPdf. You can download it from https://wkhtmltopdf.org/downloads.html

int PrintHtmlToPdf(String Source, String Path, String msg)

Dim Obj, msg, ret
item.Enabled = False
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
HMIRuntime.Trace "Start: " & Obj.GetDateTime() & vbNewline
ret = Obj.PrintHtmlToPdf("https://wkhtmltopdf.org", "C:\\PDF\\wkhtmltopdf.pdf", msg)
If ret = -1 Then
HMIRuntime.Trace "Error: " & msg & vbNewline
End If
HMIRuntime.Trace "Finished: " & Obj.GetDateTime() & vbNewline
item.Enabled = True

 

Dim Obj, msg, ret
item.Enabled = False
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
HMIRuntime.Trace "Start: " & Obj.GetDateTime() & vbNewline
ret = Obj.PrintHtmlToPdf("file:///C:/PDF/wkhtmltopdf.htm", "C:\\PDF\\wkhtmltopdf2.pdf", msg)
If ret = -1 Then
HMIRuntime.Trace "Error: " & msg & vbNewline
End If
HMIRuntime.Trace "Finished: " & Obj.GetDateTime() & vbNewline
item.Enabled = True

 

Thanks to HtmlRenderer.PdfSharp, I have created this function, which serves to create a pdf file from html code. Here you do not need to install anything, the library with its dependencies is already attached in the compiled version.

int GeneratePdf(String Source, String Path, String msg)

Dim Obj, pdf, msg, ret
item.Enabled = False
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
HMIRuntime.Trace "Start: " & Obj.GetDateTime() & vbNewline

pdf = " <html> " _
& "<body>" _
& "<h1>My First Heading</h1>" _
& "<p>My first paragraph.</p>" _
& "<p><h1>Hello World</h1>This is html rendered text</p>" _
& " <table width:100%"">" _
& "  <tr>" _
& "   <th>Firstname</th>" _
& "    <th>Lastname</th>" _
& "    <th>Age</th>" _
& "  </tr>" _
& "  <tr>" _
& "    <td>Jill</td>" _
& "    <td>Smith</td>" _
& "    <td>50</td>" _
& "  </tr>" _
& "  <tr>" _
& "    <td>Eve</td>" _
& "    <td>Jackson</td>" _
& "    <td>94</td>" _
& "  </tr>" _
& "</table> " _
& "</body>" _
& "</html> "

ret = Obj.GeneratePdf(pdf, "C:\\PDF\\CodeHTML2PDF.pdf", msg)
If ret = -1 Then
HMIRuntime.Trace "Error: " & msg & vbNewline
End If
HMIRuntime.Trace "Finished: " & Obj.GetDateTime() & vbNewline
item.Enabled = True

 

 

Dim Obj, pdf, msg, ret
item.Enabled = False
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
HMIRuntime.Trace "Start: " & Obj.GetDateTime() & vbNewline

pdf = "<head><style>.test { background-color: linen;color: maroon;}</style></head>" _
& " <body Class=""test""><p><h1>Hello PLC HMI SCADAS</h1>This is html generated with HtmlRenderer.PdfSharp and rendered text with css and image.</p>" _
& " <p><img src=""/images/header1280.gif"" height=""100%"" width=""100%""></p>" _
& " </body>"

ret = Obj.GeneratePdf(pdf, "C:\\PDF\\CodeHTML2PDF_2.pdf", msg)
If ret = -1 Then
HMIRuntime.Trace "Error: " & msg & vbNewline
End If
HMIRuntime.Trace "Finished: " & Obj.GetDateTime() & vbNewline
item.Enabled = True

 

Update, if you download the latest version 26-07-2018, the following functions have been updated, where no arguments need to be passed to the following functions.

string :GetUserGroup ()
string :GetUserGroupLogon()
string :GetMaxLimitTag (string TagName)
string :GetMinLimitTag (string TagName)


string : GetRuntimeProject()

Dim Obj, ret
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
ret = Obj.GetRuntimeProject()

 

void : ShowTaskbar()

Dim Obj
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
Obj.ShowTaskbar()

 

void : HideTaskbar()

Dim Obj
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
Obj.HideTaskbar()

 

string :GetUserGroup ()

Dim Obj, return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.GetUserGroup()
HMIRuntime.Trace "User Group: " & return & vbNewline

 

string :GetUserGroupLogon()

Dim Obj, return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.GetUserGroupLogon()
HMIRuntime.Trace "User Group: " & return & vbNewline

 

string :GetMaxLimitTag (string TagName)

Dim Obj, return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.GetMaxLimitTag("TagName")
HMIRuntime.Trace "Max Limit: " & return & vbNewline

 

string :GetMinLimitTag (string TagName)

Dim Obj, return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.GetMinLimitTag("TagName")
HMIRuntime.Trace "Min Limit: " & return & vbNewline

 

int :PrintReport (string JobName)

Dim Obj, return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.PrintReport(JobName)

 

int :PreviewReport (string JobName)

Dim Obj, return
Set Obj = CreateObject("VBScriptLibraryWinCC.dll")
return = Obj.PreviewReport(JobName)

 

March 8, 2017

"Gratitude in silence serves no one." Gladys Bronwyn Stern