You are on page 1of 175

Cicode Programming

<Instructors Name>
Objectives

Good Understanding & Competent in Use of


Cicode

Be Able to Use Cicode in Commands and


Expressions

Apply Learning to Yor O!n "ite or #roject

Be Able to $rite Yor O!n Cicode %nctions

&no! 'o! to (ebg Yor O!n Cicode


%nctions
This Presentation is 2005 2007 Citect Pty Ltd
Agenda ) (ay *

$elcome

+ntrodction to Cicode

,ariable Operators Used in Cicode

-.e Cicode Editor

$riting "imple %nctions

Using Cicode ,ariables

Conversion %nctions

+nclde %iles
Agenda ) (ay /

Conditional Exectors

Cicode 0etrn %nctions

Arrays

(ebgging Yor Code


-raining %acilities

Emergency Exits

Ladies1 & Gents1

&itc.en

Brea2s 3 lnc.

4obile #.ones

Compendim
$elcome

+ntrodce trainer

"tdents introdce self

5ame

Employer

Crrent Citect or "CA(A experience

Expected otcomes from training


-raining Agreement

+t1s O& to67

Express ideas

C.allenge t.e facilitator

Offer examples

8estion

0elax
-raining Agreement

-rainer1s role

"tart and end on time

#rofessionally facilitate t.e exc.ange of information and 2no!ledge

Allo! time for 9and encorage: inpt

Listen non)defensively

'elp yo learn
-raining Agreement

Yor role

Be on time

#articipate

Learn in yor o!n !ay

#rovide .onest open feedbac2

Enjoy yorself
Ergonomics

(es2s and c.airs

Adjst to yor comfort level

0elocate screen; 2eyboard; mose as re<ired

Environmental conditions

Lig.ting

Air conditioning

0est and relaxation

0eglar movement

Eye strain
+ntrodction to Cicode
Chapter 2
+ntrodction to Cicode
Chapter Overview

Commands; Expressions and %nctions

Use Commands to Control #rocesses

(isplay (ata from Expressions


$.at is Cicode=

A programming langage>

A means of extending t.e fnctionality of ,ijeo Citect


projects

+nteract !it. variable tags

Exc.ange data !it. external sorces

Create complex formlae

$.y do !e need it=

$.en !e are nable to ac.ieve t.e re<ired otcome by


configring grap.ics pages

%or t.e programmers in t.e adience?

+t1s li2e any .ig.)level langage; bt !it.ot complex


strctres; pointers; recrsion or in.eritance
Cicode #roject

#re)configred project? Cicode@4il2


#asterisation #age
C.apters #age
0estore 4il2 #roject

0estore 4il2 project


from t.e folder spplied
by yor facilitator

Compile t.e project and


t.en rn t.e Compter
"etp $iAard 9express:
0n 4il2 project
-est #asterisation page
,ie! C.apters page
Commands

Cicode Commands can be issed?


4anally
Operator types in commands
Clic2ing on a btton or object on a grap.ics page
Atomatically
Operator logs in or ot of t.e rntime system
A grap.ics page is opened or closed
An alarm is triggered
+n a report
$.en an event is triggered
Cicode Commands

"ingle statement or grop of


statements
Open C.apters #age

Create bttons to trn "ilo Agitator off and on

Create / bttons in t.e


C.apters #age

Compile and -est by


s!itc.ing to t.e C.apters
#age to vie! reslts
"etting ,ariables

Execte Command

(igital -ag

C.ange stats of -ag

Analog -ag

"et vale of -ag

,ariable*Bvale

,ariable*B,ariable/
Plant1_Pump=1 ;
Plant1_Pump=0 ;
Oven_Temp=10 ;
Oven_Temp=Kettle_Temp;
"tring ,ariables
Expressions

Any combination of variables; operators; and statements


!.ic. evalate to some reslt

8 + 4

Motor_Speed / 5

Calclations in a Cicode statement

Result = Operand1 + Operand ! Operand"


(isplaying (ata

(isplayed ,ale c.anges as vale of


expression c.anges
Expression
changes
Value
changes
4ltiple "tatements

4ltiple statements can be separated by a semi)colon ;


Kettle_Temp=10 ;
Oven_Temp=Kettle_Temp ;
#at$%_&ame='#read( ;

4ltiple statements

Add a prompt
T)*_P4_P+ = T)*_P1_P+ + T)*_P_P+ ;
Prompt,-*al$ulat.on .s /.n.s%ed-0
Operator +npt

(efine 2eyboard Command as a &ey se<ence


Key e!uence
ending in E"TE#
$llo%s up to &
characters to 'e
entered
(2 signals start o)
Key e!uence
Argments

1r21 provides inpt to variables by &eyboard entry

*onve3or_Speed=1r21

*onve3or_Speed=1r2+alue1

4oT%.sT%en4oT%at,1r2151r20
Varia'le $rgu*ent +,
$rgu*ent +,
Chec-s )or "u*eric .alue
$rgu*ent +, $rgu*ent +2
/(20 ,2& 1 &25 /enter0

Enter &eyboard &ey


(efinition

C.ange 4isc*
properties
Calling %nctions

(efinition

Function A general term sed for a sbrotine

#arent.eses identifies statement as fnction

/un$t.on&ame,1r2151r2 60

Prompt,'S%utdo7n(0

S%utdo7n,0
$rgu*ents passed
to the )unction
"a*e o) the (unction

Calling fnctions
%nction +nformation

Loo2 p in online
.elp

Prompt

S%utdo7n

Pa2e4.spla3
#assing (ata to %nctions

%nctions can spport C;* or many argments

Prompt,'Press /1 8or 9elp(0


:un;/un$t.on,'1st 1r2ument(5'nd 1r2ument(0
$rgu*ents passed
to the )unction
Place dou'le !uotes around any string passed
to a )unction

Add &ey se<ence to project

0BU--O5@U# exectes command any!.ere on page


Not #34TT5"6C7864P
Search capability

+nvo2e external programs


from !it.in ,ijeo Citect
,9 (ind Excel in
:indo%s Explorer
2
9

C
l
i
c
-

;

8
r
a
g

t
o

a

C
o
*
*
a
n
d
:
i
n
d
o
%
&9 Copy ; Paste to Vi<eo Citect
4ltiple Argments

All argments mst be listed

"eparate argments !it. a comma ,

Argment order is important

"trings are D<otedE

<o2.n,'Mana2er(5 '1#*(0
Login ID Password
#assing 5meric Argments

Bot. +ntegers and %loating #oint nmbers


can be passed to a fnction
INT
REAL

1ss=.n,->+alve-55805150551+8+15'+alve_*ool_*M4-0
"a*e o) Popup
%indo%
Location on
screen
7ode o)
Popup
%indo%
Tag
#assing ,ariable Argments

$.en variables are sed as arguments

,ale of variable is passed; not variable string itself

4spStr ) (isplays a string at a specified A5

4spStr,55(Te?t/ont(5 *O1<_<@+@<0;

4spStr,55(Te?t/ont(5 '*O1<_<@+@<(0;
$ni*ation
Point
nu*'er
8isplay
using this
)ont
Value o)
C5$L6LEVEL .aria'le
%ill 8isplay
C5$L6LEVEL string %ill
8isplay as its =!uoted>
4spStr,"A5 -*ontrol<.m.ts-5 Re$.pe0
$" &2?
0etrning (ata

%nctions can retrn a vale to t.e calling


statement

"ccess 0

%ailre error number


or

Data

As in?
date,0
Prompt,'9ello5( + /ull&ame,0 0
#esult o)
@(ull"a*eA
used as a
para*eter to
@Pro*ptA
BTa2B=/orm&umPad,-@nter-5BTa2B500
Pass Value )ro*
nu*Bpad into Tag
.aria'le
Title gi.en
to nu*'er
pad
Value
passed i)
cancelled
7ode
standard in
this case
Execte %nction on "tartp
Messa2e,'Startup(5'9ello
=orld(5A40
elect
Custom
7ode
7odi)y
"mmary of ,ariables

(igital 9a727a7 Boolean or Logical:

(igital@,ariable B C

(igital@,ariable B *

(igital@,ariable* B (igital@,ariable/

+nteger 9)F/GHI ) JF/GHG:

+nteger@,ariable B FK

+nteger@,ariable B )*/GK

+nteger@,ariable* B +nteger@,ariable/ J F

"trings 9Up to /LL c.aracters:

"tring@,ariable B DappleE

"tring@,ariable B Dstring variableE

"tring@,ariable* B "tring@variable/ J Dmore textE

(atatypes 4U"- matc. dring assignments


(ata -ypes

%red

,ariable
#LC variable
Cicode variable

D%redE

"tring

%red9:

%nction

M%redN

#at. sbstittion

Array index

O%redP

%ield definition

Compile error context


C.apter / ) "mmary 8estions

$.at are t.e t!o mec.anisms to activate a


command=

$.at is a Cicode expression=

$.at c.aracter is sed to combine several tas2s=

$.at is t.e syntax to call a fnction=

$.at is t.e reslt of enclosing a tag in doble)


<otes=

'o! do yo set a system start)p fnction=


+ntrodction to Cicode
C.apter "mmary

"etting variables

Using expressions

Operator inpt

#assing data to fnctions

0etrning data from fnctions


,ariable Operators
Chapter 3
,ariable Operators
Chapter Overview

Classes of Operators in Cicode

Order of #recedence
Classes of Operators

4at.ematical
Operator Description
+ Addition 9for nmeric vale:
+ Concatenation 9for string variables:
"btraction
! 4ltiplication
" (ivision
#OD
4odls 90emainder:
+nt-o"tr9: fnction

Used !.ere fnction only accepts strings

Use a fnction li2e )ntToStr,0


Prompt,' +alue ( + )ntToStr,Ta2_100

#OD Operator

T)*_P_P+ = T)*_P4_P+ MO4 10

Concatenation

Messa2e,(P- 5 (T)*_P_P+ = - +
)ntToStr,T)*_P_P+0 5 A40
Logical Operators

Operator Q-re1 retrns $

Operator Q%alse1 retrns 0


Operator Description Operator
%&D Logical A5( Binary
O' Logical O0 Binary
&O( Logical 5O- Unary
)O' Logical RO0 Binary
-rt. -ables
%&D 0 1
0 C C
1 C *
O' 0 1
0 C *
1 * *
-rt. -ables
)O' 0 1
0 C *
1 * C
&O( 0 1
* C
12.tator_S.lo_+ =
12.tator_1l8ast_+ 1&4
*entr.8u2e_*lar_+

12.tator_S.lo_+
!ill be trned on O5LY
!.en bot.
12.tator_1l8ast_+
and
*entr.8u2e_*lar_+
are trned on7

Create mlti)state text object


Bit Operators

"tandard bit operators


11011
AND 1101
= 01001
Operator Description
B+-A5( Bit!ise A5(
B+-O0 Bit!ise O0
B+-RO0 Bit!ise RO0
0elational Operators

-ests t.e relations.ip bet!een t!o vales


Operator Description
* is e<al to
+, is not e<al to
+ is less t.an
, is greater t.an
+* is less t.an or e<al to
,* is greater t.an or e<al to

Create advanced alarm


%ormat Operator

Convert nmeric vales into formatted strings


Ta21 C DDDED

(isplay tag* as t.ree digits before and one digit after t.e decimal point
Operator Description
- 9colon:
"tring %ormat
%ormat Operators
.peci/ier Description Function 0se 12ample
S -.e .as.
c.aracter
-.e nmber of
c.aracters to
display to t.e
rig.t of t.e A5
####
+ 23
+472213
C Tero #adding
#0##
+0023
) 4ins Ustification
#-###
+23
7 #eriod (ecimal notation

###.##
+ 23.54
EU Engineering
nits
#.##EU
" Exponential
notation
#s###
+1.234e+012

%ormat Operator
Messa2e,'P"- 5 T)*_P"_P+CDDDEDD5A40
TA !ormat
Operator order of #recedence
Order Operator
* 34
/ &O(
F ! , " , #OD
K -
L + ,
H + , , , +* , ,*
G * , +,
I %&D
V O'
*C 56(%&D, 56(O', 56()O'
#recedence Examples

Ta2_1 OR Ta2_ 1&4 &OT Ta2_"


*7 5O- -ag@F
/7 A5( -ag@/
F7 O0 -ag@*

,Ta2_1 OR ,Ta2_ 1&4 ,&OT Ta2_"000

-est Order of #recedence


*entr.8u2e_*lar_+ = &OT 12.tator_S.lo_+ 1&4 12.tator_1l8ast_+
C.apter F ) "mmary 8estions

5ame t!o of t.e classes of operators sed in


Cicode7

'o! do yo test t.e relations.ip bet!een t!o


vales=

'o! do yo convert nmeric vales into formatted


strings=

$.y are brac2ets sed in formlas=


,ariable Operators
C.apter "mmary

4at.ematical operators

Logical operators

0elational operators

Order of precedence
-.e Cicode Editor
Chapter 7
-.e Cicode Editor
Chapter Overview

"tarting t.e Cicode Editor

Compile; 0n and (ebg Yor Code

%ile 5avigation %eatres

Code Editing -ools

(oc2able $indo!s and -oolbars

C.anging #references
"tarting t.e Cicode Editor

Clic2 on Cicode Editor icon

"elect 5e! Cicode page


Context "ensitive 'elp
7
Cursor
anywhere
on "Logout#
term
$it %!&'
(ey
Open t.e Cicode Editor
"ave as -raining
Compile & 0n

Go-o btton provided

#rovides line nmber !.ere error occrred

Compile & 0n

Compile only
Error
shown
oTo
error
Go-o Errors

Compiler points to error

Clic2 Go-o Btton


Error Condition
/F&*T)O&
*%an2e+alue,0
Ta2+alue1=10
@&4
/F&*T)O&
*%an2e+alue,0
Ta2+alue1=10
@&4
ERR)R
5e! Editor %eatres

Color Coding

Ato +ndenting
Comment 3 Uncomment featre
En.anced %ile 5avigation

-abs give F different vie!s

,ie! open %iles


C.anging -oolbars

Clic2 and drag to reposition toolbars

0ig.t Clic2 toolbar area bac2grond

Adds 5e! toolbars


+ndent and Comment
)utdent *ncomment
Indent Comment
Select te+t
Clic,
comment
icon
Comments

Comment yor code constantly

#reface every Cicode file !it.


/G
4@S*R)PT)O&C /un$t.on to do t%.s and t%at
More des$r.pt.on %ere
G/
// R@+ 41T@ 1FT9OR 4@S*R)P
// 1E0 0/1/04 #E#oH Or.2.nal
// E0 01/04/05 )ERaHH.tt 1dd #lo7Fp);ea,0 8un$t.on
//
// &OT@SC 1ll 8un$t.ons 7.ll He 7r.tten .n *.$ode
// proIe$t 2.ven .n t%e $ourses
/F&*T)O&
4oT%.s1ndT%at,0 > /un$t.on starts %ere
)nt .*ounter // <o$al loop $ounter
C)style Qbloc2 comments1 9dangeros> $.at abot overlap=:
CJJ style comments
Line comments
Boo2mar2s & Brea2points
Clear Pre-ious
Toggle .oo,mar,
Ne+t
Le/t Clic, 0 .rea,point
Right Clic, 0 .oo,mar,
n1& = 1&H3&ame,'=eH#ro7ser(0 ;
4spSetT.p,n1&5 'M3 =eH #ro7ser(0 ;
Experi*ent %ith
'oo-*ar-s co**ents and
indents
4se Co**ents Li'erally
List %nctions

Context sensitive fnction list

WctrlX WspaceX
Select List
!unctions
Right Clic,
in te+t
+ntellisense Atoprompt

-yping fnction and opening brac2et displays


Atoprompt

%nction list displays Atoprompt


R@1<
/F&*T)O&
1reaO8*.r$le,R@1< rRad.us0
R@TFR& ,"E141 G Po7,rRad.us500 ;
@&4
_______________________________________
/un$t.on
Test,0
1reaO8*.r$le,00
@&4
#references

Cstomising Cicode Editor


1iew 2 Pre/erences
To change options

Cicode #references
C.apter K ) "mmary 8estions

'o! can yo vie! files easily=

$.y se boo2mar2s and brea2points=

'o! can yo c.ange t.e loo2 of t.e code !indo!=


-.e Cicode Editor
C.apter "mmary

"tarting t.e editor

Goto errors

%ile navigation

Editing tools

%nction tools

#references
Cicode %nctions
Chapter 8
Cicode %nctions
Chapter Overview

"imple %nctions

"trctre of a %nction

#blic & #rivate %nctions

(eclaring & 5aming %nctions

"tatements

,oid %nctions

Cicode ,ariables

+nclde %iles
"imple %nctions
PF#<)*
/F&*T)O&
)n$*ounter,0
)/ *ount J 100 T9@&
*OF&T=*OF&T + 1;
@<S@
*OF&T@R = 0 ;
@&4
@&4
"cope of %nction #blic or
#rivate
"tart of %nction
5ame of %nction
"tart of Code
End of +% statement
End of Code

