Friday, October 29, 2010

Processing - an open source programming language

From http://processing.org/

"Processing is an open source programming language and environment for people who want to create images, animations, and interactions. Initially developed to serve as a software sketchbook and to teach fundamentals of computer programming within a visual context, Processing also has evolved into a tool for generating finished professional work. Today, there are tens of thousands of students, artists, designers, researchers, and hobbyists who use Processing for learning, prototyping, and production.."

More -->

Wednesday, October 27, 2010

DELETE


The delete operation is used to delete records from a table. A filter must be specified for the operation to take place (or you may end up deleting everything!) 
 

DELETE FROM Customers WHERE State = @State
Deletes all the customer records matching the parameter of State..

Note the following code sample:

Public Sub deleteFromCart(CartID As Integer)


        Dim myConn As SqlConnection = New SqlConnection(MyConnString)
        myConn.Open()
        Dim strSQL As String = "DELETE FROM XYZCart WHERE CartID = @CartID"
        Dim myComm As SqlCommand = New SqlCommand(strSQL, myConn)
        myComm.Parameters.AddWithValue("@CartID", CartID)
        myComm.ExecuteNonQuery()
        myConn.Close()


End Sub

Once again, parameters are used to pass the criteria used to delete the records and the ExecuteNonQuery method of the command object is engaged to complete the operation.

UPDATE

The update operation allows us to make changes to existing fields.

Using a filter - WHERE
By using a filter (WHERE), we can specify which fields of which records to update. Once again, there is no data retrieved from the database as part of the operation. For this reason, we do not need to use a data adapter or dataset.

UPDATE Customers SET FirstName=@FirstName,LastName=@LastName WHERE CustomerID=@CustomerID

Updates the specified fields of the a customer record matching the parameter of CustomerID.

BE CAREFUL
If you omit the filter, you will update all records, as below:

UPDATE Customers SET FirstName=@FirstName,LastName=@LastName

Updates all of the specified fields of all of the customer records.

Note the following code sample:

Public Sub updateCartQuantityPlusOne(CartID As Integer)

    Dim myConn As SqlConnection = New SqlConnection(MyConnString)
    myConn.Open()
    Dim strSQL As String = "UPDATE XYZCart SET Quantity = Quantity + 1 WHERE CartID = @CartID"
    Dim myComm As SqlCommand = New SqlCommand(strSQL, myConn)
    myComm.Parameters.AddWithValue("@CartID", CartID)
    myComm.ExecuteNonQuery()
    myConn.Close()



End Sub

Once again, parameters are used to pass the data to update the record and the ExecuteNonQuery method of the command object is engaged to complete the operation.

INSERT

The insert statement modifies the contents of the database in that we use it to create new records. By default, there is no data retrieved from the database as part of the operation. For this reason, we do not need to use a data adapter or dataset.

The INSERT SQL Statement

INSERT INTO TableName (FieldName1, FieldName2) VALUES (@FieldName1, @FieldName2)

Inserts data into the specified fields, creating a new record. Note that parameters are used to pass the values that need to be inserted into the fields.

Note the following code sample:

Public Sub insertIntoCart(ProductID As Integer, Quantity As Integer)
        

    Dim myConn As SqlConnection = New SqlConnection(MyConnString)
    myConn.Open()
    Dim strSQL As String = "INSERT INTO XYZCart (ProductID, Quantity, CustomerID) VALUES (@ProductID, @Quantity, @CustomerID)"
    Dim myComm As SqlCommand = New SqlCommand(strSQL, myConn)
    myComm.Parameters.AddWithValue("@ProductID", ProductID)
    myComm.Parameters.AddWithValue("@Quantity", ProductID)
    myComm.Parameters.AddWithValue("@CustomerID", 0)
    myComm.ExecuteNonQuery()
    myConn.Close()



End Sub

Parameters are used to pass the data for insertion. Note that they are passed to the AddWithValue method in the order they are specified in the SQL statement.

Also note, the ExecuteNonQuery method of the command object is engaged to complete the operation. This is common to the insert, update & delete operations.

Parameters (place-holder values)

SQL statements may contain ‘hard-coded’ values such as the following:

SELECT FieldName1, FieldName2 FROM TableName WHERE ColumnID = ‘1’ AND FieldName1 = ‘X’

