Welcome, Guest. Please login or register.

Author Topic: [VB] {#3} Intro To Terms, Commenting, Variables and more!  (Read 3270 times)

0 Members and 1 Guest are viewing this topic.

Offline Inject OH 4

[VB] {#3} Intro To Terms, Commenting, Variables and more!
« on: December 20, 2012, 08:43:06 AM »
Lets talk first a little about programming and computers in general.

Primitive Data Types - Short Version

Numerical Primitive Data Types
Byte type can hold numbers between 128 to 127
Short − 32,768 to 32,767
Int − 2,147,483,648 to 2,147,483,647
Long − 9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
Double, and float are also data types these hold decimal values (IE: 9.333, 3.0, etc)

Other Primitive Data Types
Char - This holds a single character, an example would be the letter 'a', it can not hold multiple letters or sentences.
Boolean - This holds a value of either True, Or False.


A String Data Type?
A String which is not considered a primitive data type in most programming languages, is also very important to know. The reason it's not primitive  is because internally strings are represented as multiple characters, which you could decompose into individual characters. As a requirement primitive data types must be predefined types of data. A String then, holds a string of letters or characters. Or maybe more easily spoken as a sequence of characters together as a variable *generally speaking* (EX: String would be "Gaming"). Remembering that things like a space ( ) and period (.) count as characters (as well as other things like "/", "'", ",", """, etc).



Some Common Practice / Naming conventions
Generally their are a few common practices or ways that most programmers consider to be accepted. Not really sure how to word that correctly but perhaps as I go on you will understand. It's good to follow these practices. A good example is the short name for a Button would be "btn_name", where name is the name of the particular button. The default in visual basic for buttons is "Button1", naming the button "ButtonPusher" would be considered not as well formed. This goes for other things like the text box, where it should be named "txt_UserName" following some similar rules as are used in the Naming Conventions of Variables.  The reason is so that you can retrieve useful information from the names based on regularities. Although it is not required and will not effect your code, It is generally recommended. Another important convention for variables is using casing to separate words for example:
Code: [Select]
Dim timeMins As Integer
 Dim TimeUntiTheSecondComingOfAwsomeSauce As Integer
Where the second word starts with a capital letter indicating the separation of words. Also it is generally done that the first word will start out lowercase "tempTime" allowing for a more easy flow of the words, however this is sometimes ignored if their are three or more words involved.

It is important to follow these convection's to have nice and tidy neat code that is easy to read (even for your self) and flows well. Remember however that not all venerable are as easily understood from their name, for example an increment variable for a counter in perhaps a for loop may be called int i; where 'i' stands for increment. Count is sometimes used in place of this but when you are doing lots of coding these shortcuts, or tricks can be very time saving and easily understood once you get to using them. Since they are used all around it would be good to be familiarwith them in case you have to work with code that is not yours.



Commenting Code
Commenting code is also very important. It is recommended you do so where it should be applied. Comment's in code are lines of text that the compiler will ignore. Meaning that is will not effect your program. These lines are used to describe fragments of code, watermark your application, debug code, or remind you of where you stopped or what you are heading towards. Commented code is just simply Human readable text. Depending on the programing language the method to denote comments can be different. Since we are using Visual basic for not we will just deal with "'" or (') the apostrophe. An example of the comment code is shown below where the green text is the commented code.

Quote from:  Comment Code
Imports System.Net
Imports System.IO
'@Inject OH 4
'Rev 1.2 Dec 4th 2012
'Program checks your IP and displays it otherwise sends an error


'Attempt IP Get
Try
            ipaddress = System.Text.Encoding.ASCII.GetString(( _
            webclient.DownloadData("http://www.conjointgaming.com/codecalls/whatsip.php")))
            lblIP.Text = ipaddress
        Catch ex As Exception
            'If cannot track users IP display error
            MsgBox("You are not connected to the internet or the hostname is down.", MsgBoxStyle.Critical)
            'Don't forget to close
            Me.Close()
End Try
As you can see commenting can be used to state the creator of the application (which is only visible via a user having the source code, do not use this to let users know), when it was made and a small description on what the application does. Those areas of comment are generally only for yourself and others using your code. Commenting is important, when you start making a huge complex program, it's going to be very helpful to know what your code does and where it is. Commenting is pretty necessary however you don't need to over comment for example:
Quote from:  Comment Code
'@Inject OH 4
'Rev 1.2 Dec 4th 2012
'Program checks your IP and displays it otherwise sends an error


'Attempt IP Get
'Start of Try
Try
            'YEAH GET TAT IP
            ipaddress = System.Text.Encoding.ASCII.GetString(( _
            'USIN TAT WATS MEH IP SAUCE
            webclient.DownloadData("http://automation.whatismyip.com/n09230945.asp")))
            'POP THAT BAD BOY INTO OUR TEXT BOX! YEHHHHHH
            lblIP.Text = ipaddress
        'But dog... what if something goes wrong?
        Catch ex As Exception
            'If cannot track users IP display error
            MsgBox("You are not connected to the internet or the hostname is down.", MsgBoxStyle.Critical)
            'Don't forget to close
            Me.Close()
'Now end that bad boy!
End Try
'WHITE SPACE LOL
Although over commenting doesn't hurt it's a tad unnecessary and waist time. For now don't worry about it though, right now for getting use to it and since your new, comment as much as you need and want! Also in relation to the white space comment, white space ie no code just a blank line, does not effect your code and has no effect when compiled the same as commented code. Commenting can be used to disable fragments of code for debugging as well this is helpful when you think something might be breaking your program and you want to see what's going on. We'll take about this in more detail later.


Declaring Variables
To start in visual basic lets declare a variable. Dim is what we always want to start with. So Dim timeSpent or Dim reallyCool, etc. After we name our variable we need to then go on to say "As" and define the type of variable we are creating such as Int, Boolean, etc. Example:
Code: [Select]
Dim numTest As Integer As you can see in Visual basic we do not call it "numTest As Int" we are required to write out the whole word, which is a tad annoying and not really done with most of the programming languages you'll later deal with. However the IDE (integrated development environment, or the Visual Studio application you are programming within) has some nifty features as you type it displays a drop down of likely things you are heading towards in our case we can type int... and hit enter as it will be the first selected option on our drop down. This can at times get annoying when we hit enter and it changes our code into some random thing from the drop down but we'll get into that later as well.

Now we have created a numTest variable with type Int. We should initialize it! So lets go ahead and do that by typing on the next line:
Code: [Select]
numTest = 6 followed by the next line of code to display our new value
Code: [Select]
MsgBox(myNum)Putting this into piratical use we could create a form add a button and make this it's code so we would have:
Code: [Select]
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim numTest As Integer
        numTest = 6
        MsgBox(numTest)
    End Sub
End Class
Lets assume however we are going to make numTest equal to 6 to start with and don't need to wait we can initialize it from the moment we declare it! Simple as, "Dim numTest As Integer = 33" if however we changed our first line to this but didn't remove "numTest = 6" the message box would still display 6, the number that numTest is actually equal too.  Their isn't much different between how the other data type work minus the following examples:

Code: [Select]
Dim numTest As Boolean = True
Dim numTest2 As String = "This is a string"
Dim numTest3 As Char = "c"


Anyways that is it for this tutorial. In Tutorial number 4 we will be making another application and back to reading again in tutorial number 5.

« Last Edit: January 17, 2013, 12:50:45 AM by Inject OH 4 »
Quote from:  Winston
We shall defend our island, whatever the cost may be, we shall fight on the beaches, we shall fight on the landing grounds, we shall fight in the fields and in the streets, we shall fight in the hills; we shall never surrender.
Quote from:  Zombie
Valuve Admin Steve: If not we at valve can act as a "guardian gateway".
Valuve Admin Steve: I will be your daddy.
Looking for graphic artist, Photoshopers, and other graphic related people. Hit me a PM if you can help!

Conjoint Gaming [Game On]

[VB] {#3} Intro To Terms, Commenting, Variables and more!
« on: December 20, 2012, 08:43:06 AM »

 


* ShoutBox!

Refresh History
  • Careful what you post. Forum rules still apply in the shoutbox!
  • Pyro: happy birthday Tyber
    July 14, 2024, 01:55:16 PM
  • Finniespin: More of a Patrick Hernandez guy - Born to be Alive
    June 16, 2024, 09:14:27 AM
  • Sly: Aaron Hernandez was a legend of a man
    June 14, 2024, 01:46:02 AM
  • Finniespin: how? what?
    June 01, 2024, 06:28:43 PM
  • Inject OH 4: Lost my discord rip
    May 30, 2024, 12:14:57 AM
  • Finniespin: yoooooooo!
    April 03, 2024, 05:32:48 PM
  • Coreybush11: bump
    April 01, 2024, 10:59:48 PM
  • Finniespin: wut
    March 28, 2024, 05:01:26 PM
  • Inject OH 4: And yes thank you very much Finnie! You are a champion xP
    March 22, 2024, 05:59:12 PM
  • Inject OH 4: Hey abrys agreed we should.
    March 22, 2024, 05:59:02 PM
  • Finniespin: Totally not a spam-bot, also totally not a limited time offer
    March 03, 2024, 05:25:06 PM
  • Finniespin: Anyone looking for a datacenter technician job? We got postings available around US and Europe (EMEA)
    February 17, 2024, 07:23:12 AM
  • Finniespin: https://www.google.com/about/careers/applications/jobs/results/118336179041903302-data-center-technician-global-server-operations
    February 17, 2024, 07:20:25 AM
  • Finniespin: Gave Inject 50 euros to pay for fees ^^
    February 17, 2024, 07:17:42 AM
  • xXArbysOvenMittXx: we gotta get the crew together again one day and hang, add me on discord: ogarbies
    February 12, 2024, 06:52:07 PM
  • xXArbysOvenMittXx: yo who is still paying for this lol
    February 12, 2024, 06:19:47 PM
  • Klondor: wow CG still lives, mind blown
    February 09, 2024, 05:13:53 AM
  • Finniespin: The website is back online!!!
    February 06, 2024, 03:17:05 PM
  • Inject OH 4: xD
    January 14, 2024, 05:55:44 PM
  • Finniespin: Get a load of this guy
    December 16, 2023, 09:16:03 AM
  • Inject OH 4: Sure
    December 09, 2023, 07:22:27 PM
  • HailToTheKing: cum shot . and cum shot. an d cum shot
    December 01, 2023, 01:54:12 PM
  • Finniespin: ffuck
    November 24, 2023, 03:43:47 PM
  • Inject OH 4: ee
    October 12, 2023, 01:13:56 AM
  • Sly: dd
    August 09, 2023, 03:13:48 AM
  • Inject OH 4: cc
    August 03, 2023, 09:51:36 PM
  • Finniespin: bb
    August 02, 2023, 06:12:50 PM
  • Inject OH 4: aa
    July 04, 2023, 10:29:35 PM
  • Shikaru: Been a very long time
    February 20, 2023, 05:42:04 PM
  • Shikaru: Oh wow my account is STILL active :)
    February 20, 2023, 05:42:00 PM
  • Napoleon BonaPARTY: yooo we got a lovense sponsor???
    December 16, 2022, 03:45:43 PM
  • Napoleon BonaPARTY: holy shit
    December 16, 2022, 03:45:24 PM
  • Napoleon BonaPARTY: oh wow its still here
    December 16, 2022, 03:45:21 PM
  • HailToTheKing: legends never die
    October 16, 2022, 01:28:09 PM
  • Live Bait: Oh wow. Still remember my old password.
    September 23, 2022, 08:37:38 AM
  • Mr_Rainbow: Still alive. Hope all is well with everyone this Christmas
    December 09, 2021, 03:31:04 AM
  • SlyWilliam: Much love, from our MC server to our ZPS server <3
    December 07, 2021, 10:23:37 PM
  • SlyWilliam: For the record, I don't REALLY remember all of you, but goddamn do I MISS all of you <3
    December 07, 2021, 10:23:10 PM
  • Pyro: parrot
    September 07, 2021, 05:23:18 AM
  • Inject OH 4: Do you mean for people that haven't come on in a long time and have to reagree?
    August 02, 2021, 11:39:42 PM

SimplePortal 2.3.5 © 2008-2012, SimplePortal