%nction "yntax Y #sedocode
9@<<O
StandFp,0
)/ told T9@&
Stand Fp ;
@<S@
Rema.n Seated;
/.n.s%ed
KOO4#L@
%nction Elements

"cope

(eclaration

5ame

"tatement
"cope

#UBL+C

(efalt

".ared across #roject

#0+,A-E

Only !or2s !it.in Cicode


file !.ere !ritten
(eclaring %nctions

+ndicates beginning and end of fnction code


Scope
/F&*T)O&
FunctionName!
Statement "
@&4
5aming %nctions
Up to F/ c.aracters
(o not se reserved !ords
Case insensitive
Use CamelCase
UpperCamelCase
lo!erCamelCase
Scope
FUN#$%&N
/un$t.on&ame,0
Statement "
END
"tatements

#erform t.e D!or2E in t.e fnction

'U()%#

FUN#$%&N

StatementE*amp+e!

)/ M1S9_PFMP T9@&

PROMPT,'Mas% Pump On(0;

@<S@

PROMPT,'Mas% Pump O88(0;

@&4

END
Statements
,oid %nctions

(o not retrn any data to t.e calling fnction

'U()%#

FUN#$%&N

,oi-E*amp+e!

)/ M1S9_PFMP T9@&

PROMPT,'Mas% Pump On(0;

@<S@

PROMPT,'Mas% Pump O88(0;

@&4

END
PF#<)*
/F&*T)O&
M34ateT.me,0
M)S*1=4ate,"0;
M)S*=T.me,10;
@&4
PF#<)*
/F&*T)O&
1ud1larm,0
4spPla3Sound,'MRF&NCTadaE7av(500;
Messa2e,'1larm(5(9old.n2 TuHe too 9ot(5480;
@&4
$TA3$ )R $TA3$$
/F&*T)O&
1vera2e@?1,0
T)*_P_P+ = ,T)*_P1_P+ + T)*_P4_P+0 /
@&4
Cicode ,ariables