..or they may contain a parameter(s) that is used as a place-holder value such as in the following:

SELECT FieldName1, FieldName2 FROM TableName WHERE ColumnID = @ColumnID AND FieldName1 = @FieldName

Using a parameter allows the SQL statement to work dynamically - that is, to take a current value and use it in the query. A parameter is preceded by the ‘@’ symbol.

When we define a parameter, we must provide further explanation as to where the real value will come from, at run time.

Note the following code sample:

Dim strConnectionString As String = "Provider=Microsoft.Ace.OLEDB.12.0;" & _
"Data Source=C:\FolderName\DatabaseName.accdb"
Dim MyConnection As New OleDb.OleDbConnection(strConnectionString)
MyConnection.Open()
Dim MyCommand As New OleDb.OleDbCommand("SELECT * FROM Customers WHERE CustomerID = @CustomerID AND LastName = @LastName", MyConnection)
MyCommand.Parameters.AddWithValue(“@CustomerID”, lblCustomerID.Text)
MyCommand.Parameters.AddWithValue(“@LastName”, lblLastName.Text)
Dim MyDataset As New Data.DataSet
Dim MyDataAdapter As New OleDb.OleDbDataAdapter(MyCommand)
MyDataAdapter.Fill(MyDataset, "MyQueryResults")
MyConnection.Close()

This select command includes two parameters - @CustomerID and @LastName. The next two statements inform the command object of where to find the actual values to use. The @CustomerID parameter’s value can be found in the text property of the label called lblCustomerID and the @LastName parameter value can be found in the text property of the label called lblLastName.

Notes on using parameters:
    •    Parameter names are preceded by the ‘@’ symbol
    •    You may name a parameter anything you like, however convention is to name the parameter strictly after the field name it represents.
    •    Each parameter must be passed to the command object’s Parameters.AddWithValue method
    •    Parameters must be passed to the command object’s Parameters.AddWithValue method in the same order as they are defined in the SQL statement.
    •    Spelling and case must match

SELECT


A select operation enables records to be retrieved from a database. When records are retrieved, they are brought back to the application and placed into memory. Because of this, a select operation contains objects that also allow these records to be stored.
It is important to note that the select operation does not modify the contents of the database, it simply retrieves data.

Variations on the SELECT SQL statement:

SELECT * FROM TableName
Returns all fields from all records

SELECT * FROM TableName WHERE ColumnID = ‘1’
Return all fields of the record that has a ColumnID of 1

SELECT FieldName1, FieldName2 FROM TableName
Returns the fields specified, from all records

SELECT FieldName1, FieldName2 FROM TableName WHERE ColumnID = ‘1’
Returns the fields specified, from the record that has a ColumnID of 1

SELECT FieldName1, FieldName2 FROM TableName WHERE ColumnID = ‘1’ AND FieldName1 = ‘X’
Returns the fields specified, from the record that has a ColumnID of 1 and FieldName1 has a value of X.
Another example which substitutes literal values for parameter values:

Public Function getCart() As Data.DataTable

    Dim myConn As SqlConnection = New SqlConnection(MyConnString)
    myConn.Open()
    Dim strSQL As String = "SELECT * FROM XYZCart"
    Dim myComm As SqlCommand = New SqlCommand(strSQL, myConn)
    Dim dsResults As New Data.DataSet
    Dim daDataAdapter As New     Data.SqlClient.SqlDataAdapter(myComm)
    daDataAdapter.Fill(dsResults, "CartResults")
    myConn.Close()
    Return dsResults.Tables("CartResults")

End Function

At the conclusion of the operation, any retrieved results are stored in the dataset.

Database Operations

There are four commands that may be executed against database tables:

* SELECT
* INSERT
* DELETE
* UPDATE


Commands are executed using Structured Query Language (SQL).

Algorithms

Sequence

Selection

Anatomy of a class

Instantiation

MyBase.New


The MyBase keyword allows calls from the child class to be made on state & behaviour within the parent class (remember, the parent is sometimes also called the base class).

Access Modifiers | Private, Public & Protected

An access modifier determines the visibility of a class member (states & behaviours).
An access modifier of Public allows a class member to be accessed from external objects & is denoted on a class diagram with a + (addition) symbol.
A Private access modifier allows only internal access and prevents access by external objects. Private access is denoted on a class diagram with the - (minus) symbol.
The Protected access modifier allows internal access and access by child classes. Protected access is denoted on a class diagram with the # (hash) symbol.

