COM Interface – C# and Visual Basic Programming

Netica has APIs for several different computer languages (such as Java, C/C++, etc.), which allow it to be used as part of a computer program in one of those languages. For more information, see Netica API.

One such Netica API is called Netica-COM. You can program Netica through its COM interface (also known as ActiveX or Automation) using any computer language that can access a COM interface. For example C#, Visual Basic (VB), COM enabled Java, or C++. The below is written as though VB is being used, but it pertains to programming in the other languages as well.

A great benefit of programming Netica through its COM interface is that people can interact with the GUI at the same time as your VB program is running. That can be useful for debugging, demos, and distributing products that take advantage of the Netica user interface by allowing the end-user to interact directly with the Bayes net.

If you have programmed an MS Office product using Visual Basic, you will find some similarities in style with the Netica COM interface.

To use Netica COM in its fully enabled form, you must have a Netica license password that is for both Netica Application and Netica API. First, run the latest version  (must be version 3.10 or greater) of Netica Application, so it can register itself in the registry. If you have several versions of Netica on your computer, the version of Netica that VB will use will always be the one that was last run (for example, by double-clicking it). You can leave it running or exit it. Then to get access to it from Visual Studio, choose Project Add Reference from Visual Studio, click the COM tab if necessary, and check-mark the entry called "Netica 1.0 Object Library" (with perhaps some other version number).

You can then use the object browser to see the Netica objects and functions available. Choose View Object Browser or View Other Windows Object Browser, and then:

 In Visual Studio 6, set the library to Netica in the upper left choice box.

 In Visual Studio .NET, one of the top level entries in the object browser will be "Interop.Netica". You can browse that, but it won't be as good as browsing the Netica library directly, because you won't have a description for each function. If there is no entry at the top level for the library named simply "Netica" (with the books icon), it may be enough to choose All Components from the Browse menu at the top of the window. Otherwise choose Edit Custom Component Set from it (or click on the Customize button if there is one, then the Add button). Choose the COM tab, select the Netica library from the list, click Select and then Okay. Now the Netica library should appear, and you can browse it.

In the object browser, when you click on any function or enum, then a short description will appear, which is good enough for most programming work. If you need more detail, then you will notice that within the description is the name of the equivalent function in the Netica-C API. You can look up that function in the Netica-C documentation.

 To view that documentation, see: http://www.norsys.com/onLineAPIManual/index.html

To download it, go to: http://www.norsys.com/download_api.html

Example Code:  Here is example code to program Netica in C#, Visual Basic and Managed C++ (C++/CLI) using the COM interface. There is also an example Visual Studio project for each, called "Netica Demo for xx" within the "Netica\Netica xxx\Programming Examples" folder of the Netica download package.

Password/Distribution:  If your license password enables only Netica API, then the GUI will operate in a limited mode, and if your license password enables only Netica Application, then your VB calls to Netica will operate in a limited mode. If you want to distribute your VB program that uses Netica, you need to only send Netica.exe (and perhaps Netica.hlp), but not Netica.dll. Make sure you have the required license from Norsys before you do so.

To start up Netica so that it operates with a password that is not put in the Registry, start it from your VB program with the command line argument -password followed by the password you want Netica to use. That password will not be entered into the registry, and its security part will not be visible to the user.

GUI Control:  You can use the Visible property of the Netica.Application object to determine whether or not the graphical user interface (GUI) is present or not (by setting it to true or false, see the example below). If it is not visible, then it will be a minimized window appearing only as an icon on the task bar. If you wish to prevent the user from un-minimizing it, thereby preventing them from having access to the Netica GUI, set the UserAllowed property of Netica.Application to false.

Example: To do the above, your program might have a part looking something like this:

Shell ("C:\\Netica\\Netica312\\Netica.exe –password +Me/MyOrg...")

Dim app As New Netica.Application

app.Visible = False

app.UserAllowed = False

...

app.Quit

Continuous/Discrete Nodes:  To make a continuous node, use BNet.NewNode and pass 0 for the number of states. To later discretize it, or set the levels of an already discrete node, simply change its Level property. You just set Node.Level(0), then Node.Level(1), etc. It will adjust the number of states of the node each time. If you have very many states, you may want to start with the highest first, since that is somewhat more efficient.