(DOCX, Unknown)

advertisement
Variables & Simple Data Types
Which data types should be used to store the following items of information?
1. Address
-
string
2. Date of birth
-
integers/characters
3. Weight (kg)
-
integers
4. Height (m)
-
integers
5. Gender
-
Boolean
6. Name
-
string
7. Telephone Number
-
integers
8. Email address
-
string
9. School ID number
-
integers
10. Initial
-
character
Write variable declarations in VB.net for the following...
11. An integer variable called counter which is initialised to ‘5’.
Dim counter As Integer = 5
12. A String variable called filePath which is initialised to ‘C://Users/Default/’.
Dim filePath As String = “C://Users/Default/”
13. A Boolean variable called voted which is initialised as ‘false’.
Dim voted As Boolean = false
14. A Char variable called qmark which stores a question mark.
Dim qmark As Char = “?”
15. A Single variable called starRating which is initialised to ‘3.5’.
Dim starRating As Double = 3.5
Programming Exercise: Hello World
Create a program using VB.net that will display the message ‘Hello World!’ when a button is
clicked. Your program should output the message ‘Goodbye Cruel World!’ when a second
button is clicked. You should create a String variable called output_str to store your output
message.
Extension task:
•
•
•
Create an integer variable called counter and initialise it to zero.
The value of counter should increase by 1 every time the ‘Hello’ button is clicked.
The value of counter should decrease by 1 every time the ‘Goodbye’ button is
clicked.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim result As String
result = "Hello world!"
output.Text = resultEnd Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim result As String
result = "Goodbye cruel world!"
output.Text = result
End Sub
End Class
Download