Debugging Functions YouTube Tutorial
Table of Contents

Project Informations VB-Action scripts
The records you place in the Project Information region will not be supplanted naturally, which implies you can have all drives referring to a particular adaptation of an archive. It additionally implies you should check consistently to ensure the archives are as yet current.
ย Project Information
Sub OnClick(ByVal Item)ย ย
Dim Infos
Dim DSN
Set DSN = HMIRuntime.Tags(โ@DatasourceNameRTโ)
DSN.Read
Infos = โProjectname: โ & HMIRuntime.ActiveProject.Name & vbCrLf & _
โProject Pfad: โ & HMIRuntime.ActiveProject.Path & vbCrLf & _
โProject DSN: โ & DSN.Valueย
Dim TextFeld
Set TextFeld = ScreenItems(โStatischerText5โ)
TextFeld.Text = Infos
Set DSN = Nothing
End Sub
Color Change HMI Objects in picture window VB-Action script
ย Color HMI Objects in the picture window
Sub OnClick(ByVal Item)ย ย ย ย ย ย ย ย ย ย ย ย
Dim PictureInWindow
Dim HMIObjects
Set PictureInWindow = ScreenItems(โWindowโ).Screen.ScreenItems โ.ScreenItems โ.ScreenItems(โCircle1โ)
For Each HMIObjects In PictureInWindow
If HMIObjects.Backcolor = RGB(255,0,0) Then
HMIObjects.Backcolor = RGB(0,0,255)
Else
HMIObjects.Backcolor = RGB(255,0,0)
End if
Next
End Sub
Read Network Drives VB-Action scripts
Read Network Drives
Sub OnClick(ByVal Item)ย ย
Dim FileSyst, LW, LWListe, Ausgabe, Bezeichnung
Set FileSyst = CreateObject(โSCRIPTING.FILESYSTEMOBJECTโ)
Set LWListe = FileSyst.Drives
For Each LW In LWListe
If LW.DriveType = 3 Then โNetwork
Bezeichnung = LW.Sharename
Elseif LW.DriveType = 4 Then โCD-ROM
ย Bezeichnung = โCD-ROMโ
Else
On Error Resume Next
Bezeichnung = LW.VolumeName
End If
Ausgabe = Ausgabe & LW.DriveLetter & โ โ โ & Bezeichnung & Chr(13)
Bezeichnung = โโ
Next
MsgBox Ausgabe
End Sub
Date/Time VB-Action scripts
ย Adding Date/Timeย
Sub OnClick(ByVal Item)ย ย ย ย
Dim TagX, MonatX, JahrX, StundeX, MinuteX, SekundeX
Dim objOldTime
Dim objNewTime
Dim AktTime
Set objOldTime = ScreenItems(โOrginalDateโ)
Set objNewTime = ScreenItems(โNewDateโ)
Dim ZahlTage
Dim ZahlStunden
Dim ZahlMinuten
Set ZahlTage = ScreenItems(โeaTageโ)
Set ZahlStunden = ScreenItems(โeaStundenโ)
Set ZahlMinuten = ScreenItems(โeaMinutenโ)
TagX = Day(Now)
MonatX = Month(Now)
JahrX = Year(Now)
StundeX = Hour(Now)
MinuteX = Minute(Now)
SekundeX = Second(Now)
โMsgbox โTag: โ & TagX & vbcrlf & โMonat: โ & MonatX & vbcrlf & โJahr: โ & JahrX & vbcrlf & โStunde: โ & StundeX & vbcrlf & โMinute: โ & MinuteX & vbcrlf & โSekunde: โ & SekundeX
objOldTime.Text = Now
AktTime = Now
AktTime = DateAdd(โdโ,ZahlTage.InputValue,AktTime) โ Tag hinzuaddieren
AktTime = DateAdd(โhโ,ZahlStunden.InputValue,AktTime) โ Stunden hinzuaddieren
AktTime = DateAdd(โnโ,ZahlMinuten.InputValue,AktTime) โ Minuten hinzuaddieren
objNewTime.Text = โ Neue Zeit : โ & AktTime
โMsgBox โOrginal Zeit: โ & Now & vbcrlf & โ Neue Zeit : โ & AktTime
End Sub
Change date toย SQL format
Sub OnClick(ByVal Item)ย ย ย ย ย
Dim TagX, MonatX, JahrX, StundeX, MinuteX, SekundeX
Dim objOldTime
Dim objNewTime
Dim AktTime
Set objOldTime = ScreenItems(โOrginalDateโ)
Set objNewTime = ScreenItems(โNewDateโ)
Dim ZahlTage
Dim ZahlStunden
Dim ZahlMinuten
Set ZahlTage = ScreenItems(โeaTageโ)
Set ZahlStunden = ScreenItems(โeaStundenโ)
Set ZahlMinuten = ScreenItems(โeaMinutenโ)
TagX = Day(Now)
MonatX = Month(Now)
JahrX = Year(Now)
StundeX = Hour(Now)
MinuteX = Minute(Now)
SekundeX = Second(Now)
โMsgbox โTag: โ & TagX & vbcrlf & โMonat: โ & MonatX & vbcrlf & โJahr: โ & JahrX & vbcrlf & โStunde: โ & StundeX & vbcrlf & โMinute: โ & MinuteX & vbcrlf & โSekunde: โ & SekundeX
objOldTime.Text = Now
AktTime = Now
AktTime = DateAdd(โdโ,ZahlTage.InputValue,AktTime) โ Tag hinzuaddieren
AktTime = DateAdd(โhโ,ZahlStunden.InputValue,AktTime) โ Stunden hinzuaddieren
AktTime = DateAdd(โnโ,ZahlMinuten.InputValue,AktTime) โ Minuten hinzuaddieren
objNewTime.Text = โ Neue Zeit : โ & AktTime
โMsgBox โOrginal Zeit: โ & Now & vbcrlf & โ Neue Zeit : โ & AktTime
Dim TimeSelectionStart,TimeSelectionEnd
TimeSelectionStart = Year(Now) & โ-โ & Month(Now) & โ-โ & Day(Now) & โ โ & _
Hour(Now) & โ:โ & Minute(Now) & โ:โ & Second(Now)
TimeSelectionEnd =ย Year(AktTime) & โ-โ & Month(AktTime) & โ-โ & Day(AktTime) & โ โ & _
Hour(AktTime) & โ:โ & Minute(AktTime) & โ:โ & Second(AktTime)
Dim SQLStart,SQLEnd
Set SQLStart = ScreenItems(โSQLStartโ)
Set SQLEnd = ScreenItems(โSQLEndโ)
SQLStart.Text = TimeSelectionStart
SQLEnd.Text = TimeSelectionEnd
End Sub
Set Date VB-Action scripts
Set Date
Sub OnLButtonDown(ByVal Item, ByVal Flags, ByVal x, ByVal y)ย
Dim DatumText
Set DatumText = ScreenItems(โDatumโ)
DatumText.Text = InputBox(โInsert Dateโ)
Set DatumText = Nothing
End Sub
Change Button Color VB-Action scripts
ย Change Button Color
Sub OnLButtonDown(Byval Item, Byval Flags, Byval x, Byval y)ย ย ย ย ย ย ย
Dim objButton
Set objButton = ScreenItems(โWindowโ).Screen.ScreenItems(โButton1โ)
If objButton.Backcolor = RGB(255,0,0) Then
objButton.Backcolor = RGB(0,255,255)
Else
objButton.Backcolor = RGB(255,0,0)
End If
Set objButton = Nothing
End Sub
Read Archives VB-Action scripts
From the start WinCC Archive 7.4 SP1 supportsย string type variables. Weโre also using an interface that provides a query string variable archive. But so far as of the TIA Portal V15.1, TIA WinCC Professional does not support archive string type variables.ย
Read Archives
Sub OnLButtonDown(ByVal Item, ByVal Flags, ByVal x, ByVal y)ย ย
Dim objConnection
Dim strConnectionString
Dim lngValue
Dim strSQL
Dim objCommand
Dim DataSource
Dim Archive
Set Archive = ScreenItems(โArchiveโ)
Archive.Text = โโ
Dim DSN_Name
Set DSN_Name = HMIRuntime.Tags(โ@DatasourceNameRTโ)
DataSource = DSN_Name.Read
HMIRuntime.Trace โDSN Name : โ & DataSource & vbCrLf
strConnectionString = โProvider=MSDASQL.1;PersistSecurityInfo=False; Data Source=โ &DataSource&โ;โย
HMIRuntime.Trace โstrConnectionString: โ & strConnectionString & vbCrLf
โAuswahl des Archives
strSQL = โArchiveโ
โAuswahl der Tabelle
Set objConnection = CreateObject(โADODB.Connectionโ)
objConnection.ConnectionString = strConnectionString
objConnection.Open
โVerbindung zur Datenbank
Set objCommand = CreateObject(โADODB.Commandโ)
objCommand.CommandType = 2
โIm OCX der Type der Tabelle ist 2
With objCommand
ย ย .ActiveConnection = objConnection
ย ย .CommandText = strSQL
โCommandtext ist der Name der Tabelle
End With
โVerbindung herstellen
Dim oRs
Set oRs = objCommand.Execute
โoRs ist der Rรผckgabewert der Tabelle
Do While Not oRs.eof
โeof bedeutet End of File
Archive.Text = Archive.Text & oRs.Fields(โValuenameโ).value & vbCrLf
โAuswahl der Spalte in der Tabelle die in das Textfenster geschrieben werden sollen
oRs.movenext
โร sonst wรผrde es eine Endlosschleife (movenext bedeutet geh zur nรคchsten Zeile )
Loop
oRs.close
Set oRs=Nothing
Set Archive = Nothing
โ oRs wird auf null gesetzt
Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing
โSchlieรen der Verbindung
End Sub
File Transfer info VB-Action scripts
The application example shows a reverse osmosis plant. The plant has a motor and several valves to control the flows within the plant. The mapping of the analog measuring points, the states of valves and motors, as well as the states of the system, is carried out via VB script. The procedures for the state and analog measurement loop simulation are called via triggered actions. Thus a complete simulation of the reverse osmosis plant is guaranteed. The values of the analog measuring points are stored via a process value archive and the status messages via anย alarm archive can be File Transfer.
File Transfer
Sub OnClick(ByVal Item)ย ย
Dim FileSyst
Dim Datei
Const PFAD = โC:Test.txtโ
Set FileSyst = CreateObject(โSCRIPTING.FILESYSTEMOBJECTโ)
Set Datei = FileSyst.OpenTextFile( PFAD, 2, True, False)
Datei.WriteLine(โFirst Line insertedโฆ.โ)
Datei.WriteLine(โHier kรถnnen viele Zeilen stehenโ)
Datei.WriteLine(โLast Line insertedโฆ.โ)
โMsgBox Datei.ShortName
Datei.Close
MsgBox โ Die Datei: -โ & PFAD & โ- wurde erstelltโ
โSet datei = FileSyst.GetFile(PFAD)
End Sub
Read RegKey VB-Action scripts
ย Read RegKey
Sub OnClick(ByVal Item)ย
Const REGPATH = โHKLMSoftwareSiemensWinCCSetupBuildNrโ
Dim Shell
Dim Build
Set Shell = CreateObject(โWSCRIPT.SHELLโ)
Build = Shell.RegRead(REGPATH)
MsgBox Build
End Sub
Theย GetValue
ย method of theย My.Computer.Registry
ย object can be used to read values in the Windows registry.
If the key, โSoftwareMyAppโ in the following example, does not exist, an exception is thrown. If theย ValueName
, โNameโ in the following example, does not exist,ย Nothing
ย is returned.
Theย GetValue
ย the method can also be used to determine whether a given value exists in a specific registry key.
When code reads the registry from a Web application, the current user is determined by the authentication and impersonation that is implemented in the Web application.
Network Config VB-Action scripts
Below script is for network path and network drives.
Network Config
Sub OnClick(ByVal Item)ย
Dim NW
Set NW = CreateObject(โWSCRIPT.NETWORKโ)
MsgBox NW.UserDomain
MsgBox nw.ComputerNameย
MsgBox nw.UserNameย
End Sub
Open File Dialog VB-Action scripts