Inheritance

Classes contain state & behaviour - things they have & things they do. Just as humans inherit certain states & behaviours from their parents, so too can classes.


Often referred to as a Parent-Child relationship. Other names include:

Parent | Superclass | Base class | Generalisation

Child | Subclass | Derived class | Specialisation

The Constructor - New()

A constructor is represented on a class diagram as: Visibility New(ParametersIfAny) and is always the first behavior in the list.

A constructor behavior may require parameters to execute. This solely depends on the requirements of the system and the design of the object. Parameters are required if it makes sense that the object should know something about its state upon creation.

For instance, an object created from the Player class would not make much sense if it's Name state did not have a value. The account status of the object may also be very important to establish. In the diagram below, you will notice that the constructor for the Player object contains a number of parameters.
+New(NewName: String, NewHealth: Integer, AccountStatus: Boolean, NewPassword: String)

As the designer of the class, I have decided that a Player object would not make sense unless all of the states were established at the time of object instantiation, however, the Sword and Flight class do not require any parameters for object instantiation.


Note: A constructor behavior cannot return a value, therefore it is always implemented as a subroutine.

Why hide object state?

By restricting access to an objects internal state via getter behaviors, we can ensure that all values are valid before assigning them to internal state.

For instance, the Player class has a state called Name. If an external object has direct access to this state, there is the possibility that an incorrect or invalid value may be assigned to it, however, if that state can only be modified via a setter behavior, the behavior implementation (code) can check the value for its validity before assigning the value to the Name state. Eg. Is the name the correct length, type, etc.

Mutators: Set

Classes may contain mutator behaviors for some or all of their states. This enables other objects to change the value of a state. A mutator behavior is usually implemented as a subroutine, unless there is a requirement for a return message - such as a confirmation that the change took place, in which case you would use a function (which could return a value, such as True or False).

A setter subroutine requires a parameter which represents the new value of the state.

For example, the Player class now contains a number of mutator behaviors. Following convention, the names of these behaviors begin with the word Set.

In a class diagram, the format for a setter behavior(subroutine) looks like this:

Visibility SubroutineName(Parameters: DataType)

...as can be seen in the Player class example:

+SetName(NewName: String)

The implementation (code) for a mutator, reads the parameter that is passed to it and updates the value of the state with the value of the parameter. In other words, the SetName() function will read the String parameter passed to it and then change the value of the Name state.

An mutator behavior has visibility of Public.

Accessors: Get

Classes may contain accessor behaviors for some or all of their states. This enables other objects to read the value of a state. An accessor behavior is nearly always implemented as a function, as a function returns a value to the calling procedure.

For example, the Player class now contains a number of accessor behaviors. Following convention, the names of these behaviors begin with the word Get.

In a class diagram, the format for a behavior that returns a value(function) looks like this:
Visibility FunctionName(ParametersIfAny):ReturnDataType

...as can be seen in the Player class example:
+GetName():String

The implementation (code) for an accessor, reads and returns the value of the state being accessed. In other words, the GetName() function will return a String (containing the value of the Name state) to the calling procedure.

An accessor behavior has visibility of Public.

Accessors & Mutators

Below you will find a our class diagram - notice there are a number of behaviors. These behaviors are known as accessors and mutators and will allow external objects to access (read), and in some cases, change the value of an objects state. Each of these behaviors is preceded by a plus sign. This denotes that the behavior is public and can be accessed by other objects directly.

Visibility: Private & Public


Following the laws of encapsulation, when designing a class, it is important to define the visibility of the states and behaviors contained within the class. This is known as visibility.

Notice in the class diagram below, each state has a minus preceding its name and each behavior has a plus preceding its name. A minus denotes that a state or behavior is private and cannot be directly accessed from external objects. A plus denotes that a state or behavior is public and may be accessed externally by other objects.

When an object state is private, no other object can read or change the value.



What is Encapsulation?


Encapsulation is the process of packaging the base functionality of a class and providing access to the features of the class through a collection of behaviors. This means that the inner workings of the class are hidden from other classes and cannot be directly accessed.

Objects are responsible for maintaining their own state & behavior.