Located in Compter memory

-emporary data storage

(ata -ypes

"trings ) "-0+5G

+ntegers ) +5-

0eal 5mbers ) 0EAL


"+LO@LE,EL vale
O,E5@-E4# vale
"-0+5G@-AG vale
iAverage
rArea
s4y5ame
PLC Registers
Computer 4emory
(eclaring Cicode ,ariables

Li2e ,ariable -ags Y a (ata -ype mst be


specified for Cicode ,ariables

Global; 4odle; Local


Cicode ,ariable "yntax

"yntax?
S*OP@ 41T1TLP@ &1M@ = )&)T)1<+1<F@
K<O#1< STR)&K sM3Str.n2 = '( > &ull +alue

lobal
4odule
Local
STRIN
INT
REAL
1ariable
Name
Initiali5e
1ariable
Global Cicode ,ariables

,alid across all Cicode files and all inclde projects

4aintenance more difficlt

Local variables preferred


K<O#1< STR)&K 2s4e8aultPa2e = 'M)M)*( ;
%N$
FUN#$%&N
.+o/a+E*amp+eSt0in1 s'a1e!
%N$ iStatus "
iStatus = 'a1eDisp+a2s'a1e! "
%F iStatus 34 0 $5EN
'a1eDisp+a21sDe6au+t'a1e! "
END
7E$U7N iStatus "
END
4odle Cicode ,ariables

