r/visualbasic • • May 06 '20

VB.NET Help Former angular dev now working with Visual Basic/c#. Looking for some resources on VB.

Hey everyone,

As title says all of my development has been angular clients with C# api’s and sql for data. In my new job all the other devs use VB.net and c# web pages. Some stuff is familiar on the c# side, but vb.net is wayyyy different from what I’ve seen lol. Anyone know of any good resources for a overview of vb.net?

8 Upvotes

7 comments sorted by

4

u/routineMetric May 06 '20

Not sure if you've used it, but I've always found official Microsoft docs both very useful and surprisingly unknown to others.

https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/

Also, here is a free pdf book compiled from a bunch of good StackOverflow answers.

https://books.goalkicker.com/VisualBasic_NETBook/

1

u/x_Teferi_x May 06 '20

I really appreciate these resources! PDF sounds great!

1

u/itsmybirthday19 May 06 '20

Thank you for sharing the PDF book

3

u/andrewsmd87 Web Specialist May 06 '20 edited May 06 '20

If you know c# the transition to VB shouldn't be too hard. I went from PHP to vb to c# without too much trouble. It's just getting used to the different syntax. There are maybe like a dozen things that I think will cover 95% of what you need, and the rest you can always google, or straight up use the telerik vb to c# converter.

Main things are. If you can, always set

option strict on

You can google what it does but it basically makes VB more like a strongly typed language which will save you debugging headaches down the road. Now, if it's a legacy system don't just go blindly setting that as it could cause issues if the system was built without it on.

Even though VB doesn't make you (unless you have option strict on), ALWAYS define your variable with a type.

DO NOT DO

Dim myDecimal = 0

do

Dim myDecimal AS decimal = 0

The reason being is if you did decimal math on the first one, VB will try to infer the type and think it's a int. Then, presto, you're losing your decimal precision. However, the code will build and run fine. It could even pass testing if people were testing generic stuff like 10/5

The other big ones are if statements look like this

if some var then
'do stuff
end if

for loops are a little wonky

For index As Integer = 1 To 5
'do stuff
next

If you ever want to "return" from anything, there's always an exit for that, i.e. exit sub, exit for, exit while, etc.

Functions and Subs are also a little different than in c#

Functions always have to return a value, subs do not. In layman's terms I always just explain it as functions give you something back, subs do stuff you want sectioned off, but don't return anything. I'm not saying it's a good feature of the language, but it exists.

And then linq syntax is a tad different, but it'd take too long to go into all of that. Google will be your freind.

The last thing is with no statement terminator (; in c#) it can get tricky to write multi line statements, especially depending on what version of VB you're using. Newer versions can kind of auto handle knowing when something ends, but older ones need a _ to tell it go to the next line

I.e. say you're doing

Dim myString as String = "some super long ass thing that " & "I want to concatenate onto two lines"

and you want that on two lines, you need to do

Dim myString as String = "some super long ass thing that " & _
    "I want to concatenate onto two lines"

Note it's & _ instead of just &

There's more but those are the biggest things IMO. I really would not be worried about the transition, if you know c#. Remember that pretty much anything you can do in c# you can do in VB, and most of the function and object names are even the same.

1

u/x_Teferi_x May 06 '20

Hey I really appreciate that detail! We’re all working from home right now and won’t be back on site till probably mid June/July so I won’t be able to get fully trained until then. I’m just trying to get a head start. Yea what really threw me off was the subs thing. I was sent an already in use application just to review the code and get a feel for it and I couldn’t understand what a sub was really lol. They also use vb in conjunction with .net (I’ve used .net core) but that won’t be bad at all. At first glance things seem way more tedious than need be compared to similar functions in my previous work, but I’m sure it’ll all come together. Thank you again!

2

u/andrewsmd87 Web Specialist May 06 '20

Another way to think of a sub is it's just the way VB defines void functions.

Given that I bounce around different languages, I generally call subs functions because that's what they really are.

I think you'll be fine knowing c#. Outside of some nuances, a lot of it should really look familiar.

1

u/analogsquid Jun 15 '20

What industry/what kind of product are you working on that you use Visual Basic?

(Student, new to this, just starting Visual Basic. Trying to get an idea of some of the things people are doing with it.)