CitectVBA Reference Guide
CitectVBA Reference Guide
10
CitectVBA Reference Guide
November 2008
Legal Notice
DISCLAIMER
Schneider Electric makes no representations or warranties with respect to this manual and, to the maximum
extent permitted by law, expressly limits its liability for breach of any warranty that may be implied to the re-
placement of this manual with another. Further, Schneider Electric reserves the right to revise this publication
at any time without incurring an obligation to notify any person of the revision.
COPYRIGHT
Copyright 2009 Schneider Electric (Australia) Pty Ltd All rights reserved.
TRADEMARKS
Schneider Electric has made every effort to supply trademark information about company names, products
and services mentioned in this manual.
Citect, CitectHMI, and CitectSCADA are registered trademarks of Schneider Electric (Australia) Pty Ltd.
IBM, IBM PC and IBM PC AT are registered trademarks of International Business Machines Corporation.
MS-DOS, Windows, Windows NT, Microsoft, and Excel are either registered trademarks or trademarks of Mi-
crosoft Corporation in the United States and/or other countries.
DigiBoard, PC/Xi and Com/Xi are trademarks of Digi International Inc.
Novell, Netware and Netware Lite are are either registered trademarks or trademarks of Novell, Inc. in the
United States and other countries..
dBASE is a trademark of dataBased Intelligence, Inc.
All other brands and products referenced in this document are acknowledged to be the trademarks or regis-
tered trademarks of their respective holders.
GENERAL NOTICE
Some product names used in this manual are used for identification purposes only and may be trademarks of
their respective companies.
November 2008 edition for Vijeo Citect Version v7.10
Manual Revision Version v7.10.
PLEASE NOTE
Electrical equipment should be installed, operated, serviced, and maintained only by qualified personnel. No
responsibility is assumed by Schneider Electric for any consequences arising out of the use of this material.
2008 Schneider Electric (Australia) Pty Ltd. All Rights Reserved.
Validity Note
The present documentation is intended for qualified technical personnel responsible for the implementation,
operation and maintenance of the products described. It contains information necessary for the proper use of
the products. However, those who wish to make a more "advanced" use of our products may find it necessary
to consult our nearest distributor in order to obtain additional information.
The contents of this documentation are not contractual and in no way constitute an extension to, or restric-
tion of, the contractual warranty clauses.
For further information contact your local Schneider Electric representative.
5
Contents
Legal Notice ......................................................................................................3
Contents ............................................................................................................5
Chapter: 1 Introducing CitectVBA..................................................................9
Safety Information ..........................................................................................10
Hazard categories and special symbols ................................................................................................. 10
Please Note ............................................................................................................................................ 11
Before You Begin.................................................................................................................................... 11
Chapter: 2 Integrating CitectVBA into your Project ...................................13
Accessing Cicode Tags with CitectVBA ................................................................................................. 13
Using CitectVBA in Command or Expression fields ............................................................................... 14
Accessing ActiveX Objects with CitectVBA ............................................................................................ 14
Multithread Considerations with CitectVBA ............................................................................................ 15
Calling CitectVBA from Cicode............................................................................................................... 16
Calling Cicode from CitectVBA............................................................................................................... 17
Chapter: 3 Using the CitectVBA Test Project..............................................21
Creating the Test Project ........................................................................................................................ 21
Opening the Test Project ........................................................................................................................ 22
Setting up Test Project Communications................................................................................................ 22
Setting up the Test Project Computer..................................................................................................... 23
Adding a Variable Tag ............................................................................................................................ 23
Adding a Graphics Page......................................................................................................................... 24
Saving Your Graphics Page ................................................................................................................... 24
Opening the Graphics Page ................................................................................................................... 24
Chapter: 4 Understanding CitectVBA Language Basics............................25
CitectVBA Files....................................................................................................................................... 25
Cicode Editor .......................................................................................................................................... 25
Scope of CitectVBA................................................................................................................................ 26
Procedural (local) level scope .......................................................................................................... 26
Modular level scope.......................................................................................................................... 26
Global level scope ............................................................................................................................ 26
CitectVBA Statements ............................................................................................................................ 27
Comments .............................................................................................................................................. 27
Header information........................................................................................................................... 28
Labels ..................................................................................................................................................... 28
CitectVBA Line Continuation Character.................................................................................................. 29
Naming ................................................................................................................................................... 29
Option Statements.................................................................................................................................. 30
Contents
6
Option Explicit statement.................................................................................................................. 30
Option Compare statement .............................................................................................................. 31
Option Base statement ..................................................................................................................... 31
CitectVBA Data Types............................................................................................................................ 32
Constants................................................................................................................................................ 32
Declaration of constants................................................................................................................... 33
Intrinsic constants............................................................................................................................. 34
Variables................................................................................................................................................. 35
Variable declaration.......................................................................................................................... 35
Variable initialization values ............................................................................................................. 36
Arrays of Variables ........................................................................................................................... 37
Variant Declaration........................................................................................................................... 41
Numbers ................................................................................................................................................. 42
Numeric Data Types......................................................................................................................... 43
Exponential Notation ........................................................................................................................ 44
Floating Point Calculation Rules....................................................................................................... 44
Rounding Numbers........................................................................................................................... 45
Date and Time Handling......................................................................................................................... 46
Date Constants................................................................................................................................. 47
Formatting Date Values.................................................................................................................... 48
Date and Time Data Constraints ...................................................................................................... 50
Date Data Type Structure................................................................................................................. 50
Date-values............................................................................................................................................. 51
Time-values...................................................................................................................................... 51
Dates in Databases Using Different Calendars................................................................................ 51
Operators................................................................................................................................................ 52
Assignment Operator........................................................................................................................ 53
Arithmetical (Math) Operators .......................................................................................................... 53
Relational Operators......................................................................................................................... 54
Logical Operators ............................................................................................................................. 54
Operator Precedence ....................................................................................................................... 54
Strings..................................................................................................................................................... 55
String Comparisons.......................................................................................................................... 56
String Concatenation........................................................................................................................ 56
Control Structures................................................................................................................................... 57
GoTo statement................................................................................................................................ 58
Do statement .................................................................................................................................... 58
While statement................................................................................................................................ 59
For statement ................................................................................................................................... 59
If statement....................................................................................................................................... 59
Select case statement ...................................................................................................................... 61
End statement .................................................................................................................................. 62
Exit statement................................................................................................................................... 63
OnError statement ............................................................................................................................ 63
Stop statement ................................................................................................................................. 63
With statement.................................................................................................................................. 64
Subroutines and Functions..................................................................................................................... 64
Subroutines ...................................................................................................................................... 65
Functions.......................................................................................................................................... 66
Arguments ........................................................................................................................................ 67
DLLs and APIs........................................................................................................................................ 69
Contents
7
Accessing Functions in DLLs ........................................................................................................... 69
Passing Arguments to DLL Functions from CitectVBA..................................................................... 72
OLE Services.......................................................................................................................................... 73
OLE terminology............................................................................................................................... 73
OLE automation objects ................................................................................................................... 74
Declaration of OLE automation objects............................................................................................ 75
Assigning references to OLE automation objects............................................................................. 75
Using OLE automation objects......................................................................................................... 76
Accessing the object model of OLE automation server applications................................................ 77
Understanding object models in OLE automation ............................................................................ 78
Using the Microsoft Word object model ............................................................................................ 80
OLE automation example using the Microsoft Word object.............................................................. 80
Using the Microsoft Excel object model............................................................................................ 81
Deleting OLE automation objects..................................................................................................... 81
File Input/Output with CitectVBA ............................................................................................................ 82
Chapter: 5 CitectVBA Function Reference..................................................83
Array Functions....................................................................................................................................... 83
Conditional Statements........................................................................................................................... 88
Conversion Functions............................................................................................................................. 94
ASCII character code conversion..................................................................................................... 94
Date conversion................................................................................................................................ 96
Date and time formatting/conversion................................................................................................ 99
Number and string conversion........................................................................................................ 100
Declarations.......................................................................................................................................... 108
Date and Time Functions...................................................................................................................... 119
DateValue....................................................................................................................................... 121
File I/O Functions.................................................................................................................................. 129
Math/Trigonometry Functions............................................................................................................... 155
Numeric functions........................................................................................................................... 155
Trigonometric functions .................................................................................................................. 160
Miscellaneous Functions ...................................................................................................................... 162
Procedural Statements ......................................................................................................................... 164
String Functions.................................................................................................................................... 174
Chapter: 6 ASCII/ANSI Character Code Listings ......................................187
Index ..............................................................................................................195
Contents
8
9
Chapter: 1 Introducing CitectVBA
CitectVBA is a Visual Basic for Applications (VBA) and VBScript-compatible Basic script-
ing language. Vijeo Citect has embedded support for CitectVBA.
CitectVBA has the following features:
- CitectVBA code is multithreaded and fully scheduled within the Vijeo Citect Kernel.
- CitectVBA uses the same well proven engine that Cicode uses and can be used wherever
Cicode is used.
- CitectVBA has a small footprint of under 400K.
- CitectVBA code is directly callable from Vijeo Citect Command and Expression fields.
- CitectVBA code is callable from Cicode and visa-versa.
- CitectVBA code provides native support for ActiveX objects, Vijeo Citect Variable Tags
and Alarm Tags.
- CitectVBA makes ActiveX object manipulating easier. It allows direct interaction with
the object models from 3rd party applications such as Word, Excel, etc.
Note: You may notice slight differences between CitectVBA and VBA in other applica-
tions; this is normal as each application has a different object model.
The Cicode Editor has been upgraded to fully support CitectVBA. New features of the ed-
itor include:
- Integrated Cicode and CitectVBA compiler
- Integrated Cicode and CitectVBA source code editor
- Integrated Cicode and CitectVBA debugger
See Also
Integrating CitectVBA with Vijeo Citect
Chapter: 1 Introducing CitectVBA
10
Safety Information
Hazar d cat egor i es and speci al sy mbol s
The following symbols and special messages may appear in this manual or on the product
to warn of potential hazards or to call attention to information that clarifies or simplifies a
procedure.
A lightning bolt or ANSI man symbol in a "Danger" or "Warning" safety label on the prod-
uct indicates an electrical hazard which, as indicated below, can or will result in personal
injury if the instructions are not followed.
The exclamation point symbol in a safety message in a manual indicates potential personal
injury hazards. Obey all safety messages introduced by this symbol to avoid possible injury
or death.
Sy mbol Name
Light ning Bolt
ANSI man
Exclamat ion Point
DANGER
DANGER indicat es an imminent ly hazardous sit uat ion, which, if not avoided, will
result in deat h or serious inj ury.
WARNING
WARNI NG indicat es a pot ent ially hazardous sit uat ion, which, if not avoided, can
result in deat h or serious inj ury.
CAUTION
CAUTI ON indicat es a pot ent ially hazardous sit uat ion which, if not avoided, can
result in minor or moderat e inj ury.
CAUTION
CAUTI ON, used wit hout t he safet y alert symbol, indicat es a pot ent ially hazard-
ous sit uat ion which, if not avoided, can result in propert y damage.
Chapter: 1 Introducing CitectVBA
11
Pl ease Not e
Electrical equipment should be installed, operated, serviced, and maintained only by qual-
ified personnel. No responsibility is assumed by Schneider Electric for any consequences
arising out of the use of this material.
Bef or e You Begi n
Vijeo Citect is a Supervisory Control and Data Acquisition (SCADA) solution. It facilitates
the creation of software to manage and monitor industrial systems and processes. Due to
Vijeo Citects central role in controlling systems and processes, you must appropriately de-
sign, commission, and test your Vijeo Citect project before implementing it in an operation-
al setting. Observe the following:
* For additional information, refer to NEMA ICS 1.1 (latest edition), "Safety Guidelines for
the Application, Installation, and Maintenance of Solid State Control".
WARNING
UNI NTENDED EQUI PMENT OPERATI ON
Do not use Vij eo Cit ect or ot her SCADA soft ware as a replacement for PLC- based
cont rol programs. SCADA soft ware is not designed for direct , high- speed syst em
cont rol.
Fai l ur e t o f ol l ow t hese i nst r uct i ons can r esul t i n deat h, ser i ous i nj ur y , or
equi pment damage.
WARNING
LOSS OF CONTROL
- The designer of any cont rol scheme must consider t he pot ent ial failure
modes of cont rol pat hs and, for cert ain crit ical cont rol funct ions, provide
a means t o achieve a safe st at e during and aft er a pat h failure. Examples
of crit ical cont rol funct ions are emergency st op and overt ravel st op.
- Separat e or redundant cont rol pat hs must be provided for crit ical cont rol
funct ions.
- Syst em cont rol pat hs may include communicat ion links. Considerat ion
must be given t o t he implicat ions of unant icipat ed t ransmission delays or
failures of t he link.
*
- Each implement at ion of a cont rol syst em creat ed using Vij eo Cit ect must
be individually and t horoughly t est ed for proper operat ion before being
placed int o service.
Fai l ur e t o f ol l ow t hese i nst r uct i ons can r esul t i n deat h, ser i ous i nj ur y , or
equi pment damage.
Chapter: 1 Introducing CitectVBA
12
13
Chapter: 2 Integrating CitectVBA into your Project
You can integrate CitectVBA into your Vijeo Citect project in two ways:
- Use CitectVBA code script directly in your Command or Expression fields within Vijeo
Citect.
- Store user-defined CitectVBA script in a separate CitectVBA file.
In either case, all procedures within a CitectVBA script can access (read and write) any
Vijeo Citect variable tag in the same way as Cicode can access Vijeo Citect tags.
See Also
Accessing Cicode Tags with CitectVBA
Accessing Cicode Tags with CitectVBA
CitectVBA can use your Vijeo Citect project variable tag and alarm tag variables in the same
way as could Cicode (except for syntax differences). Both programming languages refer to
a projects variable tags by using the name of the tags as defined in the project.
Note: Project variable tags are defined (in Vijeo Citect) by using the Variable Tags form in
the Citect Project Editor. For details, see Adding a Variable Tag.
For instance, in the following example, two variable tags in your Vijeo Citect project may
be named B1_PUMP_101_SP and B1_PUMP_101_PV respectively, representing the Set
Point and Process Variable values of Pump 101. These variable tag names can be used with-
in a CitectVBA statement (just as you would use any other variable in CitectVBA). Both val-
ues can be read-from and written-to directly using CitectVBA:
set pump speed to 500 rpm
B1_PUMP_101_SP = 500
calculate pump speed error
Dim varPumpSpeedError
varPumpSpeedError = B1_PUMP_101_PV - B1_PUMP_101_SP
You should note that CitectVBA does not recognize Vijeo Citect variable tags that are
named with an initial digit (0-9).
To access such tags using CitectVBA, you must precede the tag name with a case-insensi-
tive string containing the letters V, B, and the underscore character (VB_) as in the fol-
lowing example:
Vijeo Citect Tag Name: "123Pump"
CitectVBA reference "VB_123Pump"
For details about accessing ActiveX objects using CitectVBA, see Accessing ActiveX Objects
with CitectVBA. For details of using tags that have a number as their first digit in your Vijeo
Citect project, consider using the [General]TagStartDigit Citect.INIparameter.
See Also
Using CitectVBA in Vijeo Citect Command or Expression fields>Calling CitectVBA from
Cicode
Calling CitectVBA from Cicode
Chapter: 2 Integrating CitectVBA into your Project
14
Using CitectVBA in Command or Expression fields
Vijeo Citect expects that all code contained within a Vijeo Citect Command or Expression
field to be Cicode by default. When using CitectVBA code script directly in a Vijeo Citect
Command or Expression field within Vijeo Citect, you must precede the CitectVBA script
with the keyword CiVBA, as shown here:
CiVBA
TestTag_1 = TestTag_1 + 1
This is known as the language override command. When the Vijeo Citect compiler reads
the keyword CiVBA, it knows to handle that code (within the same Vijeo Citect Command
or Expression field) as CitectVBA script, and compiles it as such. No such override com-
mand is required to use Cicode.
The CiVBA language override statement must be placed first in the Vijeo Citect Command
or Expression field if you want to use CitectVBA script code instead of Cicode in that Vijeo
Citect Command or Expression field.
Note: You must use either Cicode or CitectVBA in a Vijeo Citect Command or Expression
field. You cannot change or swap between the two programming languages (within the
same Vijeo Citect Command or Expression field) once youve started using one or the oth-
er.
You can, however, call a single Cicode function from within CitectVBA script if you wrap
the Cicode call within special CitectVBA functions CicodeCallOpen()and CicodeCallRe-
turn(). For details, see Calling Cicode from CitectVBA.
Alternatively, to call a single CitectVBA function (from within the Vijeo Citect Command
or Expression field) after you have already used Cicode in that field, you can wrap the Ci-
tectVBA within three nested special Cicode functions: VbCallOpen(), VbCallRun()and Vb-
CallReturn(). See Calling Cicode from CitectVBA.
See Also
Accessing Cicode Tags with CitectVBA
Accessing ActiveX Objects with CitectVBA
Multithread Considerations with CitectVBA
Calling CitectVBA from Cicode
Calling Cicode from CitectVBA
Accessing ActiveX Objects with CitectVBA
ActiveX objects which have been added to a graphics page in your Vijeo Citect project can
be referred to in CitectVBA by constructing a unique reference name using the page name,
the underscore character, the letters AN, and the animation number of the object.
This reference name is called the Event Class name in Vijeo Citect. To view the reference
name, double-click the ActiveX object, select the Access tab, then click the Identification
tab.
Chapter: 2 Integrating CitectVBA into your Project
15
In this example, the reference name for the Temperature meter object would be referred to
in CitectVBA as ActiveX_AN125.
All object properties can be accessed and manipulated using CitectVBA in the same way
that object properties can be manipulated using Cicode.
See Also
Accessing Cicode Tags with CitectVBA
Using CitectVBA in Vijeo Citect Command or Expression fields
Multithread Considerations with CitectVBA
Cicode is pre-empted and executed on an instruction-by-instruction basis. This means that
execution of a simple unnested Cicode thread can only switch to another thread after the
current Cicode instruction has completed execution.
CitectVBA code is pre-empted and executed on a line-by-line basis (as opposed to an in-
struction-by-instruction basis), and pre-empting can only occur after the current line has
completed execution.
Each line of CitectVBA script is handled as a separate thread in Vijeo Citect. Therefore mul-
tiple procedures placed on one line may not complete before another subsequent thread is
processed in a multithreading environment. This could cause unpredictable results and
consequences, including data invalidation and corruption.
WARNING
UNI NTENDED EQUI PMENT OPERATI ON
-Creat e your Cit ect VBA program so t hat every code st at ement is posit ioned on a
unique line.
-Do not group more t han one code st at ement on a single line in your program.
Grouping Cit ect VBA st at ement s on a single line can cause dat a corrupt ion during
mult it hreaded execut ion.
Fai l ur e t o f ol l ow t hese i nst r uct i ons can r esul t i n deat h, ser i ous i nj ur y , or
equi pment damage.
Chapter: 2 Integrating CitectVBA into your Project
16
If, for example, you were reading or setting some variable or point in a multi-statement
thread, and further processing that data in a later thread,that data might become invalid or
incorrect. For this reason, you should separate every statement onto separate lines in Cit-
ectVBA.
For example, it is better to write:
A = Motor1.speed() + Motor4.speed() + Motor5.speed()
as
A = Motor1.speed()
A = A + Motor4.speed()
A = A + Motor5.speed()
in situations where the method speed()may take a long time to execute.
In the first example above, the CitectVBA thread executes for three times longer before it
can be pre-empted than in the latter example.
Note: This is not an issue with Cicode because the Cicode engine can pre-empt aggregated
code.
See Also
Accessing Cicode Tags with CitectVBA
Using CitectVBA in Vijeo Citect Command or Expression fields
Calling CitectVBA from Cicode
Calling Cicode from CitectVBA
Calling CitectVBA from Cicode
Three new Cicode functions allow CitectVBA code to be called from within Cicode script,
and be pre-emptively multitasked by Vijeo Citect. These calls VbCallOpen(), VbCallRun(),
and VbCallReturn()can be nested to implement the entire function set with a single line of
Cicode.
Note: When using the CiVBA language override in a Command field, the compiler con-
structs the nested call for you. The same mechanism is used even though it is not self evi-
dent. For details, see Using CitectVBA in Vijeo Citect Command or Expression fields.
For information on multithreading in CitectVBA, see Multithread Considerations with Ci-
tectVBA.
To call a given CitectVBA function or subroutine from Cicode, use the VbCallOpenfunction.
This returns a handle which can then be used to execute the call by passing it to the VbCall-
Runfunction. Upon return from VbCallRun, you can call the VbCallReturnfunction to get the
return value of the CitectVBA function called.
The Cicode VbCallOpen()function is used to initiate a call to the CitectVBA function or sub-
routine, and returns a handle to the open function.
<ReturnValue> = VbCallOpen(<FunctName>, <ArgList>)
where:
- <ReturnValue> represents the handle to the opened function.
- <FunctName> represents the name of the CitectVBA function or subroutine being called.
Chapter: 2 Integrating CitectVBA into your Project
17
- <ArgList> represents a comma separated list of arguments to pass to the opened Cit-
ectVBA function or subroutine named in <FunctName>.
The Cicode VbCallRun()function is used to execute the CitectVBA function or subroutine
(previously opened with the Cicode VbCallOpenfunction), and requires the handle returned
from the VbCallOpenfunction call. The VbCallRunfunction provides an opportunity for the
opened CitectVBA function to complete and return a value in the multi-threaded Vijeo Ci-
tect environment. It passes its argument value (of OBJECT data type) through as its return
value upon completion.
<ReturnValue> = VbCallRun(<CallHandle>)
where:
- <ReturnValue> represents the handle to the opened CitectVBA function passed through
for the <CallHandle>argument.
- <CallHandle> represents the handle to the previously opened CitectVBA function as re-
turned by the Cicode VbCallOpenfunction.
The Cicode VbCallReturn()function is used to obtain the return value of the completed Ci-
tectVBA function (previously opened with the Cicode VbCallOpenfunction), and requires
the handle returned from the VbCallRunfunction call.
<ReturnValue> = VbCallReturn(<CallHandle>)
where:
- <ReturnValue> represents the value returned by the completed CitectVBA function
(which was previously opened by the Cicode VbCallOpenfunction). The data type of the
return value is dependent upon the data type of the return value for the CitectVBA func-
tion opened.
- <CallHandle> represents the handle to the previously opened CitectVBA function as re-
turned by the Cicode VbCallRunfunction.
Example
FUNCTION
TestCitectVBA()
INT iRet;
STRING sMsg = "Hello";
INT iVal = 123;
iRet = VbCallReturn(VbCallRun(VbCallOpen("CiVBATest", iVal)));
Message("TestCitectVBA Function", "CiVBATest = " + IntToStr(iRet), 0);
END
Example
Function CiVBATest(Value As Integer) As Integer
CiVBATest = Value * 2
End Function
See Also
Calling Cicode from CitectVBA
Calling Cicode from CitectVBA
Calling a Cicode function from CitectVBA is accomplished by two CitectVBA functions:
CicodeCallOpen()and CicodeCallReturn().
Chapter: 2 Integrating CitectVBA into your Project
18
To call a given Cicode function, use the CicodeCallOpenfunction which will create and exe-
cute a Cicode thread that runs the function. For multitasking purposes, a separate function
CicodeCallReturnis used to obtain the return-value of the completed Cicode function most
recently called by the CicodeCallOpenfunction.
The return value is initialized when control is returned to the Vijeo Citect kernel. This oc-
curs only after completion of the line of CitectVBA code containing CicodeCallOpen. For de-
tails on multithreading in CitectVBA, see Multithread Considerations with CitectVBA.
To call a given Cicode function or subroutine from CitectVBA, use the CicodeCallOpenfunc-
tion. Upon return from CicodeCallOpen, you can call the CicodeCallReturnfunction to obtain
the return value of the Cicode function called.
The CicodeCallOpenfunction is a CitectVBA function used to call a Cicode function from Ci-
tectVBA. It is used to initiate and execute a call to the Cicode function and returns an inte-
ger value representing the success or the type of error encountered by the CicodeCallOpen
function.
<ReturnValue> = CicodeCallOpen(<FunctName>, <ArgList>)
where:
- <ReturnValue> represents the return value of:
- 0 if CicodeCallOpenfunction was successful
- 1 for CicodeCallOpenfunction general error
- 2 for specified Cicode function not found
- 3 for incorrect number of arguments for specified Cicode function passed in <Ar-
gList>.
- <FunctName> is a string representing the name of the Cicode function being called. The
function name should be enclosed in double quotes.
- <ArgList> represents a variable length comma separated argument list of all the argu-
ments to be passed to the Cicode function being opened (dependant upon which Cicode
function is being called and the arguments that Cicode function requires). The argu-
ment list should not be enclosed within brackets, although when using variable names
as arguments, those variable arguments within the list must be individually enclosed
within brackets to force the passing of the variable to Cicode by value.
The CicodeCallReturnfunction is a CitectVBA function used to obtain the return value of
the most recently completed Cicode function opened with the CitectVBA CicodeCallOpen-
function.
<ReturnValue> = CicodeCallReturn()
where:
- <ReturnValue> represents the return value of the Cicode function specified in the most
recent call of the CicodeCallOpenfunction. Note that the return data type of CicodeCall-
WARNING
UNI NTENDED EQUI PMENT OPERATI ON
Do not nest t he CicodeCallOpen and CicodeCallReturn funct ions. Nest ing
t hese funct ions can lead t o unint ended equipment operat ion when your program
is run.
Fai l ur e t o f ol l ow t hese i nst r uct i ons can r esul t i n deat h, ser i ous i nj ur y , or
equi pment damage.
Chapter: 2 Integrating CitectVBA into your Project
19
Returnwill depend upon the return data type of the Cicode function called in the most
recent call of the CicodeCallOpenfunction.
No arguments are passed to the CicodeCallReturnfunction, as it can only return the result
of the most recent return-value for the Cicode function called by the CitectVBA CicodeCal-
lOpenfunction.
Note:In the following example, a CitectVBA variable is enclosed in brackets to force the
passing of the variable by value. See Passing variables Byref and Byval.
CitectVBA
declare modular variant variable to store function results
Dim vntRet as Variant
Function TestCicode() As Integer
declare local variables
Dim intRet As Integer
Dim strReply as String
Dim intMaxScale as Integer
copy current tag value to variable
uses the project variable tag named MAX_SCALE
intMaxScale = MAX_SCALE
call Cicode function
for example: TrnSetScale( AN, Pen, Percent, Scale)
intRet = CicodeCallOpen( "TrnSetScale", 53, -1, 100, (IntMaxScale) )
Note the syntax used:
- brackets around the CitectVBA function argument list
(Only necessary when the CitectVBA function is preceded by an equals (=) sign .)
- double quotes around the Cicode function name
- no brackets around the Cicode function argument list
- brackets around individual variable arguments
test results
If intRet = 0 Then
vntRet = CicodeCallReturn()
strReply = "CicodeCallOpen Function successfully called"
Else