Centric features In this presentation… –macro capabilities more sophisticated functionality...

Preview:

Citation preview

centric features

• In this presentation…– macro capabilities

• more sophisticated functionality

– advanced macro features• Inspector• Debugging• error trapping• printing macros• structures and user defined types

– all features discussed in this session are also available with newlook developer (ND)

Advanced Macro Programming

• inspector

– access to variables, objects and properties– read and modify access– remove variables– value and type information– arrays and collections– watch important values

Advanced Macro Programming

• inspector

– All window

Advanced Macro Programming

• inspector

– Auto window

Advanced Macro Programming

• inspector

– Watch window

Advanced Macro Programming

• debugging

– control and inspect execution– breakpoints– macro context list– observe execution of code even without errors

Advanced Macro Programming

• types of problems

– error conditions– invalid input– macro logic errors

Advanced Macro Programming

• breakpoints

– breakpoints halts the execution of a macro or script and gives you a snapshot of its condition at any moment.

– variables and properties can be inspected to analyze the current state.

– variables and property values can be changed to alter the execution of the macro or script.

Advanced Macro Programming

• breakpoints allow you to:

– observe the condition of the user interface. – determine which active macros/scripts have been

called. – watch the values of variables, properties, and

objects. – change the values of variables and properties. – view which action the macro or script will run next.

Advanced Macro Programming

• breakpoints occur when:

– execution reaches a line with a breakpoint– you choose Break from the Run menu– you click the Break button on the toolbar– a break expression defined in the Add Watch dialog

box changes

Advanced Macro Programming

• debugging toolbar

– debugging mode• turn on or off the debugging features. When debugging

mode is turned off breakpoints do not cause execution to halt.

– start• begin execution from current location and proceed until

next breakpoint is reached.

Advanced Macro Programming

• debugging toolbar

– break• halt execution at the macros current location.

– end• terminate execution of the current macro/script at its

current location.

Advanced Macro Programming

• debugging toolbar

– step into• continue execution by executing the next statement

and move into the next macro/script being called.

– step over• continue execution by executing the next statement

and move over the next macro/script being called.

Advanced Macro Programming

• debugging toolbar

– step to cursor• continues execution of the current macro/script until it

reaches the current cursor position.

– toggle breakpoint• turns on or off the breakpoint at the current cursor

position.

Advanced Macro Programming

• debugging toolbar

– clear all breakpoints• clears any breakpoints currently set

– show next action• displays the next action to be executed.• the editor will display the action with the cursor located

at the statement.

Advanced Macro Programming

• debugging toolbar

– add watch• add a variable, object or property to the Watch window

to allow its current value to be seen.

– context list• while in break mode, presents a dialog box that shows

all macros that have been called but not yet run to completion.

Advanced Macro Programming

• debugging toolbar

Advanced Macro Programming

• context list

– displays the call stack.– shows all macros that have been called to get to this

execution point.– allows you to easily select the macros calling the

current macro to analyze their program logic.

Advanced Macro Programming

• error trapping

– handling of error conditions.– actions to set error handlers, raise errors or resume

execution.– error handler is called if an error is encountered in

the macro when running.– default run-time error dialog if no error handler is

set.

Advanced Macro Programming

• OnError macro action

– used to set or clear the error handler.– error handlers can be nested.– default handling displays run-time error dialog.– error handler should test or copy the Err object

properties before another error could be triggered.

Advanced Macro Programming

• OnError macro action

– Arguments• label

name of location to execute if a macro error occurs.

blank label disables the error handler.

error handler automatically disabled when macro terminates.

Advanced Macro Programming

• Resume macro action

– used to resume execution of a macro after a run-time error has been handled.

– special value of Next to resume at the statement after the one that triggered the error.

– other values allowed to resume at other points.

Advanced Macro Programming

• Resume macro action

– Arguments• label

name of location to execute if a macro error occurs.

Next value behavior depends upon whether the handler is in the same macro as where the error was triggered.

Advanced Macro Programming

• Raise macro action

– Arguments• Number

error number to be raised.

• Descriptiontext description to be displayed in error dialog.