This means that a Sword object should not be able to directly manipulate a Player state and vice verse. For this reason, object state is hidden & behaviors may be created to allow external objects access and change state values.

Another way to refer to encapsulation is 'information hiding'.

Encapsulation (Information Hiding)

"Information hiding - Wikipedia, the free encyclopedia" ( http://bit.ly/9yZwyY )

Inheritance

Inheritance is said to be an is-a relationship. In the example below we can see 4 classes - but actually, the diagram illustrates that there is one superclass and three sub-classes.

Level is the superclass. WaterWorld, RainbowWorld and DragonWorld are sub-classes which have inherited state and behavior from the super class, as well as having their own unique state and behavior.


In plain English we can say that a WaterWorld object is-a Level object, a RainbowWorld object is-a Level object and a DragonWorld object is-a Level object

Inheritance is a feature supported by many programming languages and lies at the heart of Object Oriented Design.

The example above shows the correct notation to illustrate inheritance in a class diagram.

Composition

Composition is said to be an has-a relationship; one object is composed of other objects. For instance, a car object is actually composed of many other objects such as an engine, doors, steering wheel etc.

The class diagram below is an example of composition, you will notice that the Player class has two has-a relationships. In plain English we can say that a Player object has a Sword object and a Player object has a Flight object.


You will notice there is a number on each relationship. This number represents the multiplicity between the objects in the relationship. In this example, a Player has one(1) Sword object and one(1) Flight object.

The example above shows the correct notation to illustrate composition in a class diagram.

Multiplicity

"How to show Multiplicity on a class diagram" ( http://bit.ly/cE3P7s )

Star UML

Star UML is a free UML modelling program. You can download it here:

"StarUML - The Open Source UML/MDA Platform" ( http://bit.ly/b43TLS )

Parameters


The inputs required by a behavior are often called Parameters and like state, a data type is required in the definition of a parameter.

The format for representing parameters in a behavior:  

BehaviorName(Parameter: DataType)

The format for representing a behavior that has no parameters:  

BehaviorName()

Class example:



The Login behavior of a class called Player class may look like this:

Login(Password: String)
The parenthesis (brackets) which follow the name of the behavior are used to identify any parameters that are required for the behavior to function. In this case of the Login behavior, a parameter called Password which has a data type of String is required by the behavior for it to function. In other words, the Player class has a Login function but it needs a String password to execute.

The Logout behavior of the Player class looks like this:

Logout()

You will notice that the parenthesis for this behavior are empty. This behavior does not require any parameters to execute.

There are two behaviors in the Player class which are responsible for increasing and decreasing the Player class Health state:
IncreaseHealth(Increase: Integer)
DecreaseHealth(Decrease: Integer)

Both of these behaviors require an Integer (whole number) parameter. In other words, these behaviors need to know how much to increase or decrease the Player Health state. As you might imagine, a Player may incur varying amounts of damage or gain varying amounts of health depending on the various interactions within game play.

What is Date?

The Date data type is used to represent dates ranging from January 1 of the year 0001 through December 31 of the year 9999, and times from 12:00:00 AM (midnight) through 11:59:59.9999999 PM.

What is Decimal?

The Decimal data type is used to store currency and other decimal values as it supports up to 28 digits to the right of the decimal point.

What is Boolean?

 The Boolean data type is a simple True/False type.

What is an Integer?

 The Integer data type is a numeric type and can hold whole numbers - such as 1, 100, 3500.

What is a String?


The String data type can hold any combination of keyboard characters - this means letters, numbers and special characters.

What is a Class Diagram?



A class diagram is the format used to design reusable objects. It is a description of the class only. A class diagram does not include any implementation details - in other words, it does not include code; which is language specific. It is up to the developer to make the class work.

From a class diagram, a developer/programmer can create the class in just about any language. From there, the class may be used to create many objects in a computer program.

What is a Class?

In OOD, when we design objects to be used in a computer program, these objects become a class. You can think of a class as being a blueprint or a plan from which many objects may be created. For example, an architect may design a house plan, and from that house plan, a builder may build many houses. It is the same with a class. The blueprint for a object is called a class and they are represented using a class diagram.

What is Object Oriented Design?

Object Oriented design is the process of planning a program of interacting objects for the purpose of solving a software problem - such as a business application or gaming program. It is one approach to software design and usually takes place before any code is written.

Once upon a time, programs were written in continuous lines of code. This lead to code duplication and this in turn lead to systems that were very difficult to maintain.

Object Oriented design views a system as a number of objects, each with their own responsibilities. Multiple identical objects may be created using a common blueprint, called a class. OOD promotes code reuse.

Objects may represent real world objects, imaginary objects or they may represent lists of data.

Class Diagram

 From http://en.wikipedia.org/wiki/Class_diagram

"In software engineering, a class diagram in the Unified Modeling Language (UML) is a type of static structure diagram that describes the structure of a system by showing the system's classes, their attributes, and the relationships between the classes."

Read more >>>

What Is an Object?

From http://download.oracle.com/javase/tutorial/java/concepts/object.html

"Objects are key to understanding object-oriented technology. Look around right now and you'll find many examples of real-world objects: your dog, your desk, your television set, your bicycle.

Real-world objects share two characteristics: They all have state and behavior. Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes). Identifying the state and behavior for real-world objects is a great way to begin thinking in terms of object-oriented programming." Read more >>>

The For loop

The For loop is used when the number of repetitions is known. It uses a single variable to start the loop, and indicates how many times the loop needs to execute.

For intCount = 0 To 5
   msgbox("This is loop number " & intCount)

Next


The loop counter variable in this instance is intCount. It begins at 0. Each pass of the loop causes the loop counter to increment +1. The loop will execute 6 time - from 0 to 6.

What is a loop?

Loops allows a programmer to repeat a block of code a number of times while some condition is true, or until some condition becomes true. For instance, a loop could be used to prompt a user for an answer until the correct input is entered.

A loop must contain a starting condition and an ending condition. It is very important that a loop is able to reach an ending condition or we end up with what what is called an ‘infinite loop’ – a loop that never ends. This can cause our programs to behave abnormally and may even cause a computer to ‘crash’.

What is an array?

An array is a list of values referred to by a single name. Arrays make it easy to access a list of related values. They can store lists of names, values or objects. Whenever you want to hold a list of values in memory for further processing or display, an array is an appropriate data structure.



Some terminology

Index
An index is a numbered position within the array. An array index begins at zero(0)

UpperBound
The UpperBound is the maximum index in an array.

Element
An element is the value (or object) contained within an index.


Note the difference
While the UpperBound & the Length of an array sound very similar, they are not the same at all.

Making a Program Choose Between Two Possibilities: The If...Then Statement

MSDN http://msdn.microsoft.com/en-au/library/whz9yas9.aspx

Comparison Operators / Relational Operators

Comparison operators are used to compare values.

=  : Equality
<>  : Inequality
 > : Greater than
 < : Less than
 >=  : Greater than or equal to
 <= : Less than or equal to

Logical Operators

Logical operators perform conditional and, or, and not operations

And          : Used to evaluate two operands(values) as being true (or false)
Or            :
Used to evaluate one or more operands(values) as being true (or false)
Not          :
Used to evaluate whether an operand(value) is not true (or not false)

Constructor

The constructor of a class is implemented as a subroutine. The constructor may or may not require parameters. A subroutine cannot return a value.


Code eg 1: Constructor with no paramters

Public Sub New()
' Code does something...
End Sub

Code eg 2: Constructor with paramters
Public Sub New(NumberOfPoints As Integer, UserName As String)
' Code does something with parameters...
End Sub

Programming Behavior

Each behavior of a class is implemented as a procedure. A procedure may be a subroutine or a function.

Procedures may or not require parameters to execute.


Subroutine
When the behavior simply needs to execute some code, we use a subroutine.

Code eg 1: Subroutine with no parameters
Public Sub NameOfBehavior()
    'Code does something
End Sub
Code eg 2: Subroutine with parameters

Public Sub Login(UserName: String, Password: String)
    'Code does something with parameters...
End Sub


Function
When the behavior is required to return a value to calling procedure, we use a function.

Code eg 1: Function with no parameters
Public Function NameOfFunction() As String
    'Code does something
    Return "Sample return String"
End Sub
Code eg 2: Function with parameters

Public Function getLastName(FirstName: String) As String
    'Code does something with parameters...
    Return LastName
End Sub

Programming State

An object state (things the object has - attributes like Name, Price, Damage) is simply a value that needs to be stored in memory. Object states are implemented as constants or variables.

Note: Other terms for state include property, attribute and data member.


Constant
When we need to store a value that does not change, we declare a constant.

Code eg: Constant Declaration
Private Const strThisConstant As String = "Something"

        Variable
         When we need to store a value that will need to change, we use a variable.

Code eg: Variable Declaration
Private strThisVariable As String = "Something"

Making a Computer Do Something: Writing Your First Procedure

MSDN http://msdn.microsoft.com/en-au/library/74dh43ez.aspx

Parameters in Subroutines & Functions

Sometimes a behavior will require further information to accomplish a task. When an input is required for a behavior to execute, this input is passed to the procedure as one or a number of parameters (sometimes called arguments).

Code eg: Subprocedure using parameters.

Public Sub Login(Username As String, Password As String)
    ' Code does something
End Function

Code eg: Function using parameters.

Public Function Calculate(NumberOne As Integer, NumberTwo As Integer) As Integer
    ' Code does something
   Return AValue
End Function

Functions

A function returns a value to the procedure that called it.

Code eg 1: Function.

Public Function CalculateScore() as Integer
        ' Declare variables
        Dim TotalDamage As Integer = 555
    Dim TotalAgility As Integer = 6
        ' Create the expression
        Dim TotalPoints As Integer = TotalDamage * TotalAgility
    Return
TotalPoints
End Function

A function returns a value to the calling procedure. In the above case, the function will return the value of the variable called TotalPoints. The As Integer part of the function header, indicate that the function will return a value that is of the Integer type.

Code eg 2: Function.

Public Function getFirstName() as String
    Return strFirstName
End Function

This new example shows a function that will return a String value.

Subroutines

A subroutine simply executes code when called by another procedure.

Code eg: Subroutine.

Public Sub CalculateScore()
        ' Declare variables
        Dim TotalDamage As Integer = 555
        Dim TotalAgility As Integer = 6
        ' Create the expression
        Dim TotalPoints As Integer = TotalDamage * TotalAgility
End Sub

A subroutine does not return a value to the calling procedure.

If you need to return a value - use a function.

Expressions

An expression in a programming language is a combination of values, variables, operators, and functions that are evaluated to produce another value.

Multiplication

Code eg: Multiplication of two variables.

' Declare variables
Dim TotalDamage As Integer = 555
Dim TotalAgility As Integer = 6
 ' Create the expression
Dim TotalPoints As Integer = TotalDamage * TotalAgility

The expression in this example will evaluate to 3330.

Division


Code eg: Division of two integer variables

' Declare variables
Dim NumberOne As Integer = 9
Dim NumberTwo As Integer = 3
' Create the expression
Dim Result as Integer = NumberOne / NumberTwo

The expression in this example will evaluate to 3.

Subtraction

Code eg: Subtraction from two integer variables

' Declare variables
Dim TotalPointsPossible As Integer = 200
Dim TotalPlayerMisses As Integer = 50
' Create the expression
Dim TotalScore As Integer = TotalPointsPossible - TotalPlayerMisses

                    The expression in the example will evaluate to 150.

Addition



Code eg: Addition of two integer variables.

' Declare variables
Dim RoundOneScore As Integer = 5000
Dim RoundTwoScore As Integer = 4678
' Create the expression
Dim TotalScore As Integer = RoundOneScore + RoundTwoScore

                    The expression in the example will evaluate to 9678

Arithmetic Operators


The following are arithmetic operators. They may be used in arithmetic expressions (maths problems)
  • + Addition Operator
  • - Subtraction Operator
  • / Division Operator
  • * Multiplication Operator

Arrays: Variables That Represent More Than One Value

http://msdn.microsoft.com/en-au/library/ms172582.aspx

Words and Text: Using String Variables to Organize Words

From http://msdn.microsoft.com/en-au/library/whhs118y.aspx

"In this lesson, you will learn how to use the String data type to represent words and text.
The previous lesson showed how to use variables to store data in a program, and that each variable must be of the appropriate type for the data that it will store. In this lesson, you will learn more about the String data type, which is used to store text." Read more >>>

Representing Words, Numbers, and Values with Variables

From http://msdn.microsoft.com/en-au/library/9kc1d337.aspx

"Variables are an important concept in computer programming. A variable is a letter or name that can store a value. When you create computer programs, you can use variables to store numbers, such as the height of a building, or words, such as a person's name. Simply put, you can use variables to represent any kind of information your program needs.

You might ask, "Why use a variable when I could just use the information instead?" As the name implies, variables can change the value that they represent as the program is running. For example, you might write a program to track the number of pieces of candy you have in a jar on your desk. Because candy is meant to be eaten, the number of pieces of candy in the jar is likely to change over time. Rather than rewriting your program every time that you get a sugar craving, you can represent the number of pieces of candy with a variable that can change over time...." Read More >>

Naming Conventions

Variables are prededed by a prefix to indicate the data type of the item. This method is known as a naming convention and improves the readability of your code. It is very similar to the way presentation objects from the toolbox are named.

Name prefixes for the following data types:
  • String - str
  • Integer - int
  • Boolean - bln
  • Decimal - dec

Arrays

An array is an indexed list of related information of the same data type. One way to think of an array is list of variables of the same data type.

Each position in the array is called an Index. Indexes begin at zero (0).

A declaration statement is used to declare the existence of the array. It is defined as a particular data type. Each index may then be assigned a value.

Syntax
Dim ArrayName() As DataType

Dim intTopScore() As Integer = {23000,23500,23070,23008,23708}

The example above is an array of 5 integers. The first integer sits at Index zero (0) and the last integer sits at Index four (4).

Variables

A variable is a value that can change. For instance, weather forecasters often refer to variable winds and variable temperatures - meaning that the wind and temperature could change without warning. In the context of computers, however, variables only change when told to and cannot do anything on their own.

Variables must be declared before they are used in Visual Basic.NET. To declare a new variable, you must use the Dim keyword, which is short for "dimension", referring to the process of reserving memory for the new variable.

You can create any variable you need using Dim. When you hear the word "variable', just remember that it is just a pointer to a location in memory in which some data is stored.

Variables may be used in many different situations such as storing a username, storing numbers for calculation, storing a weather temperature etc.

A declaration statement is used to declare the existence of the variable. It is defined as a particular data type. It may then be assigned a value.

Syntax
Dim VariableName As DataType

Code eg: Declaring a variable.
In this case, the variable is a String data type called strUserFirstName with a value of Straximo 
 
Dim strUserFirstName As String = "Straximo"

Data Type Summary (Visual Basic)

http://msdn.microsoft.com/en-us/library/47zceaw7%28v=VS.90%29.aspx

Constants

Some applications need to work with known values that do not change. As such, these values may be programmed into a programming entity known as a constant.

Constants are often used to enforce business rules within an application. For instance, a membership fee - 49.95, the number of days it takes to process an order - 7, the amount of damage required to destroy an enemy - 100. When a value is stored in a constant, it cannot be changed during program execution.

A declaration statement is used to declare the existence of the constant. It is defined as a particular data type. It may then be assigned a value.

Syntax
Const ConstantName As DataType

Code eg: Declaring a constant.
In this case, the constant is an Integer data type called intDamage with a value of 100.
    Const intDamageRequired As Integer = 100

Code Commenting

A single quote at the beginning of a new line will allow you to insert comments into your code.

'  This is a comment

The Visual Studio IDE

Visual Studio is an Integrated Development Environment. An IDE allows a developer to author, modify, compile, deploy and debug software. This software is installed on the TAFE machines for use in this course.

You are not required to own a copy of this software, however, there is a free express version called Visual Basic Express which you may choose to install on your own machine for convenience.

Tuesday, October 19, 2010

Datasets

The dataset is the area in memory that is used to store returned results from database queries. One dataset may contain many sets of results. For this reason, each set of query results must be stored with a unique name.


The data adapter is in charge of placing the returned results into the dataset.

MyDataAdapter.Fill(DataSetName, “QueryResultsName”)

You will notice that when the Fill method of the data adapter is called, two parameters are passed to the method:

1. The name of the dataset to fill.

2. The name that the results will be stored under.

Visual Basic Access Levels

"Access Levels in Visual Basic" ( http://bit.ly/cnKiay )

Saturday, October 16, 2010

Searching a Memo field for a word - Access

Criteria as follows:

Like "*keyword*"

Access Query and Filter Criteria

From http://www.fontstuff.com/access/acctut06.htm

"When constructing a query or a filter, you need to tell Access what to look for in each field. You do this by defining criteria - typing something (an "expression") into the Criteria cell of the query or filter grid. If you do not define any criteria for a particular field, Access assumes that you are applying no constraints and will display everything it has. This means that you only have to define criteria for those fields you are interested in..."

This tutorial is arranged in the following sections:
  • Matching Text
  • Using Wildcards
  • Working with Numbers
  • Working with Dates
  • Excluding Things
  • Finding Empty Fields

Lorum Ipsum generator

Need some dummy content to fill out those wireframes, etc?

http://www.lipsum.com/

Video Tutorial: Access Queries

Fantastic video tutorial showing query creation with Access.

http://www.gcflearnfree.org/computer/lesson.aspx?id=1552&p=2

Saturday, October 9, 2010

Microsoft Access 2010 home page

http://office.microsoft.com/en-us/access-help/

Data types in Microsoft Access

From http://www.basenow.com/help/Data_types_in_Microsoft_Access.asp

"The following list summarizes all the field data types available in Microsoft Access, their uses, and their storage sizes..."

Database Management Systems (DBMS)

From http://en.wikipedia.org/wiki/Database_management_system

"A Database Management System (DBMS) is a set of computer programs that controls the creation, maintenance, and the use of a database..."

Primary Key

from http://searchsqlserver.techtarget.com/definition/primary-key

"A primary key, also called a primary keyword, is a key in a relational database that is unique for each record. It is a unique identifier, such as a driver license number, telephone number (including area code), or vehicle identification number (VIN). A relational database must always have one and only one primary key. Primary keys typically appear as columns in relational database tables. 

The choice of a primary key in a relational database often depends on the preference of the administrator. It is possible to change the primary key for a given database when the specific needs of the users changes. For example, the people in a town might be uniquely identified according to their driver license numbers in one application, but in another situation it might be more convenient to identify them according to their telephone numbers...."

Wednesday, October 6, 2010

Revision Control

http://en.wikipedia.org/wiki/Source_control

Source code repository

http://en.wikipedia.org/wiki/Codebase

Software Reuse

http://www.buzzle.com/editorials/9-3-2004-58862.asp

Code reuse

http://en.wikipedia.org/wiki/Code_reuse

Reusable Components -- Decades of Misconceptions, Guidelines for Success

http://www.idinews.com/reUse.html

International Electrotechnical Commission IEC

http://www.iec.ch/

Metadata

Data about data.

http://en.wikipedia.org/wiki/Metadata

Technical Writing Principles and Techniques

http://www.docstoc.com/docs/5936733/Technical-Writing-Principles-and-Techniques

International Standards for Business, Government and Society ISO

http://www.iso.org/iso/home.htm

W3C Standards

http://www.w3.org/

User Agent Accessibility Guidelines 1.0

http://www.w3.org/TR/WAI-USERAGENT/guidelines.html

Authoring Tool Accessibility Guidelines 1.0

http://www.w3.org/TR/2000/REC-ATAG10-20000203/

Web Content Accessibility Guidelines (WCAG) 2.0

http://www.w3.org/TR/2008/REC-WCAG20-20081211/

GNU Coding Standards

http://www.gnu.org/prep/standards/standards.html#Preface

Code Conventions for the Java Programming Language

http://www.oracle.com/technetwork/java/codeconvtoc-136057.html

Coding Standards for Visual Basic

"The purpose of this document is to provide quality guidelines for the control of code developed in Visual Basic, ensuring some degree of discipline is employed in the development environment. In addition these standards are designed to increase readability, maintainability, reliability and portability of Visual Basic programs...."

http://www.pbdr.com/vbstd/VB%20Coding%20Standards%281%29.htm

Capitalization Styles/Naming Conventions

There are 3 conventions for naming styles.

Pascal case - backColor
Camel case - BackColor
Uppercase - IO,UI (for identifiers with short names)

Design Guidelines for Class Library Developers

http://msdn.microsoft.com/en-us/library/czefa0ke%28vs.71%29.aspx

Visual Basic Coding Conventions

These guidelines are used by Microsoft to develop samples and documentation. The Visual Basic Language Specification does not define a coding standard...

http://msdn.microsoft.com/en-us/library/h63fsef3%28VS.80%29.aspx