vbdebug - CIS 338: Debugging Dr. Ralph D. Westfall March,...

Info iconThis preview shows pages 1–15. Sign up to view the full content.

View Full Document Right Arrow Icon
CIS 338: Debugging Dr. Ralph D. Westfall March, 2009
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Error Handling/Debugging syntax errors logical errors good coding practices to minimize errors testing your code debugging methods "bullet proofing"
Background image of page 2
Syntax Errors spelling or punctuation errors "select * where Sitty="Pomona" 'in SQL MsgBox "Hello" 'use MsgBox("Hello") missing parts of control structures For but no Next If but no End If extra parts for control structures extra End Sub at end
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Syntax Errors - 2 using a method as a property MsgBox = "Welcome" don't use = with methods using a property as a method lblName.Caption("Name") properties are values, so need to use =
Background image of page 4
Syntax Errors - 3 writing to a "read only" property changed values could destroy data or make it inaccessible lstSpecialty.Items.Count() = 10 not using New to create an object objDataTier = DataTier() 'should be objDataTier = New DataTier()
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Syntax Errors - 4 type mismatch e.g. can't do arithmetic with text 5 / "hello" MsgBox(5/txtName.Text) 'text or empty or with an undefined value (if not using Option Strict On) MsgBox(5/CInt(txtNameText))'missing dot
Background image of page 6
Logical Errors compiler does not even catch division by literal value of zero as a syntax error Dim y = 3 / 0 division by a variable that becomes zero is much harder to spot Dim x as Double = 3 Dim y as Double = 3 y = x / (x - y)
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Logical Errors - 2 code that doesn't do what you want it to do example: trying to swap values of nA, nB nA = nB 'destroys value of nA nB = nA 'nB gets original value back
Background image of page 8
Logical Errors - 3 code that will never run ("dead" code) example: comparison If nAge < 3 Then Print "less than 3" ElseIf nAge >= 3 Then Print "3 or older" ElseIf nAge >= 55 Then Print "55 or older" 'will never run End If
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Logical Errors - 4 changing value of the counter in a loop students make this mistake fairly often on tests For i = 0 to 9 lstName.Item.Add(names(i)) i += 1 Next
Background image of page 10
Good Coding Practices indent code inside loops and conditionals "pretty printing" For nI = 1 to 2 nJ = nI^2 'exponentiation Next nI 'show (optional) counter use comments but only where they are needed
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Good Coding Practices - 2 use Option Strict at start of code for forms and other modules forces you to declare all variables helps spot spelling mistakes stops implicit data type conversions should you use Option Strict when the code goes into "production?" why or why not?
Background image of page 12
Good Coding Practices - 3 consistent object naming convention frmDataEntry 'a Windows form lstName 'a ListBox VB capitalizes function names for you e.g. string function names sName.ToUpper() 'to Upper Case sAddress.TrimStart() 'removes left side spaces
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Good Coding Practices - 4 type checking: is data what you expect? If IsNumeric(txtQuantity.Text) Then
Background image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/13/2009 for the course CIS 338 taught by Professor Westfall during the Winter '09 term at Cal Poly Pomona.

Page1 / 46

vbdebug - CIS 338: Debugging Dr. Ralph D. Westfall March,...

This preview shows document pages 1 - 15. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online