Saturday, September 27, 2008

Exercises today:

Asking a user for info that will be useful in making a dating application!

You will need a(n):



  1. Checkbox

  2. ComboBox

  3. Labels

You need to ask the user for some information about themselves and quanitify it! Make a scale of compatibility for two people. You will ask the same questions of two people on the same form.

Give them back a percetage and a memorable saying!

Here's my code for the Love Tester!

'When you click the button:


Dim love As Integer = 0
If (CheckBox1.Checked And CheckBox2.Checked) Then
love = love + 5
ElseIf CheckBox1.Checked Then
love = love - 2
End If
If TextBox1.Text.Length = TextBox2.Text.Length Then
love = love + 100
End If
If ComboBox1.SelectedItem = "Running" And ComboBox2.SelectedItem = "Running" Then
love = love + 11
End If
If love > 50 Then
lblLove.Text = "You are a good match " & love
ElseIf love > 20 Then
lblLove.Text = "You are an okay match " & love
Else
lblLove.Text = "You should run! " & love
End If

Student Grader

  • GUI Based
  • Ask User for a grade (number from 0-100)
  • Give the project a letter grade based on an if and else if series of conditions
  • Add a check box for extra credit, if selected add an extra 5 points to their grade!
  • A >= 90
  • B >= 80
  • C >= 70
  • D >= 60
  • F < "60"

Error Checking with isNumeric

Dim distance As Decimal = 0
Dim gallonsused As Decimal = 0
Dim mpg As Decimal = 0
If IsNumeric(Textgas.Text) = True And IsNumeric(Textmiles.Text) = True Then distance = Textmiles.Text
gallonsused = Textgas.Text
mpg = distance / gallonsused
Math.Round(mpg, 2)

mpgdisplay.Text = (mpg & " is your miles per gallon (mpg)")
Dim alertvariable As String = "Alert you are a gas guzzler!!!"
If mpg < 10 Then
alertlabel.Text = alertvariable
End If
If gallonsused > 50 Then
lblgasused.Text = ("you are using too much gas")
Else
MsgBox("You messed up. Gotta enter numbers")
End If
Else
MsgBox("Enter numbers")
Textmiles.Text = ""
Textgas.Text = ""
End If

Here are some interesting links:

http://blogs.msdn.com/vbteam/

You can ask questions here:

http://stackoverflow.com/

Saturday, September 20, 2008

What I Learned in the Second VB "Class"

Please write on your blog what you learned today!

Follow along with the book by reading and doing exercises from Chapter 1 through Chapter 5. If statements are from Chapter 7.

Code

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim name As String = nameOfStudent.Text
'add the ability to read in the gpa from the user!!!
Dim gpa1 As Decimal = gpa.Text
Dim newStudent As New Student(name, gpa1)
'using the name entered by the user in the constructor!!
studentName.Text = newStudent.getName
gpaLbl.Text = newStudent.getGPA

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'first we will get the school name from the user!!!
Dim schoolName As String = txtSchoolName.Text
'now we need to write out the school name TO the user!!!
displayName.Text = schoolName
End Sub
End Class

Object Oriented Programming Review!

On your blog, pick a topic that you have some expertise with or something you believe can be easily solved using an OO approach.

Please write down the class name, the attributes, and the methods.

Class Employee

Attributes:

Methods:

Visual Basic Certifications

Here is the certification information.

Thursday, September 18, 2008

Visual Basic Coding

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim newStudent As New Student("joe", 2.3)
Label1.Text = newStudent.hey
End Sub
End Class


Public Class Student
Dim name As String
Dim gpa As Decimal

Public Sub New(ByVal name1 As String,ByVal gpa1 As Decimal)
'Intializes object from datarow
name = name1
gpa = gpa1
End Sub

Public Function hey() As Double
Return gpa
End Function

End Class

Saturday, September 13, 2008

What did you learn today?

What, if anything, did you learn today?

On September 13th, we did the following programs:
  1. Miles per gallon calculator
  2. Number-squarer
  3. Subtract the second number from the first number
We discussed:
  1. Object-oriented programming
  2. UML diagrams for LunchCart, Baseball team
  3. History of programming
  4. Began Visual Basic syntax

For class two

