VB.Net Console Mode Guide is an excellent resource for when you are just starting to use the VB.net console system. It will allow you to work over lots of examples and build upon your knowledge one step at a time.
All programming languages have data types. Many of these data types are standardised across languages.
Name | Specification | Example Use |
---|---|---|
Integer | A signed (positive or negative) 32-bit Whole number | Your Candidate number might be stored as an integer in a database |
Byte | A unsigned 8 bit bte | Storing Binary Information, storing settings |
Double | a 64 bit number, can be decimal | Prices of stocks on the stock exchange maybe stored as doubles |
char | A Single Character | Storing if someone is Male or Female |
String | A serious of chars, enclosed in double quotes. | Storing someone’s address |
Boolean | Has two options, true or false | Storing of someone wishes to receive emails |
ENum | An ordered set of values | Storing all the days of the week. |
Array | A collection of values of another data type, eg you could have an array or integers, or an array of doubles etc. | Storing a collection of scores for a darts player. |
Relational Operators are operators that give a True or False answer. For example '=' is a relational operator, "Stephen" = "James" is clearly false, and "Stephen" = "Stephen" is true!
There are six common relational operators, these are:
Equal to (=)
Not Equal to (<>)
Greater Than (>)
Greater than or equal to (>=)
Less than(<)
Less than or equal to (<=)
Some examples of use are:
5 > 6 False
4 = 4 True
4 < 4 False
4 <= 4 True
4 <> 4 False
4 <> 5 True
The simple IF Statment can be thought of as the diagram on the right. Where the condition that is being questioned is something involving one of the relational operators talked about above.
In the 'Do Something' Block there could be any code that you like, you could have calls to a function, you could have a for loop, or just a simple two lines setting a varable.
Example.
IF var = 1 then
var = 2
You could put another IF statment in the 'Do Something' Block, this called nested IF's because there is an IF within an IF. Say you were looking for a student called James out of thousands, you might start off by asking if the current student was male or female, then if they were male you could check to see if their name was "James"
if is a keyword in most languages and as such cannot be used as a variable name.
The If-THe-Else statement is slightly different, another flow chart is pictured below to show the differenceIf-Then-Else Flowchart.
An example of where you might use a If-Then-Else Statment might be if you were giving out instructions for a class, if the person you were handing too was a member or staff you would hand them special instructions, otherwise you would hand them normal instructions.
Case statments give you a list of options based on one variable, this can sometimes be easier than writing lots of If Statements, for example if you wanted to assign points based on age you might write the following code:
Select case age
Case 16
points = 5
Case 17
points = 10
Case 18
points = -5
So if age was 16, points would equal 5 after running this code, but if age was 18, points would equal -5 after running this code.
One key advantage of computers is that they can do the same thing several times very very quickly.
As programmers you need to be able to instruct a computer to repeat a task without having to write it out lots and lots of times. for that we have loops.
There are three key types of loops that you need to know how to write
Loops that run a set number of times - These are your typical for loop. This could be for a count that increases or for each element in an array. A simple for loop that just outputs the numbers from one to ten is shown below.
Dim x as Integer
For x = 1 to 10
Console.Writleline(x)
Next
As you can see, this is much easier than writing ten console.Writelines. now imagine if you needed one thousand numbers outputted, for loops save so much time!
Loops that run at least once - This loop runs, then checks a condition and decides as a result of the condition whether or not to the run the loop again.
Loops that run under certain conditions - This kind of loop is similar to the above, except the condition is checked before the loop runs at all, so theoretically the loop might not run at all. Think of this as an if statement that repeats until the condition is false