Visual Basic .NET Tips


Option Explicit

Forcing the explicit declaration of all variables reduces potential bugs. Classic VB required an Option Explicit statement in the declaration section of code if we wanted the Visual Basic compiler to enforce variable declaration which held the potential for problems because variables were often misspelled. When using Option Explicit, an entirely new variable is created if not already declared. Unlike classic VB, Visual Basic .NET implements Option Explicit by default, preventing the accidental creation of new variables and protecting the use of declared ones. Syntax: Option Explicit On



[ Top ] [ Home ]



Keep Your Code Portable by Using App.Path

Would you like to avoid having to modify the path in your Visual Basic program, every time you need to run it from a different subdirectory or drive?

There are a number of ways to get the app.path in VB.NET. This particular method works for VB.NET (including windows forms applications and .dlls) and ASP.NET. Unlike app.path in vb6, this includes the the "\" at the end of the value. Instructions: Copy the code below and paste directly into your VB .NET project.
Public Function App_Path() As String 
Return System.AppDomain.CurrentDomain.BaseDirectory()
End Function


[ Top ] [ Home ]


All items Copyright ©1996 - 2017 Chin. All Rights reserved Reproduction without explicit permission is prohibited. See: Terms of use