vbNullString
is a remnant of VB6 (which I think would be under the Microsoft.VisualBasic.Constants
namespace), and used to be a null string pointer often confused with ""
, an empty string. In VB.NET vbNullString
is Nothing
, so when you do this:
If targetFolder = vbNullString Then
You're actually verifying whether targetFolder
contains a reference at all... but you probably mean to check whether the provided string is null or empty. A more idiomatic way to test for this is String.IsNullOrEmpty
:
If String.IsNullOrEmpty(targetFolder) Then
vbNullString
is a remnant of VB6 (which I think would be under the Microsoft.VisualBasic.Constants
namespace), and used to be a null string pointer often confused with ""
, an empty string. In VB.NET vbNullString
is Nothing
, so when you do this:
If targetFolder = vbNullString Then
You're actually verifying whether targetFolder
contains a reference at all... but you probably mean to check whether the provided string is null or empty. A more idiomatic way to test for this is String.IsNullOrEmpty
:
If String.IsNullOrEmpty(targetFolder) Then
VB.NET's `String` type overrides the `=` operator such as [`Not String.IsNullOrEmpty(s)`, `s ""`, `s String.Empty` and `s vbNullString` are all equivalent](http://stackoverflow.com/a/34069187/1188513).- The following only apply if your project defaults options aren't customized:- You're not specifying `Option Explicit` *explicitly*, but that's fine because in VB.NET that's the default behavior, contrary to VB6/VBA where implicit declarations are allowed by default.- You're not specifying `Option Strict` either, and that's *less* fine, because by default, the VB.NET compiler won't enforce strict data typing- VB6/VBA was very loose with type conversions, and without `Option Strict`, VB.NET keeps a lot of that looseness. Note that `Option Strict` *implies* `Option Explicit`, so you don't *have* to specify both.
The following only apply if your project defaults options aren't customized:
You're not specifying Option Explicit
explicitly, but that's fine because in VB.NET that's the default behavior, contrary to VB6/VBA where implicit declarations are allowed by default.
You're not specifying Option Strict
either, and that's less fine, because by default, the VB.NET compiler won't enforce strict data typing - VB6/VBA was very loose with type conversions, and without Option Strict
, VB.NET keeps a lot of that looseness. Note that Option Strict
implies Option Explicit
, so you don't have to specify both.
You're specifying Imports
statements, but then you fully-qualify things in these imported namespaces - this defeats the purpose: either you Imports
namespaces, or you fully-qualify stuff. For example, you have Imports System.IO
, so this code:
files = System.IO.Directory.GetFiles(System.IO.Directory.GetCurrentDirectory(), "Export*.xlsx")