Test and Measurement Forum

Porting VBA/VB6 example code to VB .NET

Post your .Net discussions here

Porting VBA/VB6 example code to VB .NET

Postby Hitesh » Fri Jan 29, 2016 8:57 am


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

<DllImport(_DRIVER_FILENAME, EntryPoint:="ps5000aOpenUnit")>
            Public Function OpenUnit( ByRef handle As Short, _
                                       ByVal serial As String, _
                                       ByVal resolution As DeviceResolution) As UInteger
             End Function

Hope this helps :D

Technical Support Engineer
Site Admin
Site Admin
Posts: 2790
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Return to .Net Languages (C#, VB.Net, .)

Who is online

Users browsing this forum: No registered users and 0 guests