Utilization of shell VBS object โ > I call DOS orders and catch the shell yield into a book record which I then, at that point read into List Objects on the HMI screen.ย
utilization of File System Object โ > fso objects give numerous techniques and properties that can be utilized similarlyย
It doesnโt look extravagant and it has a few disadvantages, for example, to enter a subdirectory, I utilize a pushbutton to call fitting content, while it would be more pleasant if the client would enter an index with double tap on chosen list thing (basic Click occasion on the List box object works defective when there is a parchment bar showed close to the rundown).
Open File Dialog
Sub OnClick(Byval Item)ย ย
โACHTUNG Code funktioniert nur wenn Lizenz von Microsoft da ist
โ z.b. Visual Studio 6
dim dlgCommonDialog
set dlgCommonDialog = CreateObject(โMSComDlg.CommonDialogโ)
On Error Resume Next
ย ย ย ย dlgCommonDialog.CancelError = True
ย ย ย ย dlgCommonDialog.DialogTitle = โEine Datei auswรคhlenโ
ย ย ย ย dlgCommonDialog.Filter =โAlle Dateien(*.*) | *.*โ
ย ย ย ย dlgCommonDialog.MaxFileSize = 255
ย ย ย ย dlgCommonDialog.ShowOpen
ย If .Filename <> โโ then
ย Dim objTextanzeige
ย Set objTextanzeige = ScreenItems(โPfadTextโ)
ย objTextanzeige.Text = dlgCommonDialog.Filename
ย Else
ย MsgBox โKeine Datei angewรคhltโ, vbinformation
ย End if
set dlgCommonDialog=nothing
End Sub
Windows Color Dialog VB-Action scripts
Display a modular exchange box that permits the client to pick particular shading esteem. The client can pick a shading from either a bunch of essential or custom shading ranges. On the other hand, the client can produce shading esteem by changing the RGB or tone, immersion, radiance (HSL) shading upsides of the discourse box UI. The Color exchange box returns the RGB worth of the shading chosen by the client.ย
ย Windows Color Dialog
Sub OnClick(ByVal Item)ย ย
dim dlgCommonDialog
set dlgCommonDialog = createobject(โMSComDlg.CommonDialogโ)
dlgCommonDialog.ShowColor
Dim objButton
Set objButton = ScreenItems(โButton1โ)
objButton.BackColor = dlgCommonDialog.Color
โmsgbox โDez: โ & cstr(dlgCommonDialog.Color) & vbCR & _
โย ย ย ย โHex: โ & hex(dlgCommonDialog.Color)
Set objButton = Nothing
set dlgCommonDialog=nothing
End Sub
Read Path VB-Action scripts
Read Path
Sub OnClick(ByVal Item)ย
Dim objShell
Dim objEnv
Dim varPath
Set objShell = CreateObject(โWSCRIPT.SHELLโ)
Set objEnv = objShell.Environment(โPROCESSโ)
varPath = objEnv(โPATHโ)
MsgBox varPath
End Sub
NB Designer OMRON HMI Youtube Tutorial Videos
DOPSOFT DELTA HMI Youtube Tutorial Videos
Wonderware Intouch Youtube Tutorial Videos
GT Designer MITSUBISHI HMI Youtube Tutorial Videos
WinCC Siemens HMI Youtube Tutorial Videos
FACTORY TALK VIEW Youtube Tutorial Videos