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