"pecific to t.e file !.ere it is declared

(efalt for Cicode variables

(eclare before fnctions se it

4ltiplies maintenance isses


Local Cicode ,ariables

"pecific to /unction !.ere declared

Any variable defined !it.in a fnction


is local by defalt 9no prefix re<ired:

Only valid !.ile fnction exectes

Local variables ta2e precedence if


name conflict occrs
Local Cicode ,ariables
'U()%#
%N$
FUN#$%&N
)oca+E*amp+e!
)&T .1vera2e ;
.1vera2e=,T1K1 + T1K0 /;
7E$U7N iA8e0a1e
END
,ariable 5aming "tandards
'ngarian 5otation

+nitial 9lo!ercase: letter describes variable sage

Coined by C.arles "imonyi of 4icrosoft

Applications 'ngarian vs7 "ystem 'ngarian


.9stem :ungarian &otation
Pre/i2 6nterpretation
i; n +nteger
r 0eal
s "tring
o Object 9activeR:
. 'andle 9int:
%pps :ungarian &otation
Pre/i2 6nterpretation
p #mp 9on3off:
t -emperatre
x 'oriAontal coord
y ,ertical coord
c Control variable
/F&*T)O&
1ud1larm,STR)&K s/.le5 STR)&K sT.tle5 STR)&K
sMessa2e0
4spPla3Sound,s/.le500;
Messa2e,sT.tle5sMessa2e5480;
@&4
1ud1larm,-*CO=)&4O=SOMed.aO$%.mesE7av-5 'Oven
Temp-5 '9old.n2 TuHe Too *old-0
3utton
Converting Cicode ,ariables
Convert (ata -ypes for frt.er processing
)ntToStr,0
RealToStr,0
StrTo)nt,0
StrToReal,0
CnputDE StrToInt67
Calculations
FBGH

