VB.NET problem with DPLOTLIB

Q&A for Visual Basic, Visual Basic .NET, and PowerBasic developers using DPlot

Moderator: DPlotAdmin

Post Reply
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

VB.NET problem with DPLOTLIB

Post by DPlotAdmin »

At this writing, the VB.NET example programs will not run correctly from within the VB.NET environment (the compiled examples work just fine). The problem the examples have is in finding DPLOTLIB.DLL. Windows searches for DLL's in this order:
  1. The directory from which the application loaded.
  2. The current directory.
  3. Windows 95 and Windows 98: The Windows system directory.
    Windows NT: The 32-bit Windows system directory.
  4. Windows NT: The 16-bit Windows system directory.
  5. The Windows directory. Use theGetWindowsDirectory function to get the path of this directory.
  6. The directories that are listed in the PATH environment variable.
The problem with #1 is "the application" in this case is the VB.NET IDE, not your project. In VB6 this is solved in the Form_Load event for the project with:

Code: Select all

ChDrive App.Path
ChDir App.Path
ChDir ".."
"App" in this case is the project. For the examples, each project is located in a subfolder below the main \dplotlib folder, so this sequence sets the current directory (#2 in the list above) to the folder where DPLOTLIB.DLL resides. It still works with the compiled executable because #1 takes over (assuming DPLOTLIB.DLL is in the same folder where the executable lives).

The problem in VB.NET is there is no App object. If you try the above you'll just get an error message. The solution comes from Googling "VB.NET App.Path". There you'll find a replacement for App.Path:

Code: Select all

Public Function App_Path() As String
    Return System.AppDomain.CurrentDomain.BaseDirectory()
End Function
You can add this function anywhere in the module where your Form_Load event is.

If you display App_Path in a MsgBox you'll find that it's the \bin folder below the project files. In the case of the example programs that's 3 levels below the \dplotlib folder. So in the Form_Load event for the examples, if you add:

Code: Select all

ChDrive(App_Path())
ChDir(App_Path())
ChDir("..\..\..")      ' or ChDir("....")
before any calls to DPLOTLIB functions, then all will work as expected, whether run inside VB.NET or as a compiled executable. The above should of course be tailored to how your project files are arranged.
Visualize Your Data
support@dplot.com
Post Reply