|
Introduction To Using VB.NET Code On The NA IntroductionAdding code allows more power and flexibility behind an action than simple getting and setting of bits. It allows complex logic expressions and mathematical calculations to determine precisely the action to take. Code can also be used to validate values entered and allow the user to correct mistakes. Code may perform calculations to ensure what the user sees is meaningful. Code can be used to initialise values when pages are opened/closed. Why VB.NETThe NA is running Windows Embedded Compact 7 (WEC7) and therefore is using the .NET Compact Framework. Using .NET enables the NA to benefit from a huge amount of flexibility and standard functionality that otherwise would take years to develop. BASIC was developed back in 1964! Beginner's All-purpose Symbolic Instruction Code. As the name suggests, it’s easy to use. Since its development there have been many versions and changes. Microsoft Developed Visual BASIC (VB) to allow users to easily create user interfaces for Windows. In the last 10 years Microsoft has developed VB to be used under its .NET framework. Far from its ‘Beginners’ or Hobby beginnings, VB.NET is now widely used in a commercial setting VB.NET is now an established language that is widely used. Novice developers will be quickly become familiar with the syntax which is easy to use and forgiving when compared with C#, C++ or Java. Unlike Visual BASIC from many years ago, VB.NET is a compiled language (not interpreted) which means the quality and speed is comparable to any other .NET language. Where can I use code?In the NA Series there are several main areas that code can be used: Global subroutines are useful to contain all the common functionality for the whole project. They can be linked to global events such as scheduled events that run at a particular time of day (perhaps export a file to the USB device or something). Each Page has a code behind. Here the user can program functionality specific to that page. All actions of page objects that call subroutines would result in a call to a function in the page code. It is also possible to call a subroutine on a background page. IAGs can contain code and expose methods to allow code to be encapsulated within a reusable object (IAG). Subroutines and FunctionsIn VB.NET there are two ways of defining methods:
The syntax for a new subroutine is:
The syntax for a new function is:
A subroutine or function local to the current page can be called by just its name or using:
Functions and subroutines that are global can be called using the group name. A Subroutine defined in a global group can called in this way:
The syntax for calling subroutines and functions when you are using return values is different:
Code Explorer
The Code EditorThe code editor is started from Solution Explorer or Code Explorer. The code editor behaves the same for page or global code. Subroutines and functions can be expanded or collapsed using the + or – button next to the code block. The Code Editor uses colour coding to help you with your syntax (default colours can be changed in the options): The code editor will offer suggestions as you are typing; this reduces mistakes and the need for using a manual. Autocomplete will pop up automatically when in the right context e.g. ‘me.’ Or ‘mediaplayer.’. You can also get auto complete to pop up at any point in Sysmac Studio by pressing <Ctrl> + <Enter> to display all possible options.
Building the CodeTo build the project, and associated code, click on: Project | HMI Build. The output from the build process will appear at the bottom of Sysmac Studio. Double clicking on any errors or warnings will jump directly to the code that needs correcting:
Using More Advanced VB.NET CodeThis article has shown how to get started with VB.NET code in your NA Project. For details of HMI functions available to the NA see 'Using NA Objects And Methods From VB.NET Code' article. See Also:Introduction to the NA series HMI Link: |
| Comments | ||
|
||



