Professional Documents
Culture Documents
Cc lnh trong VB
1. HMIRuntime Object
Description
The HMIRuntime object represents the graphic runtime environment.
sage
The !HMIRuntime! object can be use" #or the #ollo$ing% #or e&le'
Rea" or set the current Runtime language (!)anguage! propert*+.
Rea" or set the name o# the current base picture (!Base,creen-ame! propert*+.
Rea" the path o# the active Runtime project (!.ctive/roject! propert*+.
.ccess tags (!Tags! propert*+.
.ccess tags o# a list (!Data,et! propert*+.
0&it runtime (!,top! metho"+.
Displa* messages in a "iagnostics $in"o$ (!Trace! metho"+.
0&le
The #ollo$ing comman" terminates 1inCC runtime'
2VB,3
HMIRuntime.,top
DataSet Object (List
Description
4
sing the Data,et object% "ata ma* be e&change" across several actions.
. Data,et object is global an" "e#ine" b* the ,creen object. .n* VB, action ma* access the
"ata.
The Data,et object at the ,creen object must be a""resse" accor"ing to picture hierarch* an"
shall persist as long as the picture is "ispla*e". The global object persists over the entire Runtime
time perio".
.ccess uses the DataItem object.
-ote'
5bjects o# t*pe ,creen% ,creens% ,creenItem% ,creenItems% Tag an" Tag,et cannot be inclu"e" in
the Data,et list.
The Data,et object "oes not support an* classes.
sage
sing the !Data,et! list% *ou ma*'
5utput or process (enumerate+ all objects in the list.
5utput the number o# elements containe" (!Count! propert*+.
/rocess a speci#ic object in the list (!Item! metho"+.
."" an object to the list (!.""! metho"+.
Remove a speci#ic object #rom the list (!Remove! metho"+.
Remove all objects #rom the list (!Remove.ll! metho"+.
.ccess to list elements uses'
HMIRuntime.Data,et(!Itemname!+
6or a picture7speci#ic list% access uses'
HMIRuntime.,creens(!,creenname!+.Data,et(!Itemname!+
In a picture% *ou ma* access the Data,et object o# the picture b* using'
Data,et(!Itemname!+
I# upon access the state" name "oes not e&ist in the list% VT80mpt* is returne" an" an 0&ception
is triggere".
0&le
The e&le sho$s ho$ to a"" a value to the list% ho$ to rea" it an" remove it. It ma9e sense to
per#orm this in several "i##erent actions.
:
!VBS1"#
HMIRuntime.DataSet.$%% &m't'(1&) #*
HMIRuntime.T(ace &m't'(1+ & , HMIRuntime.DataSet(&m't'(1&.Va-ue , .bNe/Line
HMIRuntime.DataSet.Rem'.e(&m't'(1&
The DataItem object is use" to access the contents o# the Data,et list. Values or object re#erences
are store" in the list as DataItem.
.ccess uses the name un"er $hich the value $as a""e" to the list. ,ingle access using an in"e& is
not recommen"e" since the in"e& changes "uring a""ing or "eleting o# values. The in"e& ma* be
use" to output the complete contents o# the list. The output is in alphabetical or"er.
-ote'
6or object re#erences it must be ascertaine" that objects are multirea"7enable".
0&le
The e&le sho$s ho$ the value o# 2Motor42 is output as Trace.
2VB,4;3
HMIRuntime.Trace !motor4' ! < HMIRuntime.Data,et(!motor4!+.Value < vb-e$)ine
The #ollo$ing e&le enumerates all DataItem objects o# the Data,et list. -ame an" value are
output as Trace.
2VB,4;=
Dim "ata
6or 0ach "ata In HMIRuntime.Data,et
HMIRuntime.Trace "ata.-ame < !' ! < "ata.Value < vb-e$)ine
-e&t
-ote'
6or objects% value ma* possibl* not be output "irectl*
$cti.eSc(een 0('1e(t2
Description
,upplies a re#erence to the picture $hich contains the object $ith the current #ocus.
sage
!.ctive,creen! is use" in Runtime to a""ress the properties o# the picture $hich contains the
currentl* #ocusse" object.
0&le
The #ollo$ing e&le assigns the name o# the current picture to the tag !str,cr-ame! an"
outputs it in a message'
2VB,;>
Dim str,cr-ame
str,cr-ame ? HMIRuntime..ctive,creen.5bjectname
MsgBo& str,cr-ame
3
BaseSc(eenName 0('1e(t2
6unction
De#ines or returns the current basic picture.
,TRI-@ ($rite7rea" access+
. picture change is e&ecute" using the
HMIRuntime.Base,creen-ame ? (A,erverprB#i&C''+A-eues @run"bil"C
comman".
1hen rea"ing out the !Base,creen-ame! propert*% onl* the picture name $ithout server pre#i& is
returne".
-ote'
.l$a*s enter picture names $ithout the e&tension !/D)! #or reasons o# compatibilit* $ith #uture
versions.
0&le
The #ollo$ing e&le e&ecutes a picture change to !bil"4.p"l!'
HMIRuntime.Base,creen-ame ? !bil"4!
Sc(eens 0('1e(t2
Description
Returns an object o# t*pe !,creens!.
,creens (rea" onl*+
0&le
The #ollo$ing e&le accesses the picture !-e$/D)4!'
2VB,>=
Dim obj,creen
,et obj,creen ? HMIRuntime.,creens(!-e$/D)4!+
Ta3s 0('1e(t2
Description
Returns an object o# t*pe !Tags!.
Tags (rea" onl*+
0&le
The #ollo$ing e&le accesses the tag !Tag4!'
0&le
The #ollo$ing e&le accesses the tag !Tag4!'
2VB,>;
Dim objTag
,et objTag ? HMIRuntime.Tags(!Tag4!+
=
Set 'Visib-e 0('1e(t2
Description
$itches an object visible or invisible or issues a correspon"ing value'
TR0' 5bject is visible
6.),0' 5bject is invisible
V.RI.-T8B55) ($rite7rea" access+
0&le
The #ollo$ing e&le sets all the objects in the picture !-e$/D)4! to invisible'
2VB,DE
Dim obj,creen
Dim obj,crItem
Dim lngIn"e&
Dim str-ame
lngIn"e& ? 4
,et obj,creen ? HMIRuntime.,creens(!-e$/D)4!+
6or lngIn"e& ? 4 To obj,creen.,creenItems.Count
str-ame ? obj,creen.,creenItems(lngIn"e&+.5bject-ame
,et obj,crItem ? obj,creen.,creenItems(str-ame+
obj,crItem.Visible ? 6alse
-e&t
E
M4T S5 B6I T70 M89 VB TRONG WINCC
0&le' .ccessing objects in @raphics Designer
Int('%ucti'n
.ccess can be ma"e to all @raphic Designer objects using VB, 1inCC in or"er to ma9e the
graphic runtime environment "*namic. @raphic objects can be ma"e "*namic on operation (e.g.
clic9ing the mouse on a button+% "epen"ing on a tag or c*clicall* (e.g. #lashing+.
The #ollo$ing e&les illustrate ho$ to change a graphic object #ollo$ing a mouse clic9.
0('ce%u(e
In the #ollo$ing e&le% the ra"ius o# a circle is set to :F in runtime per mouse clic9'
2VB,4:4
Dim objCircle
,et objCircle ? ,creenItems(!Circle4!+
objCircle.Ra"ius ? :F
-ote'
The e&pression use" in the e&le onl* applies to @raphics Designer. In the case o# analog
actions in @lobal ,cript% a""ress the objects using the HMIRuntime object.
0&le' De#ining the color o# objects
Int('%ucti'n
The colors o# graphic objects are "e#ine" via R@B values (Re"G@reenGBlue+. The color values #or
graphic objects can be set or rea" out.
0('ce%u(e
The #ollo$ing e&le "e#ines the #ill color #or !,creen1in"o$4! to blue'
2VB,4::
Dim obj,creen
;
,et obj,creen ? HMIRuntime.,creens(!,creen1in"o$4!+
obj,creen.6ill,t*le ? 434FHE
obj,creen.6illColor ? R@B(F% F% :EE+
0&le' Con#iguring language changes
Int('%ucti'n
The runtime language o# 1inCC can be change" using VB,. The most t*pical use is buttons $ith
the correspon"ing language co"es $hich are place" on the start page o# a project.
The runtime language is speci#ie" in VB, b* means o# a language co"e% e.g. 4F34 #or @erman 7
@erman*% 4F33 #or 0nglish 7 nite" ,tates etc. .n overvie$ o# all language co"es is provi"e" in
the principles o# VB,cript un"er the topic !)ocale ID ()CID+ Chart !.
0('ce%u(e
se the !Mouse clic9! event on a button to create a VB, action an" enter the #ollo$ing action
co"e to s$itch the runtime language to @erman'
2VB,4:3
HMIRuntime.)anguage ? 4F34
0&le' Deactivating runtime
Int('%ucti'n
It is possible to terminate 1inCC runtime $ith VB,% e.g. via a mouse clic9 or on tag values or
other events% such as multiple #ault* input o# a pass$or" $hen starting runtime.
/roce"ure
The #ollo$ing e&le terminates 1inCC runtime'
2VB,4:=
HMIRuntime.,top
H
0&le' Con#iguring change picture globall*
Int('%ucti'n
VB, can be use" to initiate a global picture change an" thus% #or e&le% "ispla* a picture #rom
a server on a client in a "istribute" s*stem. To "o this% server2s server pre#i& must prece"e the
target picture.
0('ce%u(e
Con#igure the #ollo$ing co"e #or a picture change to a button% #or e&le'
2VB,4:E
HMIRuntime.Base,creen-ame ? !,erverpre#i&''-e$ screen!
0&le' Con#iguring Change /icture Via /ropert*
Int('%ucti'n
I# partitione" pictures are use" in the con#iguration% e.g. in a basic picture title an" operating bar
#or the user inter#ace an" an embe""e" picture $in"o$ #or the actual picture "ispla*% con#igure a
picture change using the properties o# the picture $in"o$.
The propert* o# the !,creen-ame! picture $in"o$ must be change" in or"er #or the other picture
to appear. The action an" picture $in"o$ must be con#igure" in the same picture.
0('ce%u(e
In the #ollo$ing e&le% the !test.p"l! picture is "ispla*e" in the !,creen1in"o$! picture
$in"o$ $hen e&ecuting the action'
2VB,4:;
Dim obj,cr1in"o$
,et obj,cr1in"o$ ? ,creenItems(!,creen1in"o$!+
obj,cr1in"o$.,creen-ame ? !test!
>
0&le' Con#iguring "iagnostic output via Trace
Int('%ucti'n
I# a @,C "iagnostics $in"o$ has been inserte" in the picture% "iagnostic output can be "ispla*e"
in the "iagnostics $in"o$ in runtime using the Trace comman".
@,C Diagnostics issues the Trace metho"s containe" in the actions in the chronological seIuence
the* are calle". This also applies to Trace instructions in proce"ures $hich are calle" in actions.
The targete" implementation o# Trace instructions% e.g. #or the output o# tag values% enables the
progress o# actions an" the proce"ures calle" in them to be trace". The Trace instructions are
entere" in the #orm !HMIRuntime.Trace(AoutputC+!.
The @,C Diagnostics "ispla*s trace output #rom C an" VB,.
0('ce%u(e
The #ollo$ing e&le $rites a te&t in the "iagnostics $in"o$'
2VB,4:H
HMIRuntime.Trace !CustomiJe" error message!
0&le' 1riting tag values
Int('%ucti'n
sing VB,% it is possible to $rite a tag value to the /)C% e.g. b* clic9ing the mouse on a button
to speci#* setpoint values% or to set internal tag values to trigger other actions.
Various $rite variations are mentione" an" e&plaine" belo$.
Sim1-e /(itin3
In the #ollo$ing e&le% a value is $ritten to the !Tag4! tag'
2VB,4:>
HMIRuntime.Tags(!Tag4!+.1rite ;
This is the simplest #orm o# $riting since no object re#erence is generate".
1riting $ith object re#erence
In the #ollo$ing e&le% a local cop* o# the tag object is create" an" a value $ritten to !Tag4!'
D
2VB,4:D
Dim objTag
,et objTag ? HMIRuntime.Tags(!Tag4!+
objTag.1rite H
Re#erencing o##ers the a"vantage o# being able to $or9 $ith the tag object be#ore $riting. The tag
value can be rea"% calculations e&ecute" an" $ritten again'
2VB,43F
Dim objTag
,et objTag ? HMIRuntime.Tags(!Tag4!+
objTag.Rea"
objTag.Value ? objTag.Value K 4
objTag.1rite
S2nc:('n'us /(itin3
-ormall*% the value to be $ritten is trans#erre" to the tag management an" processing o# the
action resume". In some cases% ho$ever% it must be ensure" that the value has actuall* been
$ritten be#ore processing o# the action can be resume".
This t*pe o# $riting is realiJe" b* speci#*ing the value 4 #or the a""itional% optional parameters'
2VB,434
Dim objTag
,et objTag ? HMIRuntime.Tags(!Tag4!+
objTag.1rite >%4
or
2VB,43:
Dim objTag
,et objTag ? HMIRuntime.Tags(!Tag4!+
objTag.Value ? >
4F
objTag.1rite %4
N'te+
/lease note that the call ta9es longer in comparison to the stan"ar" call. The "uration is also
"epen"ent on the channel an" .,% amongst other things.
The t*pe o# $riting complies to the ,etTagLLL1ait(+ call in C scripting.
1riting $ith status han"ling
In or"er to ensure that a value has been $ritten success#ull*% it is necessar* to e&ecute an error
chec9 or "etermine the status o# the tag% a#ter the $riting process.
This is "one b* chec9ing the value o# the !)ast0rror! propert* a#ter $riting. 1hen the test proves
success#ul% i.e. the job has been place" success#ull*% the tag status is chec9e".
In the case o# a $rite job% the current status #rom the process is not "etermine". To establish this%
it is necessar* to rea" the tag. The value speci#ie" in the Mualit* Co"e propert* a#ter the rea"
process provi"es an in"ication o# the tag status an"% i# necessar*% ma9es re#erence to a #aile" .,
connection.
In the #ollo$ing e&le% the !Tag4! tag is $ritten. I# an error occurs "uring $riting% the error
value an" error "escription appear in the @lobal ,cript "iagnostics $in"o$. 6inall*% the Mualit*
Co"e is chec9e". I# the Mualit* Co"e is 5N (F&>F+% it is "ispla*e" in the "iagnostics $in"o$.
2VB,433
Dim objTag
,et objTag ? HMIRuntime.Tags(!Tag4!+
objTag.1rite D
I# F AC objTag.)ast0rror Then
HMIRuntime.Trace !0rror' ! < objTag.)ast0rror < vbCr)# < !0rrorDescription' ! <
objTag.0rrorDescription < vbCr)#
0lse
objTag.Rea"
I# <H>F AC objTag.Mualit*Co"e Then
HMIRuntime.Trace !Mualit*Co"e' F&! < He&(objTag.Mualit*Co"e+ < vbCr)#
0n" I#
44
0n" I#
N'te+
.#ter $riting a tag% the Mualit*Co"e propert* o# the local tag object #rom !B.D 5ut o# ,ervice!
is set because it is not 9no$n $hich Mualit* Co"e manages the tag in the process.
The Mualit* Co"e cannot be $ritten #rom VB,.
0&le' Ho$ to Rea" Tag Values
Int('%ucti'n
VB, can be use" to rea" an" #urther process a tag value. This ma9es it possible% #or e&le% to
clic9 the mouse on a button to obtain in#ormation on the s*stem status or to e&ecute a calculation.
Various rea" variations are mentione" an" e&plaine" belo$.
Sim1-e (ea%in3
In the #ollo$ing e&le% the value o# !Tag4! is rea" an" "ispla*e" in the @lobal ,cript
"iagnostics $in"o$'
2VB,43=
HMIRuntime.Trace !Value' ! < HMIRuntime.Tags(!Tag4!+.Rea" < vbCr)#
This is the simplest #orm o# rea"ing since no object re#erence is generate".
Rea%in3 /it: 'bject (e;e(ence
In the #ollo$ing e&le% a local cop* o# the tag object is create"% the tag value rea" an"
"ispla*e" in the @lobal ,cript "iagnostics $in"o$'
2VB,43E
Dim objTag
,et objTag ? HMIRuntime.Tags(!Tag4!+
HMIRuntime.Trace !Value' ! < objTag.Rea" < vbCr)#
Re#erencing o##ers the a"vantage o# being able to $or9 $ith the tag object. The tag value can be
rea"% calculations e&ecute" an" $ritten again'
2VB,43;
4:
Dim objTag
,et objTag ? HMIRuntime.Tags(!Tag4!+
objTag.Rea"
objTag.Value ? objTag.Value K 4
objTag.1rite
sing the Rea" metho"% process tags $hich have been rea" are a""e" to the image% #rom this
moment on the* c*clicall* reIueste" #rom the .,. I# the tag is alrea"* in the image% the value
containe" in it is returne".
5n closing the picture% the tags are logge" o## again.
N'te+
I# a tag is reIueste" in a @lobal ,cript action% it remains logge" on #or the entire 1inCC runtime
perio".
Di(ect (ea%in3
-ormall*% the tag values are rea" #rom the tag image. In certain situations% ho$ever% it ma* be
necessar* to rea" the value "irect #rom the .,% e.g. to s*nchroniJe #ast processes.
I# the optional parameter is set to 4 #or the rea" process% the tag is not logge" in c*clicall* but the
value is reIueste" once #rom the .,.
2VB,43H
Dim objTag
,et objTag ? HMIRuntime.Tags(!Tag4!+
HMIRuntime.Trace !Value' ! < objTag.Rea"(4+ < vbCr)#
N'te+
/lease note that the call ta9es longer in comparison to the stan"ar" call. The "uration is also
"epen"ent on the channel an" .,% amongst other things.
This t*pe o# call must be avoi"e" in the case o# c*clic C actions because this is the main reason
#or per#ormance problems.
This t*pe o# rea" process correspon"s to @etTagLLL1ait(+ call #rom C scripting.
Rea%in3 /it: status :an%-in3
43
In or"er to ensure that a value is vali"% a chec9 shoul" be ma"e #ollo$ing rea"ing. This occurs b*
the #act that the Mualit* Co"e is controlle".
In the #ollo$ing e&le% the !m*1or"! tag is rea" an" the Mualit*Co"e then chec9e". 1hen the
Mualit* Co"e "oes not correspon" to 5N (F&>F+ the )ast0rror% 0rrorDescription an" Mualit*Co"e
properties are "ispla*e" in the @lobal ,cript "iagnostics $in"o$.
2VB,43>
Dim objTag
,et objTag ? HMIRuntime.Tags(!Tag4!+
objTag.Rea"
I# <H>F AC objTag.Mualit*Co"e Then
HMIRuntime.Trace !0rror' ! < objTag.)ast0rror < vbCr)# < !0rrorDescription' ! <
objTag.0rrorDescription < vbCr)# < !Mualit*Co"e' F&! < He&(objTag.Mualit*Co"e+ <vbCr)#
0lse
HMIRuntime.Trace !Value' ! < objTag.Value < vbCr)#
0n" I#
N'te+
I# an error occurs "uring rea"ing% Mualit*Co"e is set to !B.D 5ut o# ,ervice!. There#ore% it is
su##icient to chec9 the Mualit*Co"e #ollo$ing rea"ing.
<=am1-e+ H'/ t' W(ite Object 0('1e(ties
Int('%ucti'n
VB, enables access to the properties o# all @raphics Designer picture objects. /roperties can be
rea" out to be mo"i#ie" or change" "uring runtime.
The #ollo$ing e&les illustrate various #orms o# access.
Sim1-e Settin3 '; a 0('1e(t2
In the #ollo$ing e&le% the bac9groun" color o# the !Rectangle4! object containe" in the
picture is set to re"'
2VB,43D
,creenItems(!Rectangle4!+.Bac9Color ? R@B(:EE%F%F+
4=
This is the simplest #orm o# $riting since no object re#erence is generate".
N'te+
I# the $or9 is complete" $ithout an object re#erence% onl* the stan"ar" properties are provi"e" in
Intellisense.
N'te+
The #orm o# e&pression use" in the e&le onl* applies to @raphics Designer. In the case o#
analog actions in @lobal ,cript% a""ress the objects using the HMIRuntime object.
Settin3 a 0('1e(t2 /it: Object Re;e(ence
In the #ollo$ing e&le% a re#erence is create" to the !Rectangle4! object containe" in the
picture an" the bac9groun" is set to re" using the VB, stan"ar" #unction R@B(+'
2VB,4=F
Dim objRectangle
,et objRectangle ? ,creenItems(!Rectangle4!+
objRectangle.Bac9Color ? R@B(:EE%F%F+
Re#erencing is use#ul $hen several object properties must be change". 1hen using Intellisense%
this process then lists all the object properties.
N'te+
The #orm o# e&pression use" in the e&le onl* applies to @raphics Designer. In the case o#
analog actions in @lobal ,cript% a""ress the objects using the HMIRuntime object.
Settin3 0('1e(ties .ia t:e 0ictu(e Win%'/
VB, in @raphics Designer o##ers t$o options #or cross7picture a""ressing'
using the screen object o# a picture $in"o$ $ith !,creenItems!
starting #rom the basic picture $ith !HMIRuntime.,creens!
Re#erencing the picture $in"o$
In the #ollo$ing e&le% the color o# a rectangle is change" in the un"erl*ing picture $in"o$.
The script is e&ecute" in the !Base,creen! picture $hich contains the picture $in"o$
!,creen1in"o$4!. The picture $in"o$ "ispla*s a picture $hich contains an object o# t*pe
!Rectangle! $ith the name !Rectangle4!.
4E
2VB,4DD
,ub 5n)Buttonp(B*Val Item% B*Val 6lags% B*Val &% B*Val *+
Dim objRectangle
,et objRectangle ? ,creenItems(!,creen1in"o$4!+.,creen.,creenItems(!Rectangle4!+
objRectangle.Bac9Color ? R@B(:EE%F%F+
0n" ,ub
Re;e(encin3 ;('m t:e basic 1ictu(e
Oou ma* also re#erence the picture $ith the object to be change" through HMIRuntime.,creens.
The speci#ication o# the picture is "e#ine" relative to the basic picture via the #ollo$ing access
co"e'
PABasic picture nameC.QA/icture $in"o$ nameCP'A/icture nameCQ... .A/icture $in"o$
nameCP'A/icture nameCQ
In the #ollo$ing e&le% a re#erence is create" to the !Rectangle4! object containe" in the
!,creen:! picture an" the bac9groun" color is set to re".
The picture !,creen:!% in this case% is in !,creen4!. !,creen4! is "ispla*e" in the basic picture
!Base,creen!.
!VBS1>1
Dim 'bjRectan3-e
Set 'bjRectan3-e ?
HMIRuntime.Sc(eens(&BaseSc(een.Sc(eenWin%'/1+Sc(een1.Sc(eenWin%'/1+Sc(een#&.S
c(eenItems(&Rectan3-e1&
'bjRectan3-e.Bac@C'-'( ? RGB(#AA)B)B
It is not necessar* to speci#* the picture name. It is possible to a""ress a picture uniIuel* using
the picture $in"o$ name. There#ore% it is su##icient to speci#* the name o# the picture $in"o$% as
in the #ollo$ing e&le'
2VB,4=:
Dim objRectangle
,et objRectangle ?
HMIRuntime.,creens(!,creen1in"o$4.,creen1in"o$4!+.,creenItems(!Rectangle4!+
4;
objRectangle.Bac9Color ? R@B(:EE%F%F+
This t*pe o# a""ressing enables objects in picture $in"o$s to be a""resse" in "i##erent pictures.
This is a particularl* interesting aspect in respect o# the picture mo"ule techniIue.
Ma@in3 t:e 0('1e(t2 D2namic 9sin3 t:e Retu(n Va-ue
.ctions on properties can not onl* be triggere" b* events or c*clicall* but properties can also be
ma"e "*namic "irectl* via an action.
In the #ollo$ing e&le% the bac9groun" color o# an object is ma"e "*namic via a return value.
The value trans#erre" can come #rom the evaluation o# events in the /)C% #or e&le an" use"
#or the graphic "ispla* o# an operating status'
2VB,4=;
6unction Bac9Color8Trigger(B*Val Item+
Bac9Color8Trigger ? R@B(4:E%F%F+
0n" 6unction
Cauti'n
I# *ou ma9e an object propert* "*namic $ith a VB, action via the return value o# a script% the
value o# the object propert* is $ritten onl* i# it has change" in relation to the last script run. It is
not consi"ere" i# the value ha" been change" #rom another location.
There#ore it is illegal to change properties $hich have been ma"e "*namic b* VB, action via the
return value #rom another location (e.g.% other C scripts or VB, scripts+.
i# *ou "o not observe this% $rong values can be the results.
0&le' Ho$ to ,tart an .ction on the ,erver ()ogging 5bject+
Int('%ucti'n
In multi7user projects% the )ogging object presentl* #unctions on the server onl*. The #ollo$ing
e&le sho$s ho$ to start an action on the server #rom the client% an" ho$ to s$ap an" "elete
archive segments on client accor"ingl*.
The e&le sho$s a global action starte" $ith a control tag. The contents o# the control tag
"etermine $hether the !Restore! metho" or the !Remove! metho" is calle". .t the en" o# the
action% the control tag is set to !F!.
. Iuer* prevents the action #rom being starte" on client computers.
/ath an" time perio" are passe" on b* internal tags.
4H
The path in#ormation ma* also contain a net$or9 release. .rchive segments to be s$appe" must
there#ore not be store" locall* at the server. It must be $arrante"% though% that the server ma*
"irectl* access the path.
N'te+
The e&le sho$s a "elete suggestion an" ma* be a"juste" as nee"e".
0('ce%u(e
4. In 1inCC 0&plorer% create the #ollo$ing internal tags $ith project7$i"e up"ates'
7 ,tart)ogging (nsigne" >7bit value+
7 ,ource/ath (Te&t tag >7bit character set+
7 Time6rom (Te&t tag >7bit character set+
7 TimeTo (Te&t tag >7bit character set+
7 RetVal (,igne" 3:7bit value+
:. Create a global VB, action an" enter the tag R,tart)oggingR as tag trigger $ith c*cle
!pon Change!.
3. Cop* the #ollo$ing script into the action
2VB,4>F
Dim ,tart)ogging
Dim ,ource/ath
Dim Time6rom
Dim TimeTo
Dim RetVal
20&it $hen running on client
I# ()e#t(HMIRuntime..ctive/roject./ath% 4+ ? !S!+ Then
0&it 6unction
0n" I#
2rea" parameters
,tart)ogging ? HMIRuntime.Tags(!,tart)ogging!+.Rea"
,ource/ath ? HMIRuntime.Tags(!,ource/ath!+.Rea"(4+
4>
Time6rom ? HMIRuntime.Tags(!Time6rom!+.Rea"(4+
TimeTo ? HMIRuntime.Tags(!TimeTo!+.Rea"(4+
2restore or remove "epen"s on the parameter
I# (,tart)ogging ? 4+ Then
RetVal ? HMIRuntime.)ogging.Restore(,ource/ath% Time6rom% TimeTo% 74+
HMIRuntime.Tags(!RetVal!+.1rite RetVal% 4
HMIRuntime.Tags(!,tart)ogging!+.1rite F%4
0lsei# (,tart)ogging ? :+ Then
RetVal ? HMIRuntime.)ogging.Remove(Time6rom% TimeTo% 74+
HMIRuntime.Tags(!RetVal!+.1rite RetVal% 4
HMIRuntime.Tags(!,tart)ogging!+.1rite F%4
0n" I#
The action ma* be starte" on a client $ith the #ollo$ing action% #or e&le. /lease note that
parameters must be $ritten prior to setting the control tag.
2VB,4>4
2set parameters
HMIRuntime.Tags(!,ource/ath!+.1rite !SSclient8pcStemp!%4
HMIRuntime.Tags(!Time6rom!+.1rite !:FF=!%4
HMIRuntime.Tags(!TimeTo!+.1rite !:FF=!%4
2start action
HMIRuntime.Tags(!,tart)ogging!+.1rite 4%4
N'te+
4D
Tags are pre"ominantl* $ritten an" rea" in !"irect! mo"e. This $ill s*nchroniJe the seIuences.
,ince this "eals $ith internal tags% this mo"e ma* be use" $ithout an* #urther concerns.
Gene(a- e=am1-es ;'( VBSc(i1t
Int('%ucti'n
-ote'
.ll objects supplie" $ith the 1in"o$s ,cript Host (1,H+ #rom Microso#t can be integrate" in
their environment using the stan"ar" VB, metho" Create5bject. Ho$ever% there is no "irect
access to the 1,H object itsel# using VB, #rom 1inCC.
0&le 4' !6ile,*stem5bject! object #or $or9ing $ith the #ile s*stem
Dim #so% M*6ile
,et #so ? Create5bject(!,cripting.6ile,*stem5bject!+
,et M*6ile ? #so.CreateTe&t6ile(!c'Stest#ile.t&t!% True+
M*6ile.1rite)ine(!This is a test.!+
M*6ile.Close
0&le :' !1,cript.,hell! object #or $or9ing $ith the 1in"o$s environment
This section contains e&les o# the general use o# VB,cript $ith regar" to the #ollo$ing
topics'
/rogramming Data Connection $ith VB,
Calling Metho"s
M,7sing the .utomation Inter#ace
,tarting 0&ternal .pplications
:F
0&le' Con#iguring a Database Connection $ith VB,
Int('%ucti'n
The #ollo$ing e&les "escribe the con#iguration o# an .ccess "atabase lin9 via an 5DBC
"river.
0&le 4 $rites a tag value #rom 1inCC in an .ccess "atabase.
0&le : rea"s a value #rom the "atabase an" $rites it in a 1inCC tag.
The e&les "o not contain an* han"ling #aults.
0('ce%u(e) <=am1-e 1
4. Create the .ccess "atabase $ith the 1I-CC8D.T. table an" columns (ID% TagValue+ $ith
the ID as the .uto Value.
:. ,et up the 5DBC "ata source $ith the name !,ampleD,-!% re#erence to the above .ccess
"atabase.
3. /rogramming.
<=am1-e 1
2VB,4F>
Dim objConnection
Dim strConnection,tring
Dim lngValue
Dim str,M)
Dim objComman"
strConnection,tring ? !/rovi"er?M,D.,M)TD,-?,ampleD,-TID?T/1D?T!
lngValue ? HMIRuntime.Tags(!Tag4!+.Rea"
str,M) ? !I-,0RT I-T5 1I-CC8D.T. (TagValue+ V.)0, (! < lngValue < !+T!
,et objConnection ? Create5bject(!.D5DB.Connection!+
objConnection.Connection,tring ? strConnection,tring
objConnection.5pen
:4
,et objComman" ? Create5bject(!.D5DB.Comman"!+
1ith objComman"
..ctiveConnection ? objConnection
.Comman"Te&t ? str,M)
0n" 1ith
objComman".0&ecute
,et objComman" ? -othing
objConnection.Close
,et objConnection ? -othing
0('ce%u(e) <=am1-e #
4. Create the 1inCC tag $ith the name "bValue.
:. Create .ccess "atabase $ith 1I-CC8D.T. table an" ID% TagValue columns' (ID as
.uto Value+.
3. ,et up the 5DBC "ata source $ith the name !,ampleD,-!% re#erence to the above
.ccess "atabase.
=. /rogramming.
<=am1-e #
2VB,4F>a
Dim objConnection
Dim objComman"
Dim objRecor"set
Dim strConnection,tring
Dim str,M)
Dim lngValue
Dim lngCount
strConnection,tring ? !/rovi"er?M,D.,M)TD,-?,ampleD,-TID?T/1D?T!
::
str,M) ? !select TagValue #rom 1I-CC8D.T. $here ID ? 4!
,et objConnection ? Create5bject(!.D5DB.Connection!+
objConnection.Connection,tring ? strConnection,tring
objConnection.5pen
,et objRecor"set ? Create5bject(!.D5DB.Recor"set!+
,et objComman" ? Create5bject(!.D5DB.Comman"!+
objComman"..ctiveConnection ? objConnection
objComman".Comman"Te&t ? str,M)
,et objRecor"set ? objComman".0&ecute
lngCount ? objRecor"set.6iel"s.Count
I# (lngCountCF+ Then
objRecor"set.move#irst
lngValue ? objRecor"set.6iel"s(F+.Value
HMIRuntime.Tags(!"bValue!+.1rite lngValue
0lse
HMIRuntime.Trace !,election returne" no #iel"s! < vb-e$)ine
0n" I#
,et objComman" ? -othing
objConnection.Close
,et objRecor"set ? -othing
,et objConnection ? -othing
There are several $a*s in $hich to "e#ine the Connection,tring #or the connection "epen"ing on
the provi"er use"'
Microso#t 5)0 DB provi"er #or 5DBC
:3
0nables connections to an* 5DBC "ata source. The correspon"ing s*nta& is'
!P/rovi"er?M,D.,M)TQUD,-?nameV6ileD,-?#ilenameWT
PD.T.B.,0?"atabaseTQID?userT /1D?pass$or"!
5ther Microso#t 5)0 DB /rovi"er (e.g. M, Xet% M, ,M) ,erver+
It is possible to $or9 $ithout D,-. The correspon"ing s*nta& is'
!P/rovi"er?provi"erTQDRIV0R?"riverT ,0RV0R?serverT
D.T.B.,0?"atabaseT ID?userT /1D?pass$or"!
<=am1-e+ CCa--in3 Met:'%s '; an $cti.eC C'nt('-
Int('%ucti'n
The #ollo$ing e&les illustrate ho$ to call metho"s an" properties o# an .ctiveL control
$hich is embe""e" in a 1inCC picture.
<=am1-e 1+ MS D'(m #.B C'mb'b'=
This e&le #ills a combobo& $ith the name !ComboBo&4! #rom an* point in the picture.
2VB,4FD
Dim cboComboBo&
,et cboComboBo& ? ,creenItems(!ComboBo&4!+
cboCombobo&..""Item !48ComboBo&86iel"!
cboComboBo&..""Item !:8ComboBo&86iel"!
cboComboBo&..""Item !38ComboBo&86iel"!
cboComboBo&.6ontBol" ? True
cboComboBo&.6ontItalic ? True
cboComboBo&.)istIn"e& ? :
<=am1-e #+ MS D'(m #.B Listb'=
This e&le #ills a list bo& $ith the name !)istBo&4! #rom an* point in the picture.
2VB,44F
:=
Dim lst)istBo&
,et lst)istBo& ? ,creenItems(!)istBo&4!+
lst)istBo&..""Item !48)istBo&86iel"!
lst)istBo&..""Item !:8)istBo&86iel"!
lst)istBo&..""Item !38)istBo&86iel"!
lst)istBo&.6ontBol" ? True
<=am1-e *+ WinCC Duncti'n T(en% C'nt('-
This e&le #ills the tren" control #unction name" !Control4! $ith the values $hich "escribe a
parabola.
2VB,444
Dim lng6actor
Dim "bl.&isL
Dim "bl.&isO
Dim objTren"Control
,et objTren"Control ? ,creenItems(!Control4!+
6or lng6actor ? 74FF To 4FF
"bl.&isL ? CDbl(lng6actor Y F.F:+
"bl.&isO ? CDbl("bl.&isL Y "bl.&isL K : Y "bl.&isL K 4+
objTren"Control.DataL ? "bl.&isL
objTren"Control.DataO ? "bl.&isO
objTren"Control.InsertData ? True
-e&t
<=am1-e >+ WinCC Duncti'n T(en% C'nt('- /it: Va-ues Su11-ie% Via $((a2s
In this e&le% a 6unction Tren" Control calle" !Control4! is supplie" $ith 4FF value pairs. In
or"er that the value pair can be trans#erre" correctl*% the trans#er e.g. in !"bl.&isLO! must not
occur "irectl* but via an interme"iate tag% e.g. !varTemp!.
:E
2VB,4E:
Dim lngIn"e&
Dim "blLO(4+
Dim "bl.&isLO(4FF+
Dim varTemp
Dim objTren"Control
,et objTren"Control ? ,creenItems(!Control4!+
6or lngIn"e& ? F To 4FF
"blLO(F+ ? CDbl(lngIn"e& Y F.>+
"blLO(4+ ? CDbl(lngIn"e&+
"bl.&isLO(lngIn"e&+ ? "blLO
-e&t
varTemp ? ("bl.&isLO+
objTren"Control.DataLO ? varTemp
objTren"Control.InsertData ? True
<=am1-e A+ Mic('s';t Web B('/se(
This e&le controls M, 1eb Bro$ser.
2VB,44:
Dim obj1ebBro$ser
,et obj1ebBro$ser ? ,creenItems(!1ebControl!+
obj1ebBro$ser.-avigate !http'GG$$$.siemens."e!
...
obj1ebBro$ser.@oBac9
...
:;
obj1ebBro$ser.@o6or$ar"
...
obj1ebBro$ser.Re#resh
...
obj1ebBro$ser.@oHome
...
obj1ebBro$ser.@o,earch
...
obj1ebBro$ser.,top
...
N'te+
Insert the instructions% separate" b* stops% in sel#7"e#ine" proce"ures. Declaration an"
assignments must al$a*s prece"e them.
<=am1-e+ 9sin3 t:e MS $ut'mati'n inte(;ace
Int('%ucti'n
The #ollo$ing three e&les illustrate ho$ to use the M, .utomation inter#ace.
<=am1-e 1+ MS <=ce-
In this e&le% an output value #rom an input #iel" is $ritten in an 0&cel table.
2VB,443
Dim obj0&cel.pp
,et obj0&cel.pp ? Create5bject(!0&cel..pplication!+
obj0&cel.pp.Visible ? True
2
20&cel0&le.&ls is to create be#ore e&ecuting this proce"ure.
:H
2Replace ApathC $ith the real path o# the #ile 0&cel0&le.&ls.
obj0&cel.pp.1or9boo9s.5pen !ApathCS0&cel0&le.&ls!
obj0&cel.pp.Cells(=% 3+.Value ? ,creenItems(!I56iel"4!+.5utputValue
obj0&cel.pp..ctive1or9boo9.,ave
obj0&cel.pp.1or9boo9s.Close
obj0&cel.pp.Muit
,et obj0&cel.pp ? -othing
<=am1-e #+ MS $ccess
This e&le opens a report #rom M, .ccess.
2VB,44=
Dim obj.ccess.pp
,et obj.ccess.pp ? Create5bject(!.ccess..pplication!+
obj.ccess.pp.Visible ? True
2
2Db,ample.m"b an" R/T81I-CC8D.T. have to create be#ore e&ecuting
2this proce"ure.
2Replace ApathC $ith the real path o# the "atabase Db,ample.m"b.
obj.ccess.pp.5penCurrentDatabase !ApathCSDb,ample.m"b!% 6alse
obj.ccess.pp.DoCm".5penReport !R/T81I-CC8D.T.!% :
obj.ccess.pp.CloseCurrentDatabase
,et obj.ccess.pp ? -othing
<=am1-e *+ MS Inte(net <=1-'(e(
This e&le opens the M, I0.
2VB,44E
:>
Dim objI0
,et objI0 ? Create5bject(!Internet0&plorer..pplication!+
objI0.-avigate !http'GG$$$.siemens."e!
Do
)oop 1hile objI0.Bus*
objI0.ResiJable ? True
objI0.1i"th ? EFF
objI0.Height ? EFF
objI0.)e#t ? F
objI0.Top ? F
objI0.Visible ? True
<=am1-e+ Sta(tin3 an e=te(na- a11-icati'n
Int('%ucti'n
The #ollo$ing t$o e&les illustrate ho$ to start an e&ternal application.
<=am1-e
2VB,44H
Dim obj1sh,hell
,et obj1sh,hell ? Create5bject(!1script.,hell!+
obj1sh,hell.Run !-otepa" 0&le.t&t!% 4
:D
3F