Use RealToStr fnction

5eed to convert nmber to string for se by messa2e,0


fnction

RealToStr,Number, Width, Places0

Number: -.e floating)point nmber to convert

Width: -.e !idt. of t.e entire string

Places: 5mber of decimal places in t.e string


Messa2e,'9old.n2 TuHe(5RealToStr,T)*_9O<4_P+5A5"05A40
@2 t%e spe$.8.$at.on A5" $an store
1E"45

Enter a vale into a -ag


/F&*T)O&
Operator)nput,0
STR)&K sTa2
//sTa2 .s a str.n2
sTa2=)nput,-@&T@R-5-@nter a value-5--0;
// 4.spla3s d.alo2 Ho?5 operator $an .nput a
// s.n2le value ,T.tle5 Prompt5 4e8ault0
<)*_S.lo_P+=StrTo)nt,sTa20;
// *onvert sTa2 value to str.n2 and pla$e .n
// <)*_S.lo_P+ var.aHle
@&4

(isplay -ime

*ent_RT is t.e accmlator


T.meToStr,Time, Format, UTC0
T.meToStr,*ent_RT550
+nclde %iles

Command field limited to */I


C.aracters

+nclde %iles accommodate a single


complex statement se<ence

Any valid (O" filename

Convention? Fi+ename.cii

0eferenced by?
PJ8.lenameQ
D) Include %'

Create an +nclde file

Use 5otepad

+%larms;cii,
1ud1larm,*CO=)&4O=SOMed.aO$%.mesE7av5
'9old.n2 TuHe(5 '9old.n2 TuHe Too *old(0
C.apter L ) "mmary 8estions

'o! many bilt)in fnctions are spplied !it. ,ijeo Citect=

$.at are t.e for basic elements of %nctions=

'o! and !.y se t.e #rivate fnction attribte=

$.at is Qdeclaring a fnction=1

'o! many c.aracters can be sed in a fnction name=

$.at is Qt.e statement=1

$.at are ,oid fnctions=

$.at is a Cicode variable=

$.at is an inclde file=


Cicode %nctions
C.apter "mmary

Elements of a fnction

,oid fnctions

Cicode variables

Converting and formatting variables

+nclde files
Conditional Exectors
Chapter <
Conditional Exectors
Chapter Overview

%or conditional exectors

+%

%O0

$'+LE

"ELEC- CA"E
+% "tatement

Execte code based on reslt of a test


)/ EE T9@& or )/ EE T9@& EE @<S@
)/ test e?press.on T9@&
True Statements ;
@&4
) Or )
)/ test e?press.on T9@&
True Statements ;
@<S@
/alse Statements ;
@&4

Use +% 77 -'E5 77 EL"E statement


/F&*T)O&
)/_@?ample1,0
)/ *entr.8u2e_*lar_+ = 1 T9@&
Messa2e,'*lar.8.er Status(5 'Runn.n2(5A40
@<S@
Messa2e,'*lar.8.er Status(5(Stopped(5A40
@&4
@&4

Use +% -'E5 EL"E sing Cicode variables


/F&*T)O&
// set data t3pes 8or var.aHles .n t%.s 8un$t.on
)/_@?ample,)&T .Ta215 STR)&K sT.tle5 STR)&K sOnMessa2e5 STR)&K
sO88Messa2e0
// )8 Ta21 .s on t%en d.spla3 ROnS popup
)/ .Ta21 = 1 T9@&
Messa2e,sT.tle 5 sOnMessa2e 5A40
@<S@
// Ta2 .s 0 ! d.spla3 RO88S Popup
Messa2e,sT.tle 5 sO88Messa2e 5A40
// @nd o8 )/ statement
@&4
// @nd o8 /un$t.on
@&4
%O0 Loop

