Module Module1
Sub Main()
'do some procedural programming
'user enters a number and gets back the number squared
Console.WriteLine("Please enter a number")
Dim a As Integer = Console.ReadLine
Dim newNumber = a * a 'squared the number
Dim newNumber2 = a ^ 2
Dim newNumber3 = Math.Pow(a, 2)
Console.WriteLine(newNumber)
Console.WriteLine(newNumber2)
Console.WriteLine(newNumber3)
'ask the user for the side of a square. give the user back the perimeter and area.
Console.WriteLine("Please enter the side of a square:")
Dim sideOfSquare As Decimal = Console.ReadLine
Console.WriteLine("The area is " & calculateArea(sideOfSquare))
Console.WriteLine("The perimeter is " & calculatePerimeter(sideOfSquare))
Console.WriteLine("The area of a circle with a radius of 10 is " & calculateAreaOfCircle(10.0))
Console.ReadLine()
End Sub
Function calculatePerimeter(ByVal side As Decimal) As Decimal
Return side * 4
End Function
Function calculateArea(ByVal side As Decimal) As Decimal
Return side * side
End Function
'define a function that calculates the area of a circle given the radius!
Function calculateAreaOfCircle(ByVal radius As Decimal) As Decimal
'pi* r^2
Return Math.PI * (radius ^ 2)
End Function
End Module
Saturday, May 16, 2009
Create a blog
- Go to www.blogger.com
- Create a blog, choose the name you want
- First post will be about:
What is object oriented programming?
What is a class?
What is an object?
What is an attribute? - Publish your blog.
- Leave a comment on this blog with your URL!
First VB project
'you will ask the user for the distance they've driven in miles
'you will ask the user for the amount of gas they used
'give the user the miles per gallon of their vehicle!
'you will ask the user for the amount of gas they used
'give the user the miles per gallon of their vehicle!
Code from first example
Module Module1
Sub Main()
Console.WriteLine("Hello World!")
Console.WriteLine("Please enter your name:")
Dim userName As String = Console.ReadLine()
'declaring a variable to hold a String!
Console.WriteLine("Welcome " & userName & " we are glad you are here!")
Console.WriteLine("How many years have you lived?")
Dim ageOfUser As Integer = Console.ReadLine()
Dim userInEightYears As Integer = ageOfUser + 8
Console.WriteLine("In eight years you will be " & userInEightYears & " old")
Console.WriteLine("Someone half your age is " & ageOfUser / 2 & " years old")
Console.WriteLine("Someone twice your age is " & ageOfUser * 2 & " years old")
If ageOfUser > 10 Then
Console.WriteLine("The secret to life is do things you enjoy!")
Else
Console.WriteLine("You already know the secret!")
End If
Console.ReadLine()
'this is conditional logic
End Sub
End Module
Sub Main()
Console.WriteLine("Hello World!")
Console.WriteLine("Please enter your name:")
Dim userName As String = Console.ReadLine()
'declaring a variable to hold a String!
Console.WriteLine("Welcome " & userName & " we are glad you are here!")
Console.WriteLine("How many years have you lived?")
Dim ageOfUser As Integer = Console.ReadLine()
Dim userInEightYears As Integer = ageOfUser + 8
Console.WriteLine("In eight years you will be " & userInEightYears & " old")
Console.WriteLine("Someone half your age is " & ageOfUser / 2 & " years old")
Console.WriteLine("Someone twice your age is " & ageOfUser * 2 & " years old")
If ageOfUser > 10 Then
Console.WriteLine("The secret to life is do things you enjoy!")
Else
Console.WriteLine("You already know the secret!")
End If
Console.ReadLine()
'this is conditional logic
End Sub
End Module
Second assignment!
'Making a guessing game that asks the user for a number
'if the number is less than 10, tell them it is bad luck
'if the number is 12, tell them the number is okay
'if the number is 101, tell them they are great people for guessing such a number
'else say thanks for your time
'if the number is less than 10, tell them it is bad luck
'if the number is 12, tell them the number is okay
'if the number is 101, tell them they are great people for guessing such a number
'else say thanks for your time
Saturday, April 4, 2009
Saturday, March 28, 2009
Project Discussion / Database review next Saturday!
If you are interested in one last class, we can meet here next Saturday at 2pm to discuss projects you are working on and database connectivity! Email me if you are interested:
david.freer@gmail.com
david.freer@gmail.com
Subscribe to:
Posts (Atom)