Advanced Macro Programming

• Raise macro action

– generates a run-time error.– can be called from error handler or from general

macros.

Advanced Macro Programming

• Err object

– used to provide information about a run-time error.– only valid when a error handler is executing.– read-only but Raise can be used to set errors.– property of the App object.

Advanced Macro Programming

• printing macros

– debugging– education– versioning

– clipboard can also be used to bring macro contents across to another application (such as notepad)

• printing macros

Open DBConnect (SampleConnection, DBServerDDM, ="Network Address=" & NetworkAddress & ";Network

Port=447;Use Encryption for Data=False;Host CCSID=37;Mode=ReadWrite|ShareDenyNone;Isolation Level=ReadCommitted;Process Binary as Character=True")

DBOpen (SampleRecordset, SampleConnection, /QSYS.LIB/QGPL.LIB/QAFCTUTDBF.FILE/DBFILE1.MBR,

DBUseServer, DBOpenForwardOnly, DBLockReadOnly, DBCmdUnknown)RunMacro (Sample - Database actions.First, , )StopMacro

Close DBClose (SampleRecordset)DBDisconnect (SampleConnection)StopMacro

Advanced Macro Programming

Advanced Macro Programming

• user defined types

– structures.– database records.– Call, RPCCall and WebCall

Advanced Macro Programming

• predefined data types

– Byte– Boolean– Integer– Long– Single– Double– String– String *– WString– WString *

Advanced Macro Programming

• Type macro action

– used to describe a user defined data type.– can have one or more elements.– multiple element data types are referred to as

structures.– described using predefined data types.

Advanced Macro Programming

• Type macro action example

Type (MyType, Code as Long, Description as String * 32)

Advanced Macro Programming

• Dim macro action

– declares a variable and allocates storage.– convention is to put Dim actions at the beginning of

the macro.– variable type can be a pre-defined type or a user

defined type.– typically used in conjunction with the Type action

and is not usually required for variable creation within macros.

Advanced Macro Programming

• Dim macro action example

Dim (MyVariable, MyType)

Advanced Macro Programming

• referencing fields

Type (MyType, Code as Long, Description as String * 32)

Dim (MyVariable, MyType)SetValue (MyVariable.Code, 99)SetValue (MyVariable.Description, "Undefined error!")

Advanced Macro Programming

• referencing fields

Advanced Macro Programming

• Call example

– Type (WIN32_FIND_DATA, dwFileAttributes as DWORD,ftCreationTimeLow as DWORD, ftCreationTimeHigh as DWORD,ftLastAccessTimeLow as DWORD,ftLastAccessTimeHigh as DWORD,ftLastWriteTimeLow as DWORD,ftLastWriteTimeHigh as DWORD,nFileSizeHigh as DWORD,nFileSizeLow as DWORD,dwReserved0 as DWORD,dwReserved1 as DWORD,cFileName as String * 260,cAlternateFileName as String * 14)

Advanced Macro Programming

• Call example

– Declare (C:\Winnt\System32\Kernel32.dll, FindFirstFileA, , Long, ByVal lpFileName as String, ByRef lpFindFileData as WIN32_FIND_DATA)

– Dim (FindFileData, WIN32_FIND_DATA)– Call (FindFirstFileA, fldFileName,FindFileData, iResult)

Advanced Macro Programming

• RPCCall example

– Type (InfoTable2, p1 as String * 10, p2 as String * 1, p3 as String * 1, p4 as Long, p5 as String * 20)

– Type (ChridReceiver, p1 as Long, p2 as Long, p3 as InfoTable2)

– Dim (VarChrid, ChridReceiver)

Advanced Macro Programming

• RPCCall example

– RPCDeclare (Connection1, QSYS, QWCRSVAL, QuerySystemChar, , Output prmRetVar as ChridReceiver, Input prmRetVarLen as Long, Input prmNumofValues as Long, Input prmValueName as String * 10, InputOutput prmError as String)

– RPCCall (Connection1, QuerySystemChar, VarChrid, 44, 1, "QCHRID", fldError, )

centric 8 Training

Workshop 1

Recommended