Execte statements a nmber of times


/OR var.aHle = e?press.on1 TO e?press.on 4O
Statements ;
@&4
1ariable used
as counter
Start Count
1alue
End Count
1alue
Count
E+p&
8
8
88
8
8
E+p9
Statements
"leep & "leep4"
// Sleep 8or 1 se$ond
Sleep,10
// Sleep 8or 500 m.ll.se$onds
SleepMS,5000
%O0 Loop

Execte statements a nmber of times


/F&*T)O&
)n$rement<evel,0
// *ounter .s an )nte2er
)&T *ounter ;
// Set *ounter to $ount 10 levels
/OR *ounter = 0 TO T 4O
// 1dd 1 to $ounter
Ta2U = ta2U + 1;
Sleep,0;
// @nd o8 /OR loop
@&4
@&4
/F&*T)O&
/OR_@?ampleU,0
)&T *ounter;
)&T .SP;
)&T .P+;
.SP = <)*_#alan$e_SP;
.P+ = <)*_#alan$e_P+;
Fse sleep,10 to dela3 t%e loop

+ncrease L+C@Balance@#,
/F&*T)O&
/OR_@?ample1,0
)&T *ounter;
)&T .SP;
)&T .P+;
.SP = <)*_#alan$e_SP;
.P+ = <)*_#alan$e_P+;
/OR *ounter = .P+ TO .SP V 1 4O
<)*_#alan$e_P+ = <)*_#alan$e_P+ + 1;
SleepMS,"000;
@&4
@&4

(ecrease L+C@Balance@#,
/F&*T)O&
/OR_@?ample,0
)&T *ounter;
)&T .SP;
)&T .P+;
.SP = <)*_#alan$e_SP;
.P+ = <)*_#alan$e_P+;
/OR *ounter = .SP TO .P+ V 1 4O
<)*_#alan$e_P+ = <)*_#alan$e_P+ V 1;
SleepMS,"000;
@&4
@&4
/F&*T)O&
/OR_@?ample",0
)&T *ounter;
)&T .SP;
)&T .P+;
.SP = <)*_#alan$e_SP;
.P+ = <)*_#alan$e_P+;
)/ <)*_#alan$e_P+ Q <)*_#alan$e_SP T9@&
/OR *ounter = .SP TO .P+ V 1 4O
<)*_#alan$e_P+ = <)*_#alan$e_P+ V 1;
SleepMS,"000;
@&4
@<S@
/OR *ounter = .P+ TO .SPV1 4O
<)*_#alan$e_P+ = <)*_#alan$e_P+ + 1;
SleepMS,"000;
@&4
@&4
@&4
$'+LE Loop

Execte statements !.ile condition is tre


=9)<@ @?press.on 4O
Statements ;
@&4
=9)<@ Tr.22er 4O
*ount = *ount + 1 ;
Sleep,10 ;
@&4

(ecrement L+C@Balance@#, !.ile #mp@%eed@C4( is tre

"et L+C@Balance@#, to *CC !.en #mp@%eed@C4( is false


/F&*T)O&
=9)<@_@?ample1,0
=9)<@ Pump_/eed_*M4 = 1 1&4 <)*_#alan$e_P+ Q 0 4O
<)*_#alan$e_P+ = <)*_#alan$e_P+ V1;
SleepMS,5000;
@&4
<)*_#alan$e_P+ = 100
Pump_/eed_*M4 = 0 >opt.onal
@&4
"elect Case "tatement

Exectes one of a c.oice of statements


S@<@*T *1S@ E*p0ession
*1S@ #aseE*p0ession19#aseE*p0ession2
Statements "
*1S@ #aseE*p0ession3 TO #aseE*p0ession4
Statements ;
*1S@ )S 4 #aseE*p0ession5 5 )S 3 #aseE*p0ession:
Statements ;
*1S@ @<S@
Statements ; > not%.n2 sat.s8.ed
@&4 S@<@*T
Case Expressions
Case =e9word Description 12ample
3none4 Expression H
i-est,ale
D4ondayE
, 4ltiple discrete matc.es F, L, I
i-est,ale; i-est,ale*
DapplesE; DorangesE
(O "pecifies inclsive range of
vales7 "maller vale placed
before -O 2ey!ord7
F (O i-est,ale
DapplesE (O DorangesE
D%ridayE (O DfridayE
6. Use !it. W;X;WB;XB;B;WX 6. +**K
6. , i-est,ale
6. + Dc.erriesE
1>.1 QCatc.er1 for !.en no ot.er Case
clase matc.es
/F&*T)O&
=%at4a3)s)t,0
S@<@*T *1S@ 4el.ver3_4a3
*1S@ 0
M)S* = -SF&41L-;
*1S@ 1
M)S* = -MO&41L-;
*1S@
M)S* = -TF@S41L-;
*1S@ "
M)S* = -=@4&@S41L-;
*1S@ 4
M)S* = -T9FRS41L-;
*1S@ 5
M)S* = -/R)41L-;
*1S@ A
M)S* = -S1TFR41L-;
*1S@ @<S@
Messa2e,- )nval.d -5'&ot a val.d numHer-5A40;
@&4 S@<@*T
@&4
C.apter H ) "mmary 8estions

