VB.NET Tutorial I – Objects, Methods, and Properties
Tonight, I am starting this VB.NET Tutorial. Firstly, let’s talk about what VB.NET is, VB stands for Visual Basic and is a modern evolution from the BASIC family of programming languages. BASIC stands for Beginner’s All-Purpose Symbolic Instruction Code. Visual Basic is a high-level programming language, no that doesn’t mean that this language is elite or hard, it means that this language has more abstract ways of managing how your program works to be less detailed and/or similar to the bare machine language. This also includes the idea of the Visual Basic being closer to human language to make it more user-friendly. In fact, I believe that Batch is very much like BASIC.
In order to start programming in VB.NET, you need a VB.NET IDE and compiler. So you can get Microsoft’s free VB.NET IDE: http://www.microsoft.com/express/vb/, or you can get the .NET IDE from SharpDevelop: http://www.icsharpcode.net/OpenSource/SD/Download/.
Both of these IDE’s have their ups and downs. The one from Microsoft has great intellisense and automatically detects errors while you code, but this IDE is not portable. The SharpDevelop IDE is portable and also supports other languages, but the intellisense is not as good as microsoft’s and starts detecting errors only when you attempt to run or build your program. As of right now I use SharpDevelop since it is portable and gives me a little more insight into my code, but Microsoft’s VB.NET IDE helped me learn VB with training wheels given its excellent intellisense when I first started Visual Basic.
Now, to explain how to work with the Visual Basic language.
0x00 – Objects, Properties, and Methods
An Object is something you can work with in VB. You can get information about an object, set information about it, or make the object do something. Objects contain a set of methods and properties. A Method is actually a set of code that is associated under the object that you can call on to execute, thus in more abstract terms we are making the object do something. Frequently the method may also return a value as a result of that action. A property is associated information that describes that object; this information may be modified or retrieved.
For abstract example:
- We have an object called ‘MasterChief’
- One of the methods of ‘MasterChief’ is ‘Kill’
- We will call that method with an argument for that method: MasterChief.Kill(Grunt)
- MasterChief also has a property called ‘ArmorColor’
- We will set data for this property: MasterChief.ArmorColor = “Purple”
Now when we called the ‘Kill’ method through MasterChief we specified an argument. Arguments (or parameters) are a set of values that you include when calling a group of code, which the code performs and executes depending on the values of the arguments. In a way you are giving options to the function or method on how you want the code to be executed.
Now in that first example I only included one argument, to include more than one just separate the values with a comma:
Now the object ‘MasterChief’ will perform the method ‘Kill’ with the given arguments: ‘Grunt’ and ‘HeadShot’.
Next we have the example of setting information about the object. In this case we have the property ‘ArmorColor’ for the object ‘MasterChief’, from here we can set a value for that property by placing an equal sign to the right of the Object.Property and placing the value to the right of the equal sign.
To get the value of a property, just specify the Object.Property but the return value must be handled by an instruction or method or the assigning of a value to something else.
The command: MasterChief.ArmorColor
does not do anything, all it does is produce a value, therefore it is an invalid command. Just like in batch when the variable myvar is set as “hello world”. %myvar% would be an unrecognized command, operable program, or batch file.
Well, that is my first explanation of the Visual Basic language. More is to come as I explain the other abstract ways of this language and how to program with them. See you soon.