CATIA macro syntax is defined as the ordering of and relationship between the words and other structural elements in phrases and sentences. You can think of it as a particular layout of words and symbols. Each scripting language is composed of its own syntax. Learning the syntax of each programming language is crucial to creating successful macros. Think of it like this: when you see an email address (email@example.com) you immediately identify it as an email address. Why is this? An email address has a correct structure in the language of the internet, its syntax. Syntax enables the programming language to understand what it is you are trying to do. Listed below are some of the key syntax features of CATIA macro programming:
Case Sensitivity: By default, VBA is not case sensitive and does not differentiate between upper-case and lower-case spelling of words.
Comments: Add comments to your statements using an apostrophe (‘), either at the beginning of a separate line, or at the end of a statement. It is recommended that you add comments wherever possible to make your scripts easier to understand and maintain, especially if another user has to make changes to it later on down the road.
Indentation: Indent or out dent script to reflect the logical structure and nesting of the statements to make it easier to read.
Parentheses: To achieve the desired result and to avoid errors, it is important to use parentheses correctly in any statement.
Semicolon (:):Inserting a semicolon allows you to write multiple commands on the same line of code.
Single Quotation(‘): To return a single quotation mark which does not indicate a comment needed in a formula for example, you’ll have to use the Chr function. Chr() is a built-in VBA function that returns the character that corresponds to the numeric value of its argument, using the ASCII coding scheme. If you provide Chr with an integer value (such as 39) it will report back the character that corresponds to that value. The ASCII value of 39 is the single quote mark. Chr(34) is for the double quote mark. This is shown in an example later on in this text.
Spaces: Add extra blank spaces to your script to improve clarity. These spaces are ignored by VBA.
Text Strings: When a value is entered as a text string you must add quotation marks before and after the string. You can concatenate, or combine, multiple strings using a plus (+) or ampersand (&) sign: txtString = “This value is “+ TestValue. Return the left, middle, or right of a string using: left(sting, digits), mid(string, digits), or right(string, digits). Get the complete length of a string with len(string). To figure out if a string contains another string use Instr(). Convert numeric strings and vice versa using str(num) or val(string).
Underscore(_): Carry over to next line (line concatenation symbol)
Syntax is often the biggest cause of a macro program giving an error and not working. There is a correct way to write your code. It takes practice, patience, and persistence to understand but over time it will become second nature to you. If you follow the rules the programming languages will understand you otherwise you will get errors.
Dealing with syntax can be tough which is why programmers have developed tools to help create programs correctly. These are called IDE, or integrated development environments (remember that definition I defined earlier?). The Visual Basic editor in CATIA is the perfect example (Alt+F11). It contains a built-in syntax checker and works much like a grammar checker found in software like Microsoft Word and will even give you hints about what it thinks you meant.
Go back to CATIA macro languagues.