$.at are t.e t!o formats of t.e +% statement=

$.y is t.e %O0 loop sed=

$.y is t.e $'+LE loop sed=

$.ic. statement is sed to execte one of several


grops of statements; depending on t.e reslt of an
expression=1
Conditional Exectors
C.apter "mmary

+% statement

%O0 loop

$'+LE loop

"ELEC- CA"E statement


4ore Cicode %nctions
Chapter ?
4ore Cicode %nctions
Chapter Overview

0etrn %nctions

Cicode Arrays

Comments
0etrn %nctions
0etrn fnctions retrn data to calling fnction
9o71reLou,0
R@TFR&,') am 8.ne(0
0etrn %nctions

4st declare t.e retrning (ata type


!unction Called
E-aluate
Statements : store
in memory
Result returned
: Stored in Tag
or 1ariable
%nctions 0etrning ,ales

0etrn ,ales
'U()%#
)&T
FUN#$%&N
7etu0nE*amp+e!
(+a;"
7etu0n3!"
END

0etrn ,ales
'U()%#
STR)&K
FUN#$%&N
#u00ent7ecipe!
(+a;"
7etu0n<Fu++ #0eam
=i+>?!"
END
Data
Type
returned
Data
Type
returned
Create Function
/F&*T)O&
1vera2e@?1,0
T)*_P_P+ = ,T)*_P1_P+ + T)*_P4_P+0 /
@&4
'eturn Function
)&T > return data t3pe .s )nte2er
/F&*T)O&
1vera2e@?,0
R@TFR& ,T)*_P1_P+ + T)*_P4_P+0 / > return
e?press.on
@&4

Create Function @ %verage12334


)&T
/F&*T)O&
1vera2e@?",%N$ i$a1@5 %N$ i$a1A0
7E$U7N ,i$a1@ + i$a1A0/2
END

Change Operator6nput34 to a 'eturn /unction


)&T
/F&*T)O&
@nterTa2+alue,0
S$7%N. s$a1
s$a1=%nput,BEN$E7B5BEnte0 a 8a+ueB5BB0"
R@TFR& St0$o%nt,s$a10"
END
Bgs Y #art *
CC 7etu0n t;e a0ea o6 a ci0c+e into 'iDDaEA0ea 1i8en t;e
CC 0a-ius in 'iDDaESiDe
CC Note t;e use o6 +oca+ 8a0ia/+es an- -ata/ase 8a0ia/+es
FUN#$%&N
A0eao6'iDDa!

0A0ea = pi!F '&G'iDDaESiDe92!"
'iDDaEA0ea = 0A0ea"
END
Bgs Y #art *; Ans!ers
CC 7etu0n t;e a0ea o6 a ci0c+e into 'iDDaEA0ea 1i8en t;e
CC 0a-ius in 'iDDaESiDe
CC Note t;e use o6 +oca+ 8a0ia/+es an- -ata/ase 8a0ia/+es
FUN#$%&N
A0eao6'iDDa!
real r1rea;
0A0ea = pi!F '&G'iDDaESiDe92!"
'iDDaEA0ea = 0A0ea"
END
:hat a'out PiIIa6$rea ; PiIIa6iIeJ
Pro'a'ly a Varia'le tag or a glo'al .aria'le1 <udging 'y the usage
Bgs Y #art /
CC $;is 6unction Hi++ con8e0t t;e -iamete0 o6 t;e 8a0ia/+e
CC ta1 60om inc;es to centimet0es
CC $;is is a 7E$U7N 6unction.
FUN#$%&N
%nc;$o#ent7EA) a!
7EA) 0#ent
0#ent=aF2.54
END
Bgs Y #art /; Ans!ers
CC $;is 6unction Hi++ con8e0t t;e -iamete0 o6 t;e 8a0ia/+e
CC ta1 60om inc;es to centimet0es
CC $;is is a 7E$U7N 6unction.
R@1<
FUN#$%&N
%nc;$o#ent7EA) a!
7EA) 0#ent"
0#ent=aF2.54"
R@TFR&,r*@&T0
END
Bgs Y #art F
CC S;oH t;e 8a+ue o6 'iDDaEA0ea on t;e p0ompt +ine.
FUN#$%&N
'0ompt'iDDa7EA) 07ea+,a+ue!
'0omptB$;e a0ea o6 t;e 'iDDa is B + 07ea+,a+ue!"
S+eep3!"
'0omptBB!"
END
Bgs Y #art F; Ans!ers
CC S;oH t;e 8a+ue o6 'iDDaEA0ea on t;e p0ompt +ine.
FUN#$%&N
'0ompt'iDDa,7EA) 07ea+,a+ue0
'0omptB$;e a0ea o6 t;e 'iDDa is B +
RealToStr,rReal+alue5A5"0!"
S+eep3!"
'0omptBB!"
END
$lternateK EEEP.WWa .s ; + rReal+alueCDDEDDD0
Arrays
Arrays .old e<ally)siAed data elements; of t.e same data type7 +ndividal
elements are accessed by index sing a consective range of integers
)&T 1partmentM4N
Fn.t 1 6 1partmentM0N
Fn.t # 6 1partmentM1N
Fn.t * 6 1partmentMN
Fn.t 4 6 1partmentM"N
A .
C D
CndexL0M
CndexL,M
CndexL2M
CndexL&M
Arrays
)&T M31rra3M10N
)&T *ount ;
/or *ount = 0 to T do
M31rra3M*ountN=*ount+1 ;
@&4
+nitialising an Array
STR)&K 1rra3M5N='T%.s(5(.s(5(a(5(str.n2(5(arra3(;

