Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (1)

Powered by Vanilla. Made with Bootstrap.
[TUT] Visual Basic - Variables , Detailed [BEGINNER]
  • So, what are variables??

    Variables are place holders of a sort, they allow us to give a value to a name or word, There are different types of variables, some languages dont have different types example: Perl. But VB.NET does, the too types i am going to tell you about are integers and Strings.


    Integers

    Integers are just another way of saying numbers, so by now you can already see how a variable would work - name = 4, but in programming there is usually a symbol or command/function needed to declare that it is a variable and not a silly programming mistake, and Vb is no different. Do declare a variable in Visual Basic we type "dim". Let me show you a full example:


    dim variable1 as integer = 4


    'dim', is letting the program know it is about to have a new variable name, the variable name is 'variable1', 'as integer' is declaring what type of variable it is, and '= 4' is the value the variable got assigned too. Simples.


    Strings

    String are variables that allow us to have words assigned top the name. Like with integers we must declare the variable, set the name, say what type and finally give it a value. To do this instead of using 'as integer' we use 'as string'. Here is an example:


    dim variable2 as string = \"root\"


    Like before we have had to declare that we are using a variable and assign it a name so we are able to give reference later on in a source, but this time we chose to use string showing that we will be using more than just numbers, because we are using more than numbers we have to surround the value with "" (quotations) so it know that that is what the = is referencing too.


    The End.


    Hope you found this a very detailed look at variables in visual basic, and let me know if you would like me to bring you more tutorials like this.
    Skype: mrpt3o
    Twitter: MrPteo


    image
  • sangf
    Posts: 203
    nice, but it could do with a proof read. also, it would be useful to include a short list of all variable types even if you only explain a couple - and i wouldn't call this detailed.
  • Sh3llc0d3
    Posts: 1,910
    Apologies but my math teacher drummed this into me for years that Integer = whole numbers. As sangf said if you included all the data-types then you could differenciate between integer, float etc :)