Please read chapter 1 and 2 in the textbook and the links below.

MPG code and Squaring Number Code

Module Module1

Sub Main()

Console.WriteLine("Please enter the miles driven (in miles)")
Dim milesDriven As Decimal = Console.ReadLine()
Console.WriteLine("Please enter the gas used (in gallons)")
Dim gasUsed As Decimal = Console.ReadLine()
'declaring variable gasUsed as a decimal
'and reading line from the console!
Dim mpg As Decimal = milesDriven / gasUsed
Console.WriteLine(mpg & " is the mpg used")

'Square your number program!
Console.WriteLine("Please enter a number to be squared ")
Dim numberToBeSquared As Decimal = Console.ReadLine
Dim numberSquared As Decimal = numberToBeSquared ^ 2
Console.WriteLine(numberToBeSquared & " was your number")
Console.WriteLine(numberSquared & " is the number squared")
Console.WriteLine("Enter any number to quit")
Dim endProgram As String = Console.ReadLine
'* multiplication
'/ division

End Sub

End Module

Object Oriented Programming

Constructors
Constructors allow you to create an object and provide it with an initial set of data so it can initialize properly. Without constructors, you create an object, then need to all a separate method to initialize it. Two steps.

Encapsulation
Is data hiding. You can create a set of procedures or methods and properties that form an interface. Other code can then use these methods with any knowledge of the code within the methods. The procedures or methods you write is called an implementation. The implementation is encapsulated within the interface.

Inheritance
The concept that an object can gain the interface and actual behaviors (implementation) of another object, then extend that interface or those behaviors. Say you create a generic Product object that handles things common to all your products. From it you may create specialized Perishable and Non-Perishable objects. Both objects inherit the original Product object's interface and behaviors but can extend or change some of those behaviors.

Initializers
An initializer allows you to declare a variable and assign it an initial value all in one statement.

Object-Based
This loosely describes a language that interacts with objects easily and directly.

Object-Oriented
Object oriented languages must support polymorphism, inheritance and encapsulation (PIE).

Overloading
This allows you to declare multiple procedures with the same name in the same scope each having different input parameter specifications. For instance, you many define a function CreateTotal that totals the values in its array argument and another CreateTotal function that takes 5 long arguments and returns their sum. You call CreateTotal and pass it the proper parameters and the language will know which version of the function to use.

Overriding
When using inheritance your new class gets all the methods from its parent or super class. However you may want a different implementation for one of these methods. You do so by overriding the original (inherited) method with your own code. Your new code may even call the original method in the parent class.

Polymorphism
This is the ability to have two different objects of two different types both implement the same method. It lets you write code that calls that method regardless of which type of object is in use at the moment.

Shared Members
Otherwise know as class, static or instance members. Shared members are methods or variables that are equally available to all instances of a class. Every object that you create, based on a given class, shares these same variables and routines.

User Interface Inheritance
Means you can create a VB form template then derive all your other forms from this template. All other forms will inherit the look and code from the template form. A change to the original form will propagate out to all the child forms.


More information:

http://en.wikipedia.org/wiki/Object-oriented_programming

Object Oriented Programming

Here's some information from Microsoft about OO programming with VB.

 And
As
Call
Do
Exit
False
True
For
Function
GoTo
If
Loop
Me
Next
Not
Nothing
Option
Or
Private
Public
Resume
Step
Sub
Then
Until
While
If..Else..ElseIf..Then

Getting to know you!

Welcome to Visual Basic at Miami Dade Community Education

In this class we will learn how to program with Visual Basic .NET with an emphasis on object oriented design. Everyone will feel comfortable designing and coding projects by the end of the class. We will analyze problems in class and code solutions in groups and individually.

I'm very excited to be your teacher. I look forward to a great class!



Today's outline:

  • Getting logged in
  • Introductions
  • Getting the book
  • Review the syllabus.
  • Pseudocode: You can't write code if you don't understand the problem!
  • Expectations for the class
    What are your expectations for this class??
  • UML for a LunchCart
  • Attributes and Methods
  • Comments, source code, and other terminology
  • Writing a console program
  • HelloWorld
  • Calculate mpg
  • Square numbers
  • Keeping current with programming trends
  • Feedback
Interested in source code? Check out Google Chrome.