computing
computing
Summer Work
An Introduction to
Visual Basic Programming
You will need Visual Basic 2010 Express to complete these programming
tasks. Go here to download it:
http://bit.ly/11SqkQf
(If it does not download, then download and install the 2012 version, but
the screenshots in the tutorials will be different)
cothamschool creative inclusive confident respectful ambitious
ICT & COMPUTING DEPARTMENT
2. Select CONSOLE PROGRAMMING, and then enter the name of your project to in the text box at the bottom of the
dialog box.
cothamschool creative inclusive confident respectful ambitious
ICT & COMPUTING DEPARTMENT
1.3 Exercises
1. Change the program so that it displays your name and address underneath the first line of text
2. Change the program so that a blank line appears between the first line and your name and address
3. Change the program so that the user has to press ENTER to view each line of text.
cothamschool creative inclusive confident respectful ambitious
ICT & COMPUTING DEPARTMENT
2.0 Opening Programs using Console
Continue using the above program.
Process.Start("notepad")
1. Change your program so that it opens NOTEPAD at the end of the program.
Process.Start("iexplore")
2. Change the program so that opens INTERNET EXPLORER after opening NOTEPAD
Exercises
1. What other programs can you open in this way? Do some research and find out.
2. Can you find out how to open internet explorer to a website you specify?
cothamschool creative inclusive confident respectful ambitious
ICT & COMPUTING DEPARTMENT
02 – Variables
Visual Basic Programming
Variables are used to store (save) information while the program is running. This information can then be recalled and used
by the program at a later time.
1. Create a New Visual Basic Console Program and call it “Variables 1” (refer to previous tutorial for how to do this)
2. In between the text SUB MAIN() and END SUB type in the below code to set up a variable called “firstname”. The
variable is setup to store text data only.
Next we need to print the text “Input your name” to the top of the screen
3. Type in the following code to ask the user to enter their name:
4. Type in the following code to store the users answer inside the “firstname” variable you just setup:
firstname = Console.ReadLine
Finally we need to output the users name to the screen, by displaying the contents of variable “firstname”
5. Now type in the following code to output the contents of your variable to the screen:
Console.ReadLine()
& = and
6. Run the program by clicking the PLAY button on the toolbar to test the code. You screen output should be similar to
what is shown below when the program has completed:
1.2 Exercises
1. Comment your code so that it is clear what is going on
2. Ask the user to enter their favourite colour and then display it on the screen
3. Ask the user to enter their age and then display it on the screen
cothamschool creative inclusive confident respectful ambitious
ICT & COMPUTING DEPARTMENT
2.1 Number Variables
In this example program you will get the user to enter two numbers and then multiply them together and show the result. An
example of the final screen output is shown below:
1. Create a New Visual Basic Console Program and call it “Variables 2”. (refer to previous tutorial for how to do this)
Now we must setup two NUMBER variables to store each of the numbers that the user enters. This means we must declare
INTEGER variables rather than the STRING variables we used in the previous example.
2. In between the text SUB MAIN() and END SUB type in the following code to set up two number variables called
“firstnumber” and “secondnumber”:
Next we must get the user to enter two different numbers. The first number the user enters is to be stored in the variable
“firstnumber”. The second number the user enters is to be stored in the variable “secondnumber”.
3. Now type in the following code to store two numbers that the user enters:
The final stage is to multiple the numbers together and then display the result on the screen.
4. Type in the following code to multiple the two numbers together and prints the result to the screen:
* symbol = multiply
cothamschool creative inclusive confident respectful ambitious
ICT & COMPUTING DEPARTMENT
Your final code should now look like this:
5. Run the program by clicking the PLAY button on the toolbar to test the code. You screen output should be similar to
what is shown below when the program has completed:
• Addition = +
• Subtraction = -
• Multiplication = *
• Division = /
2. Alter you program so that a third number is entered and them multiplied by the total of the first two numbers
3. Alter the above program so that a fourth number is entered. The fourth number should then be taken away from the
total of the first three numbers.
cothamschool creative inclusive confident respectful ambitious
ICT & COMPUTING DEPARTMENT
Selection Statements
VB.NET Programming
Selection statements enable you to set up a section of code that may or may not get executed depending on whether a
condition is true or false.
IF statements are the first type of selection statements will we will look at.
You can follow the below instructions or follow the accompanying video tutorial.
3.1 IF statements
In this example program you will store the user’s age in a variable and then tell them whether they are old enough to drive or
not depending on their age. An example of the final screen output is shown below:
1. Create a New Visual Basic Console Program and call it “IF Statements 01” (refer to the first tutorial for how to do this)
2. In between the text SUB MAIN() and END SUB type in the below code to get the users age and store the answer in a
NUMBER variable called “age”:
We must now set up the IF statement that determines which code to execute depending on the users age. If the user is over
16 a message is displayed on the screen. IF statements must always take on the following structure:
You will notice if the user is not over 16 then the program does not output any message. We can fix this by including an ELSE
statement into the IF statement structure.
5. Change your IF statement code so that it looks like the code below:
6. Run the program by clicking the PLAY button on the toolbar to test the code. You screen output should be similar to
what is shown below when the program has completed:
Now the program outputs a message if the user is over or under 16. But nothing happens if the user is 16. We can fix this by
including an ELSEIF statement into the IF statement structure.
7. Change your IF statement code so that it looks like the code below:
8. Run the program by clicking the PLAY button on the toolbar to test the code. You screen output should be similar to
what is shown below when the program has completed:
3.2 Exercises
1. Write a new program that asks the user to enter an exam mark from 0 to 100. Display the grade it represents:
Merit(60 or more), Pass (40-59), Fail (under 40)
2. Write a program that decides whether you are let into a nightclub, they are only letting in females that are over 18.
Use the AND statement, then use a nested if statement