Hidden Features of VB.NET?

The Exception When clause is largely unknown. Consider this: Public Sub Login(host as string, user as String, password as string, _ Optional bRetry as Boolean = False) Try ssh.Connect(host, user, password) Catch ex as TimeoutException When Not bRetry ”//Try again, but only once. Login(host, user, password, True) Catch ex as TimeoutException ”//Log exception End Try … Read more

Is VB really case insensitive?

The difference between VBA and VB.NET is just because VB.NET compiles continuously in the background. You’ll get an error when you compile the VBA. Like Jonathan says, when programming you can think of VB.NET as case-insensitive apart from string-comparisons, XML, and a few other situations… I think you’re interested in what’s under the hood. Well, … Read more

IsNothing versus Is Nothing

If you take a look at the MSIL as it’s being executed you’ll see that it doesn’t compile down to the exact same code. When you use IsNothing() it actually makes a call to that method as opposed to just evaluating the expression. The reason I would tend to lean towards using “Is Nothing” is … Read more

VB.NET IntelliSense : Disable newline on ENTER autocomplete

UPDATE VISUAL STUDIO 2017: Now with Visual Studio 2017 you can change it. Tools -> Options -> Text Editor -> Basic -> IntelliSense. In Enter key behavior select Never add new line on enter ANSWER FOR VISUAL STUDIO 2015 AND PREVIOUS: If you want to avoid inserting new line on enter with autocomplete suggestion, just … Read more

Linq to Sql: Multiple left outer joins

This may be cleaner (you dont need all the into statements): var query = from order in dc.Orders from vendor in dc.Vendors .Where(v => v.Id == order.VendorId) .DefaultIfEmpty() from status in dc.Status .Where(s => s.Id == order.StatusId) .DefaultIfEmpty() select new { Order = order, Vendor = vendor, Status = status } //Vendor and Status properties … Read more

Classes vs. Modules in VB.NET

Modules are VB counterparts to C# static classes. When your class is designed solely for helper functions and extension methods and you don’t want to allow inheritance and instantiation, you use a Module. By the way, using Module is not really subjective and it’s not deprecated. Indeed you must use a Module when it’s appropriate. … Read more

Is there a VB.NET equivalent for C#’s ‘??’ operator?

Use the If() operator with two arguments (Microsoft documentation): ‘ Variable first is a nullable type. Dim first? As Integer = 3 Dim second As Integer = 6 ‘ Variable first <> Nothing, so its value, 3, is returned. Console.WriteLine(If(first, second)) second = Nothing ‘ Variable first <> Nothing, so the value of first is … Read more

What is the difference between And and AndAlso in VB.NET?

The And operator evaluates both sides, where AndAlso evaluates the right side if and only if the left side is true. An example: If mystring IsNot Nothing And mystring.Contains(“Foo”) Then ‘ bla bla End If The above throws an exception if mystring = Nothing If mystring IsNot Nothing AndAlso mystring.Contains(“Foo”) Then ‘ bla bla End … Read more

Is there a conditional ternary operator in VB.NET?

Depends upon the version. The If operator in VB.NET 2008 is a ternary operator (as well as a null coalescence operator). This was just introduced, prior to 2008 this was not available. Here’s some more info: Visual Basic If announcement Example: Dim foo as String = If(bar = buz, cat, dog) [EDIT] Prior to 2008 … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)