Installing the Comm32 ocx in Visual Studio .Net
See Also - - [ Using In Visual Basic 6 ]
When you download Comm32 from our website the Installer will usually appear on your Windows Desktop or Downloads folder where you'll see the installer icon like this:-

Double click the installer icon to install Comm32. You can then start using Comm32 in your projects.
Add the Comm32. component to the Visual Studio .Net toolbox.
Open your Visual Studio .Net project and click with the "Right" mouse button on the toolbox area of the IDE and select the option to Add new components. A small window appears showing available components. Select the COM tab (Comm32 is a COM component) and then select the Comm32 component and it will be added to your toolbox where you can drag an instance of Comm32 onto your form.
If you've used ActiveX controls in VB6 then there are a couple of things you should be aware of when using Comm32.ocx in dot.Net.
- .Net can add the prefix "Ax" to ActiveX controls so you'll see names such as AxComm32 etc.
- The name of the component "Comm32" appears quite a lot especially in C and C#. After you place an instance of the control on your form we'd suggest changing the name of the control to something like 'Port' as in Port1, Port2 etc.
- Property names change in the .Net environment. Each property will be prefixed by the text get_ or set_ (see below for examples of using this syntax)
- Comm32 Properties sometimes behave like 'Functions' in the .Net environment. Look at these 3 examples.
- Reading and writing a property in VB6
If (Port.PortOpen = False) Then
Port.PortOpen = True
End if
- Doing the same in VB.Net
If Port.get_PortOpen = False then
Port.set_PortOpen(True)
End If
' Property names are prefixed with get_ or set_ (indicating read or write) and when setting a property the new value is passed in brackets just like a function call.
-
Doing the same in C#
bool b = true; // Notice this variable - we didn't need this in VB
if(Port.get_PortOpen() == false)
{
Port.set_PortOpen(ref b);
}
/* c# is even stricter - notice that we used empty brackets even when reading the property. Also notice the 'ref' keyword when setting the new value. By Default Visual Basic passes arguments 'By Ref'. In c# that isn't the case but we still need to pass the value by ref. Adding the ref keyword tells c# that you want to pass it by ref. Because you're passing an argument by ref it's cleaner if you use a variable. In this case we declared b as a boolean, set it to true and passed that by ref. */
See the downloads page where you can get the Comm32 download as well as fully functional sample projects in vb6, vb.net and c#
See Also - - [ Using In Visual Basic 6 ]
|