You must adhere to the following standard VBA naming conventions when naming iFIX pictures, schedules, objects, variables, modules, and procedures. You can find this information in the Help topics within the section Visual Basic Naming Rules of the Visual Basic for Applications Help file:
- You must use a letter as the first character.
- Names cannot exceed 255 characters in length.
- You should not use any names that are identical to the functions, statements, and methods in Visual Basic because you may shadow the same keywords in the language.
- To use an intrinsic language function, statement, or method that conflicts with an assigned name, you must explicitly identify it.
- Precede the intrinsic function, statement, or method name with the name of the associated type library. For example, if you have a variable called Right, you can only invoke the Right function using VBA.Right.
- You cannot repeat names within the same level of scope. For example, you cannot declare two variables named level within the same procedure. However, you can declare a private variable named level and a procedure-level variable named level within the same module.
- You cannot use a space, hyphen (-), period (.), exclamation mark (!), or the characters @, &, $, # in the name.
- You should not use an underscore (_) in the name. It may cause problems with scripting, because VBA uses underscores in the naming of scripts associated with objects.
- Pictures, schedules, Dynamo sets, toolbars, and toolbar categories require unique names so that the iFIX WorkSpace can load them simultaneously. This is true even though the file name extensions differ for different document types. The following scenarios illustrate this point:
- If you attempt to open a picture whose name conflicts with a document that is already open, you will not be able to open the picture. Instead, the following text appears:
NOTE: Visual Basic for Applications isn't case-sensitive, but it preserves the capitalization in the statement where the name is declared.
NOTE: If you have database tags that contain invalid VBA characters, such as hyphens, and you want to manipulate these tags through scripts, you can use two iFIX subroutines (ReadValue and WriteValue) to do so. You can learn more about the ReadValue and WriteValue subroutines in the section Optimizing Your VBA Project Development, or in the iFIX Automation Interfaces Electronic Book.
Another Schedule, Picture, Toolbar, or Dynamo Set with same name is already open.
- If you attempt to enable a toolbar whose name conflicts with a picture that is already open, the iFIX WorkSpace will not enable the toolbar.
- If you open a picture that has the same name as a toolbar category, and then either click the Buttons tab on the Customize Toolbars dialog box or run the Task Wizard, the iFIX WorkSpace will not display the toolbar category.
To correct naming conflicts for a picture:
- Close the picture.
- Rename the picture to a name that does not conflict with the other document.
- Close the conflicting Dynamo set, schedule, picture, or toolbar.
- Restart the WorkSpace.
- Open the renamed picture and save it.
Avoid naming an object, a picture, and a global subroutine with the same name, particularly if you refer to the object in a Visual Basic script. This ensures that VBA can distinguish between your objects and your subroutines. Otherwise, you may receive the following error when running a script:
Expected procedure, not variable.
Renaming VBA Objects Through Scripting
Avoid renaming VBA objects in a VBA script. Doing so will cause the code associated with those objects not to function. For example, if a rectangle named Rect1 has an associated event called Sub Rect1_Click(), changing the name of the rectangle to Rect2 will cause Sub Rect1_Click() not to function since there is no longer an object called Rect1.
The script below prompts the user to enter a new name for a rectangle object when that object (Rect1) is clicked. When you enter a new name and click OK, the object Rect1 no longer exists and the code becomes orphaned and useless.
Private Sub Rect1_Click()
Dim strNewName as String
strNewName = InputBox("Enter new name")
Rect1.Name = strNewName
End Sub