CodeCompletion
- Updated2024-09-12
- 4 minute(s) read
DIAdem SCRIPT > CodeCompletion
CodeCompletion
CodeCompletion is the automatic display of a list of objects, commands, and procedures. If you press <Ctrl-Spacebar>, DIAdem displays all the objects, commands, and procedures that are available at this point in the script. If you enter characters and press <Ctrl-Spacebar>, DIAdem completes the identifier if the identifier is unique. Otherwise DIAdem displays the selection list. If you enter a dot behind the name of an object, DIAdem displays a list of all the properties and methods that this object supports. DIAdem uses different symbols for methods and properties. The CodeCompletion of methods also displays their parameters with their data types. If the properties or methods have a return value, DIAdem also displays the return value type.
You can select methods and properties from the CodeCompletion list and insert them in the editor. If you enter the dot and DIAdem displays the list, and you enter the beginning of the term, DIAdem automatically selects the first matching element in the list. You can use the increment/decrement arrow buttons to move up and down in the list. If you press the enter key, DIAdem inserts the selected entry.
DIAdem supports CodeCompletion for all global objects such as View, Report, Navigator, Portal, Data, UnitCatalog, and BarManager, and their subobjects. Click the Contents tab in the DIAdem Help and select Programming Reference»Object-Oriented Script Interfaces for an overview of the object-oriented interfaces.
Some of the object-oriented interfaces are polymorphic. The object that is returned by a method or by a property is not unique. For example, the object returned by View.ActiveSheet.ActiveArea.DisplayObj can return the various display types in VIEW. Because the script editor does not know which object is meant, DIAdem displays a list of valid object types. After you select an object type from the list, the editor displays the CodeCompletion list of valid methods and properties for this object type.
You can also use the Set statement in scripts to use a variable to refer to an object in an object-oriented interface in DIAdem. DIAdem offers CodeCompletion also for objects that you define in this way. In DIAdem scripts, CodeCompletion supports DIAdem objects and also other objects that you assign with the Set statement and the CreateObject function. For some components you must also register the related components in the dialog box Registered Type Libraries. DIAdem does not offer CodeCompletion for objects you assigned with the GetObject function. In the following example DIAdem displays the CodeCompletion list when you enter a dot after oMySheets or oMySheet.ActiveArea.
Dim oMySheet Set oMySheet = VIEW.ActiveSheet oMySheet.ActiveArea
In the following example DIAdem displays the CodeCompletion list when you enter a dot after oMySpeech . To enable this, the required API must be installed and registered on your system.
Dim oMySpeech Set oMySpeech = CreateObject("SAPI.SpVoice") Call oMySpeech.Speak("Hello World!")
DIAdem also provides CodeCompletion in For Each...Next statements. The loop must be complete, which means the loop must also contain the Next statement. In the following example DIAdem displays the CodeCompletion list when you enter a dot after oMyArea in the Call MsgBoxDisp(oMyArea.SplitLeft) line.
Dim oMyArea For Each oMyArea in VIEW.ActiveSheet.Areas Call MsgBoxDisp(oMyArea.SplitLeft) Next
If you use the Set statement to assign multiple objects to a variable in a procedure, DIAdem uses the first object definition to create the CodeCompletion list. Multiple object definitions can be useful in branches, for example. DIAdem interprets these definitions only in a procedure for CodeCompletion and does not provide CodeCompletion for these definitions in other procedures, even if you transfer these objects as function parameters.
If an object has the standard element Item, you generally do not need to specify this element. DIAdem also recognizes the syntax in this case, and displays the CodeCompletion list. That means that in the following example you do not need to enter Sheets.Item(1):
Dim oMyArea set oMyArea= VIEW.Sheets(1).ActiveArea
If a method expects an argument and returns a collection, DIAdem does not know whether the expression in parentheses is the argument or the standard element Item. In this case, you must enter Item to get a CodeCompletion list.
In the following example, DIAdem cannot interpret the syntax correctly. If you enter the standard element Item, the expression is easier to read and DIAdem can also display the correct CodeCompletion list:
Navigator.Display.CurrDataFinder.QueryForm.GetIndexedProperties(eSearchFile)(1) Navigator.Display.CurrDataFinder.QueryForm.GetIndexedProperties(eSearchFile).Item(1)
If you define a class in a script, you can use CodeCompletion for this class.
If you use the same method name for different classes and transfer an object to this method, CodeCompletion might work incorrectly within the class. The following example defines, in two classes the Add method. In the main script the VIEW object is transferred to the Add method of the MyFirstClass class. If you edit the Add method of the MyFirstClass class in the script editor, DIAdem displays the correct CodeCompletion. Because the MySecondClass class also uses the Add method name, DIAdem cannot differentiate these two methods and therefore also displays CodeCompletion for VIEW. If you use a different method name, for example, the name Add_2 in the MyThirdClass class, DIAdem displays the correct CodeCompletion in the script.
Dim MyClass1, MyClass2, MyClass3 Set MyClass1 = new MyFirstClass MyClass1.Add(VIEW) Set MyClass2 = new MySecondClass MyClass2.Add(Data) Set MyClass3 = new MyThirdClass MyClass3.Add_2(Data) Class MyFirstClass Public Sub Add(MyPara) MyPara 'CodeCompletion for the VIEW object End Sub End Class Class MySecondClass Public Sub Add(MyPara) MyPara 'Wrong CodeCompletion for the VIEW object End Sub End Class Class MyThirdClass Public Sub Add_2(MyPara) MyPara 'Correct CodeCompletion for the Data object End Sub End Class
Related Topics
Command: ScriptCMDRegister | Method: CreateObject for VBS | Method: GetObject for VBS | Registered Type Libraries