Array is satisfied as?


A00a2I0J=<$;is?
A00a2I1J=<is?
A00a2I2J=<a?
A00a2I3J=<st0in1?
A00a2I4J=<a00a2?
Array (imensions

Arrays can .ave more t.an one dimension


6&( #9%rra9ADim$.iBeCADim2.iBeCADim3.iBeC * Dalues ;
STR)&K Str1rra3M5N ; > <.st
R@1< ResultM5NMN ; > V4 TaHle
)&T )nt1rra3M4NM"NMN ; > "V4 TaHle
Using Arrays

Arrays are declared as 4odle or Global


9cannot be declared locally:

#laced at t.e beginning of a Cicode file

(o not exceed t.e bonds of t.e array

Yo cannot pass an entire array into a


Cicode fnction

Assign text description to nmeric -ag


STR)&K sRe$.pe1rra3M5N = '/ull *ream-5 '<.te-5 'Sport-5 'S;.m-5 '9.2% prote.n-;
STR)&K /F&*T)O&
Re$.peSele$t.on,0
@&4
STR)&K sRe$.pe1rra3M5N = '/ull *ream-5 '<.te-5 'Sport-5 'S;.m-5 '9.2%
prote.n-;
STR)&K
/F&*T)O&
Re$.peSele$t.on,0
STR)&K sRe$.pe;
)&T .Re$.pe;
sRe$.pe = )nput,-Re$.pe &umHer-5-@nter a numHer Het7een 0 and
4-5--0;
.Re$.pe = StrTo)nt,sRe$.pe0;
S@<@*T *1S@ .Re$.pe
*1S@ 0 TO 4
R@TFR& sRe$.pe1rra3M.Re$.peN;
*1S@ @<S@
Messa2e,-@rror-5-&ot a val.d numHer-5A40;
@&4 S@<@*T
@&4
Comments

Comment ;Comment and Comment again


> S.n2le <.ne *omment
/un$t.on,0
/G
Mult.ple <.ne $omments
*an e?tend over several l.nes
@nd $omment Hlo$; 7.t% a del.m.ter
V *annot He started on t%e same l.ne as a statement
G/
/un$t.on,0
// 1not%er st3le o8 $omment
// #e2.n ea$% l.ne 7.t% 8or7ard slas%es
C.apter G ) "mmary 8estions

$.at does a retrn fnction do=

$.at is an Array=

$.y s.old comments be inclded in all Cicode


files=
4ore Cicode %nctions
C.apter "mmary

0etrn fnctions

(ebgging code

Arrays

Comments
Cicode (ebgger
Chapter E
Cicode (ebgger
Chapter Overview

"tarting t.e (ebgger

(ebg Options

(ebg yor Code


Citect &ernel

Covered in +ntermediate Corse

Core of t.e ,ijeo Citect system

Lo!)level diagnostic and debgging

Use !it. extreme care

"ecre access Y over)rides all ot.er secrity


measres

Command Line interface


Cicode Editor in (ebg 4ode

Open (ebg -oolbar

0ig.t)Clic2 on blan2 area of


toolbar

Open and test #iAAa page


Toggle 3rea-points
%ind Errors
%rom
4ev/.nd,%4ev5sP.WWa&umHer5(&FM#@R(0 ;
-o
4ev/.nd,%4ev5sP.WWa&umHer5(&FM(0 ;

Advanced "tepping
C.apter I ) "mmary 8estions

Explain debg mode7

-.ere are t.ree tools to control stepping t.rog.


fnctions7 $.at are t.ey=
Cicode (ebgger
C.apter "mmary

Cicode editor environment

Advanced stepping
(id !e Ac.ieve t.e Objectives=

Good Understanding & Competent in Use of


Cicode

Be Able to Use Cicode in Commands and


Expressions

Apply Learning to Yor O!n "ite or #roject

Be Able to $rite Yor O!n Cicode %nctions

&no! 'o! to (ebg Yor O!n Cicode


%nctions
"CA(A -raining 0oadmap
4pgrade ;
"e% (eatures
"et%or-ing ;
$rchitecture
Custo*isation
; 8esign
Cicode
Progra**ing
Vi<eo Citect
Con)iguration
T
e
c
h
n
i
c
a
l

-
i
l
l

#
e
!
u
i
r
e
*
e
n
t
End of Corse

8estions

Certificates

CC"E Certification

Corse evalation

!!!7citect7com3evalation

You might also like