Monday, August 9, 2010
Blog Task: Mismatched data
The InvalidCastException occurs if the wrong data type is used, if there is a data mismatch
If you enter a number within the integer range the program executes as it should
The correct data type to store a string in is a string
The correct data type to store a number in is an integer
You can store a number in a string variable as long as you declare it as a string and are not using it for any mathematical reasons
Sunday, August 8, 2010
Blog Task: Looping through the array
The upperbound of the array is 2
3 elements are contained within the array
I suggest as a starting value of 0 and an ending value of 2
The code in figure 4 produces an IndexOutOfRangeException because the loop is trying to access an index that is beyond the upperbound of the array, in this case the upperbound of the array is 2 and the loops ending condition is 3, the exception is thrown when the intLoopCounter reaches 3 because it should really be 2
The value that is displayed in the message box when the loop is in it’s second iteration is string 2
Blog Task: Warnings
Visual Studio IDE provides a warning with regards to using variables before they have been assigned a value, this warning is as follows:
#use the "new" keyword to create an object instance
#check to determine if the object is null before calling the method
The warning pops up in a box and has a yellow box around the code that is incorrect, it also contains a green squiggly line under in this case ThisPlayer1.
Blog Task: Name that function
The name of the Visual Basic function we could use to ensure that only numeric data is assigned to the integer variable (therefore avoiding the program crash if non-numeric data is entered)?:isNumeric
We implement this method by using an If IsNumeric statement
We implement this method by using an If IsNumeric statement
Overflow exception (error) occurs when a value goes beyond its data type's storage capacity
The range/capacity of an integer is -2,147,483,648 through 2,147,483,647
Blog Task: Types of errors
The three types of errors or exceptions include:
syntax errors, run-time errors, and logic errors
Let me explain them in more detail below:
Syntax errors:
#the most common type of errors
#As you write the code this is when they appear
#As you type the code into the editor VB checks the code and lets you know if and when a mistake has been made
#If you spell a word wrong or if you do not use a language element properly VB will let you know
# As soon as this error happens you can fix them in the coding environment
Run-time errors:
#After you compile and run your code this is when run time errors appear
# No syntax errors show and for this reason the code may appear to be right, however the code will not run
# eg: you write code to open a file, you do this the right way, corruption of the file may occur and for this reason the open function stops running because the application cannot carry out this function.
# Re-write this non working code to fix this issue, then recompile and rerun the code
Logic errors:
#When the application is in use these errors occur
# In response to the users actions logic errors are unexpected and unwanted
# eg: The application may stop working all together or just stop working within parameters that are expected because of an outside influence or mistyped key
#These errors are difficult to fix, it is not always easy to source where they have come from
Monday, August 2, 2010
3/8/2010 Overiding
A Student Class
STUDENT
(private) #
#Name
#Number
#Fees
New (Name, Number, Fees)
Calculate Fees() : Integer
Children Class:
On Campus Student
-CampusID
New( CampusID)
Another Child Class:
Online Student
-CourseKey
New(CourseKey)
Another Child Class:
International Studen
-RegionalCode
New (RegionalCode)
CalculateFees()
STUDENT class implementation:
Public Overidable Function CalculateFees () As Integer
End Function
International Student Implementation:
Public Overides Function CalculateFees () As Integer
3/8/2010 Constructor and Method Overloading
Constructor overloading : Multiple constructors
The parameter lists must be unique, the same data type cannot be used more then once
New()
New(Name As String)
New(Name As String, Age As Date)
Method Overloading
A Simple Class :
Player
-HealthLevel: Integer
+ New()
+ SetHealthLevel(HealthLevel:Integer)
+SetHealthLevel(HealthLevel:Integer,Bonus:Boolean)
Code :
Private _Health As Integer
Public Sub SetHealth(HealthLevel As Integer)
_HealthLevel = HealthLevel
End Sub
Public Sub SetHealth (HealthLevel As Integer, Bonus As Boolean)
_HealthLevel = HealthLevel *2
End Sub
Sunday, August 1, 2010
Loop Revision Task 2
Questions / Answer
The upper Bound of the array is 2
3 elements are contained in the array
The starting index of the array is 0
The starting value of the loop counter is 1
The loop executes 3 times
Loop Revision Task 1
2/8/2010 - Loops
For intx = 1 To intTotalNumberOfCells
intx = 1 is the starting condition
intTotalNumberOfCells is the ending condition
Subscribe to:
Posts (Atom)