Porting VBA/VB6 example code to VB .NET

Post your .Net discussions here
Post Reply
Hitesh

Porting VBA/VB6 example code to VB .NET

Post by Hitesh »

Hi,

We provide VB .NET examples for some, but not all, drivers for PicoScope and PicoLog products.

It is possible, however, to port the VBA code (or alternatively convert the C# examples) to VB .NET code. This post provides some tips on how to do this.

To port the VBA examples to VB.NET, copy the code from the VBA Macro into new files in your IDE and ensure the following:
  • Variables/parameters that are defined as (32-bit) 'Long' are changed to (32-bit) 'Integer'.
  • All other data types match those defined in the API function.
  • Parameters are passed 'ByRef' or 'ByVal' as required by the API function.
  • Strings are passed 'ByVal'
  • The path to the dll is correct for each function that is defined.
Defining Function Calls

There are two methods of defining functions in VB.NET - below are examples for the ps5000a driver API function call to open a connection to a PicoScope 5000 A and B Series PC Oscilloscopes:

1. VBA Style

Code: Select all

Declare Function ps5000aOpenUnit Lib "ps5000a.dll" (ByRef handle As Short, ByVal serial As String, _ 
ByVal resolution As DeviceResolution) As UInteger
2. Using InteropServices DllImport

Code: Select all

Imports System.Runtime.InteropServices


   			Public Function OpenUnit( ByRef handle As Short, _
                                       ByVal serial As String, _
               		                  ByVal resolution As DeviceResolution) As UInteger
             End Function
Hope this helps :D

Post Reply