Variables
String, Integers, Booleans and More
String, Integers, Booleans and More
Next, we're going to work on all the syntax in VB.NET, building up to creating your first application.
Visual Basic's syntax is created to be more...logical I guess you could say. It could probably be read by anyone with common sense.
Now let's take a look at what we'll use the most...
Variables can be a variety of things. Mainly they're going to be strings, integers, booleans, and declaring objects. (Like WebClients (System.Net namespace) and other things)
Declaring Variables
The following image will show you how to declare variables:
Spoiler (Click to View)
Why there are more data types of variables you can declare for things that suite your need, these are the most common ones and will be the most used. Here is a list of all the different data types:
Data Types (Click to View)
Arrays use indices to stored multiple data types, and let you use a number to tell them apart because they will use the same name. It is basically like declaring, for instance, 5 strings in one. This is how you declare an array for a string:
Code:
Dim str As String() ' notice the () at the end. That is how you know if it is an array.
str = {"One string", "Two strings", "Etc."} ' These strings are enclosed in brackets and separated by commas.
'This is how you call "One string":
MsgBox(str(0)) ' would output in a message box: "One string"
'this is how you call "Two strings":
MsgBox(str(1)) ' would output in a message box: "Two strings"
'This is how you call "Etc.":
MsgBox(str(2)) ' would output in a message box: "Etc."
See how that works? Take a look at this GIF if you're having some trouble...
Spoiler (Click to View)
arrays can be very useful. If you have one thing that can have multiple values of if you are trying to split a string it will always be outputted in an array. These are valuable things to learn.
Declaring Objects
Objects can be a wide range of things. In this example we're going to be using a WebClient. A WebClient "provides common methods for sending data to and receiving data from a resource identified by a
URI." - MSDN
While a WebClient has to be declared like this:
Dim wc As New WebClient()
Some things like the XMLReader and XMLWriter in the System.Xml namespace have to be declared like this:
Dim xml As XMLWriter = XMLWriter.Create(Arguments+)
or
Using xml As XMLWriter = XMLWriter.Create(Arguments+)
You can see all the arguments that something requires by going to MSDN.
Using Google Dorks will limit the results, example: some function site:msdn.microsoft.com
Anyways, continuing with the WebClient example.
Once you have declared your WebClient():
Code:
amespace YourNamespace
<Public/Private Keyword> Class YourClass
Dim wc As New WebClient() 'now it is declared
End Class
End Namespace
Let's go over some of the various and most commonly used functions for a WebClient()
DownloadFile(Uri, String) -- Downloads a file from a Uri and saves it to the file path aka the second argument.
DownloadString(Uri) -- Downloads a string from a Uri and then returns that string.
Now to call these functions we would use the name of the Object we created that is the WebClient, in this case, wc and then add the function we want after that; i.e.:
wc.DownloadFile("http://www.somesite.com/file.exe", "C:\Users\Shit\Fuck\File.exe")
For the other one, since it returns a value, we would have to declare a string in order to "capture" that value. Like so:
Dim str As String = wc.DownloadString("http://www.somesite.com/file.txt")
Now the String that we declared will be the contents of the Text File that we downloaded.
Credits:
SomeWhiteGuy - Original Post