You are on page 1of 79

0.

20 ...
DOS Basic, C, Pascal, Fortran... Windows Visual Basic, Delphi, .Net, Java.../
...DHTML Ajax

3GL

Code Complete

.
.
.
.
.
.Error Handling
.
.
.
.

1.--

Runtime

1.

for i=1 to 100

100

1.

for i=1 to MaxEntries

MaxEntries 100 MaxEntries MaxEntries

. "Devided by Zero"
0
1.

x=a/b

b 0 Runtime "Devided by Zero" 0

1.
2.
3.
4.
5.

if b=0 then
x=0
else
x=a/b
end if

1.

if (i=x) then

x i false

1.

if (i=cint(x)) then

Compiler
. Compiler
Visual Studio

2.--

Let's Go.

.
x=a/b /

1.

dim x as integer

2.

dim a as integer, b as integer

3.
4.

x=a/b

a=7, b=10 0.7x=0


Why?
a b x
x=0.0

1.

dim x as integer

2.

dim a as double, b as double

3.
4.

x=a/b

Compile error x=0

.Overflow

16 2^16 - 1 65536
32767 Runtime

billing Long Integer Double


int64 default integer
32

.Intermediate results

Compiler raise error

3.--

0 1
5, 6

OK
.
1000000.00+0.01 1000000.00
Compiler

(1000000*100+0.01*100)/100

.""

0.1 1.0
1.

dim Nominal as single

2.

dim Sum s single

3.

dim i as integer

4.
5.

Nominal=1.0

6.
7.

Sum=0

8.
9.
10.

for i=1 to 10
Sum=Sum+0.1

11. next i
12. if Nominal=Sum then
13.

Msgbox ""

14. else
15.

Msgbox ""

16. end if


1.

const AcceptableDelta=0.00001

2.
3.
4.
5.
6.
7.

if abs(Nominal-Sum)<AcceptableDelta then
Msgbox ""
else
Msgbox ""
end if

equals
if Nominal.equals(Sum)
.

Round

1.

x=round(y,2)

+0.5
1.

dim x as single

2.
3.

x=Cint(y*100+0.5)

4.

x=x/100

4.--

String ,

, String , C String
( malloc) , (\0)
, , ?
, ,
1.

if x=" A" then

2.

...

, , scan , ,
,

, (Constant),

, ,
, ,
,

, ini , , Windows Registry Repository


java properties , XML ,
(, )

, , , , , ,
, , ,
,

, IS ,
, ,

5.--
0false) 1(true) -1 1

Boolean

1.

if (ElementIdx<0) or (Max_Elements < ElementIdx) _

2.

or (ElementIdx=LastElementIdx) then

3.

...

4.

end if

1.

Finished=(ElementIdx<0) or (Max_Elements < ElementIdx)

2.

RepeatedEntry=(ElementIdx=LastElementIdx)

3.
4.

if Finished or RepeatedEntry then

5.

...

6.

end if

Workflow

1.

'

2.

if (dep_id="
A" and ((TotalAmount>5000000 or (ApproverLevel>="3" and TotalAmount<=5000000) or (ApproverLevel>="2" and To
talAmount<=3000000))) or (dep_id=" B") or _

3.

(ApproveStatus<>"no" and ApproverLevel>="1" and TotalAmount<=1000000) or _

4.

(ApproveStatus<>"no" and ApproverLevel>="2" and TotalAmount<=3000000) or _

5.

(ApproveStatus<>"no" and ApproverLevel>="3" and TotalAmount<=5000000) or _

6.

(ApproveStatus<>"no" and ApproverLevel="4") then

7.
8.
9.

' Next Step


else
' Return

10. end if

1.

' a, b A, B

2.

' A

3.

a=(dep_id="
A" and ((TotalAmount>5000000 or (ApproverLevel>="3" and TotalAmount<=5000000) or (ApproverLevel>="2" and To
talAmount<=3000000)))

4.
5.

' B

6.

b=(dep_id=" B")

7.
8.

'

9.

otrs=(ApproveStatus<>"no" and ApproverLevel>="1" and TotalAmount<=1000000) or (ApproveStatus<>"no" and Appro


verLevel>="2" and TotalAmount<=3000000) or (ApproveStatus<>"no" and ApproverLevel>="3" and TotalAmount<=500
0000) or (ApproveStatus<>"no" and ApproverLevel="4")

10.
11. ispassed=(a or b or otrs)

1.

'

2.

if ispassed then

3.
4.
5.
6.

' Next Step


else
' Return
end if

6.--
Enum

ADO.Net Connection State Connection

.
Code
1.

if ChosenColor=1

1.

if ChosenColor=COLOR_RED

.
Compiler
raised error
.

TRUE/FALSE
Success/Warning/FataError

VB.Net enum
1.

Imports System

2.
3.
4.

Public Class MainClass


Private Enum Names As Integer

5.

Norman = 1

6.

Mike = 2

7.

Reece = 3

8.

End Enum

9.
10.

Shared Sub Main()

11.

System.Console.WriteLine(Names.Norman.ToString & " = " & Names.Norman)

12.

System.Console.WriteLine(Names.Mike.ToString & " = " & Names.Mike)

13.

System.Console.WriteLine(Names.Reece.ToString & " = " & Names.Reece)

14.
15.

End Sub

16. End Class

http://www.java2s.com/Code/VB/Language-Basics/EnumdataDemo.htm

7.--
Constant

OK
Editor Replace

8.--
Link List BASIC
...

Bubble Sort Quick Sort

...XD

.
Dynamic

1.

Dim a() as String

2.
3.

i=0

4.

Do while i<n

5.

Redim Preserve a(i) as String

6.

...

7.

i=i+1

8.

Loop

9.

x=a(b)

b Ubound(a)
.
.
key

1.
2.
3.
4.
5.

for i=1 to n
for j=1 to n
x=a(j,i) ' a(i,j) a(j,i)
next j
next i

i j

Array .Net List List Methods

1.

Dim instance As List(Of T)

2.
3.

instance.Add("a")

4.

instance.Add("c")

5.

instance.Insert(1,"b")

instance Contains, Add, Insert, Remove, IndexOf, Sort... Methods Array

9.--
Structures Structured Data

Code Insight
Structured Data New

Structured Data
.
Structured Data

1.

Name=InputName

2.

Address=InputAddress

3.

Phone=InputPhone

4.

Title=InputTitle

5.

Department=InputDepartment

6.

Bonus=InputBonus

NameAddressPhone TitleDepartment
Bonus
1.

Employee.Name=InputName

2.

Employee.Address=InputAddress

3.

Employee.Phone=InputPhone

4.
5.

Supervisior.Title=InputTitle

6.

Supervisior.Department=InputDepartment

7.

Supervisior.Bonus=InputBonus


.
Structured Data
Structured Data
1.

Type Employee

2.

Name as String

3.

Address as String

4.

Phone as String

5.

SSN as String

6.

Sex as String

7.

Salary as String

8.

End Type

9.
10. Dim NewEmployee as Employee
11. Dim OldEmployee as Employee
12. Dim PrevOldEmployee as Employee

1.

PrevOldEmployee=OldEmployee

2.

OldEmployee=NewEmployee

3.

NewEmployee=PrevOldEmployee

1.

' Structured Data

2.

HardWayRoutine(Name, Address, Phone, SSN, Sex, Salary)

3.

' Structured Data

4.

EasyWayRoutine(EmployeeRec)

Structured Data

.
Basic
Structured Data
Structured Data

10.--

Abstract Data Type

SetCurrentFontToBold() Font Attribute

.
SetFontToBold()

11.--

Variable i

1.

for i=1 to n

i Integer i String

i, j, k a, b, c
a=b, b=ca=b

AmountOfBlance 2~30

EmployeeData

8~20 Compiler
Google Naming Convention Coding Convention

12.--
C
Naming Convention Coding Convention

Java Coding Convention


http://java.sun.com/docs/codeconv/CodeConventions.pdf

Hungarian Convention
Charles Simonyi

SDG2.0

wiki http://zh.wikipedia.org/zhhk/%E5%8C%88%E7%89%99%E5%88%A9%E5%91%BD%E5%90%8D%E6%B3%95

.
1.

wn:

2.

scr:

3.

fon:

4.

ch:

5.

pa:

.
1.

a:

2.

c:

3.

d:

4.

e:

5.

g:

6.

h:Handle

7.

i:

8.

m:

awn
.
1.

Min:

2.

First:

3.

Last: First

4.

Lim:

5.

Max: Min

1.

ipaReformat

2.

3.

pa

4.

Reformat

1.

i:

2.

s:

3.

c:

4.

l:

5.

g:

giPartNoCount
PartNo

^^

13.--

.Scope

Session

1.

Dim myStr1 as String, myStr2 as String

2.

Dim myInt1 as Integer, myInt2 as Integer

3.
4.

SetMyStr(myStr1)

5.

SetMyStr(myStr2)

6.
7.

SetMyInt(myInt1)

8.

SetMyInt(myInt2)

.Persistence
NullPointException
ADO Connection Release Recordset Initialize Closed
Error Handling

Release

1.

myRecordset=Nothing

2.

myConnection=Nothing

3.

4.

GC.Collect()

.Binding Time
Early Binding Late Binding Early Binding,
Late Binding / Early Binding
Run Time Late Binding
http://wiki.answers.com/Q/What_is_the_difference_between_Late_binding_and_early_binding

Compiler Run
Time
.

init()

1.

Dim a as String, b as String

2.

Dim i as Integer, j as Integer

3.
4.

Sub init()

5.

a=""

6.

b=""

7.
8.

i=0

9.

j=0

10. End Sub

14.--if & case


if case

if case

case

if case

if statement

.
. else
common sense

1.

OpenFile(InputFile, Status)

2.

if Status=Error then

3.
4.

ErrorType=FileOpenError
else

5.

ReadFile(InputFile, FileData, Status)

6.

if Status=Success then

7.

SummarizeFileData(FileData,SummaryData,Status)

8.

if Status=Error then

9.
10.

ErrorType=DataSummaryError
else

11.
12.
13.
14.
15.

ErrorType=None
end if
else
ErrorType=FileReadError
end if

16. end if

1.

OpenFile(InputFile,Status)

2.

if Status<Error then

3.

ReadFile(InputFile,FileData,Status)

4.

if Status=Success then

5.

SummarizeFileData(FileData,SumaryData,Status)

6.

if Status<>Error then

7.
8.

ErrorType=None
else

9.
10.
11.
12.
13.

ErrorType=DataSummaryError
end if
else
Error=FileReadError
end if

14. else
15.

Error=FileOpenError

16. end if

.if
if

1.
2.
3.
4.
5.
6.

if SomeTest then
'do nothing
else
' do something
...
end if

1.

if not SomeTest then

2.

' do something

3.

...

4.

end if

. else
.

.
else debug
else

case statement
.
case

.
.

. case
case case case

1.
2.

select case x
case 'A'

3.

doA()

4.

case 'B'

5.

doB()

6.

case 'C'

7.
8.
9.

doC()
else
doElse()

10. end select

. case case
case if-else case

1.
2.

select case left(x,1)


case 'A'

3.

if x="ABC" then

4.

else if x="ACD" then

5.

end if

6.

end select

if

. default
defalut default case

15.--
statement
User ...XD for-loopwhile-loop, do-until...

1.
2.
3.

do while not rs.eof


a=rs.fields(0).value
loop

rs.movenext() CTRL+ALT+DEL break run


console run server hang VB.Net Data Reader

1.

do while dr.read()

2.

...

3.

loop

.
while(!rs.eof) i++;

.
console waiting
1.

while ( (InputChar = getch()) != '\n' );


1.

do

2.
3.

InputChar = getch();
while ( InputChar != '\n' )

.
for i=1 to n n+1
i

1.

for (i=0;i<MaxRecords;i++)

2.

3.

if (Entry[i]==TestValue)

4.

5.

break;

6.

7.

8.

if (i<MaxRecords)

9.

return (TRUE);

10. else
11.

return (FALSE);

i
1.

Found=FALSE;

2.

for (i=0;i<MaxRecords;i++)

3.

4.

if (Entry[i]==TestValue)

5.

6.

Found=TRUE;

7.

break;

8.
9.

}
}

10. return (Found);

. goto continue
VB6 continue goto
1.
2.
3.
4.
5.
6.

do while not rs.eof


if NotExpected then goto Continue
...
Continue:
rs.movenext
loop

goto continue ifthen-else Block goto


continue continue
1.

do while not eof(File)

2.

read(Record, File)

3.

if (Record.type<>TargetType) then

4.

continue

5.

....

6.

loop

continue

16.--Goto & Return


Goto VB
Goto
Go To Statement Considered Harmful
Structured Programming with go to Statements

Goto

Goto

Goto VB6 VBA Error Handling On Error Goto ErrorHandling


Error Handling VB.Net Try-Catch-Finally Block

Return Return

Goto
. Goto
Goto
1.

if (SomeExpressionTrue) then

2.

...

3.

if (isErrorRaised) then

4.
5.

goto Label1
end if

6.

else

7.

Label1:

8.
9.

doSomething()
end if

Goto

1.

if (SomeExpressionTrue) and not (isErrorRaised) then

2.

...

3.

else

4.
5.

doSomething()
end if

ErrorHadling Goto

. Label
Label
Label Define Label Goto
. Goto
Compiler Size
Goto Label
Return
. Return

null
Return
1.

Function A() as Variant

2.

Dim ret as Integer

3.

ret=0

4.
5.
6.
7.

if SomeExpress then
ret=1
end if

8.
9.

A=ret

10. End Function

. Return
Return Return
Return

17.

Block

( { () {}

Leader
Follow

Visual Source Safe Repository


Check In/Check Out

Tab
Capital

Coding Block snippet


Coding Block

Coding Block If...Then Enter End If

1.

// 1

2.

if (BooleanExpression) {...}

3.
4.

// 2

5.

if (BooleanExpression) {

6.
7.

...
}

8.
9.

// 3

10. if (BooleanExpression)
11. {
12.

...

13. }

1.
2.

if (( '0' <= InChar and InChar <= '9' ) or ( 'a' <= InChar and InChar <='z') or ( 'A' <= InChar and InChar <='Z' )) then
...

scroll bar

1.

if (( '0' <= InChar and InChar <= '9' ) or _

2.

( 'a' <= InChar and InChar <= 'z' ) or _

3.

( 'A' <= InChar and InChar <= 'Z' )) then

4.

...

Mark ^^b
. 80
80 A4
80
.

1.

ReadEmployeeData(MaxEmps,EmpData,InputFile,EmpCount,InputError)

. ,

1.

ReadEmployeeData( MaxEmps, EmpData, InputFile, EmpCount, InputError )

.
Pascal

18.

1.

'*****************************************************************

2.

'* CopyString

3.

'*

4.

'* (Source$)(Target$)

5.

'*

6.

'* Source$ Target$

7.

'*

Source$

8.

'*

Target$

9.

'*

10. '* Inputs$


11. '*
12. '* Outpur$
13. '*
14. '*
15. '*
16. '*
17. '*
18. '*
19. '* 10/1/92
20. '* (222) 555-2255
21. '*
22. '*****************************************************************

Blog

.
.
.
.
.

.
HTML

[b].

Open Source

.
.
.

Open

19.
--

API JavaDoc

JavaDoc
JavaDoc

API

Visual Source Safe Sorry


.Net Team Fundation Server Visual Source Safe
API Blog

http://210.71.186.144/cgi-bin/big5/cisa/aa02

ERP Tiptop

...XD

Schemahelp
Schema
ERP

Informix 4GL

20.Debug

User

Bug

Framework
log4j

Debug

.
User

.
You are not alone
iT

21.Error Handling
Error Handling Exception Handling Runtime

Raise Error

Handle
Exception Handling Block
1.
2.
3.
4.
5.
6.
7.

Try
' Your Code
Catch e as ExceptionType
' Error Handling
Finally
' Release Object
End Try

Exception Handling Block


Error Catch Block
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.

Try
' Your Code
Catch e as ExceptionTypeI
' Error Handling
Catch e as ExceptionTypeII
' Error Handling
Catch e as ExceptionTypeIII
' Error Handling
Finally
' Release Object

11. End Try

Dot Net VB Exception Handling


VBA Office 20032007 .Net

1.

On Error Goto ErrorHandling

2.
3.

' Your Code

4.
5.

ExitSub:

6.
7.
8.

' Release Object


Exit Sub
ErrorHandling:

9.

' Error Handling

10.

Resume ExitSub

Label Goto Goto

Error Handling

1.
2.

ErrorHandling:
msgbox Err.Description

VB

1.
2.

ErrorHandling:
msgbox ""

Validation

Google Chrome

Stack Strace Dump Log email

User

^^b
...XD

22.

DOS Widnows

Windows FormHTML Document Object Model

Encapsulation

Abstraction
Class

Instance

Reuse Inheritance

Polymorphism

Interface)Implement

DLL

23.

UML Rational Rose ALM


Application Life-Cycle ManagementUML

Class Diagram

.
Public

Information Hiding

InterfaceCompiler Interface
Implement

24.

...
...XD

OK
()()...

Define
1.

Class

2.

public

3.

public

4.

public (,)

5.

public ([])

6.

// Constructor

7.

new(){

8.
9.

= new ()
}

10.
11. Class
12.

public

13.

public ([])

14.
15. Class
16.

private

17.

private

18.

public []

19.

private ()

20.

new(string from, string to){

21.

=from;

22.

=to;

23.

(); // [] public

24.

25.
26. Class
27.

public

28.
29. Class
30.

public

31.
32. Class
33.

public

34.

public

35.

private ()

36.

new(){

37.

(); //

38.

1.

function float (string name, string motor, string from, string to) {

2.

o ;

3.
4.

o = new ();

5.

o . = name;

6.

o .. = motor;

7.
8.
9.

return o .(o .(from,to));


}

Class () Method
1.

function [] (string from, string to){

2.

o ;

3.
4.

o = new (from, to);

5.
6.

return o .;
}

[0]-> [1]-> ()
1.

function float (){

2.

//

3.

float =.();

4.
5.

//

6.

o = new ();

7.
8.

if (o ..equals("")) +=0.5;

9.

if (o ..equals("")) +=0.2;

10.
11.

return ;

12. }

1.

System.out(("","","",""));

25. Form

Form 2006
Blog
http://jamesjantw.blogspot.com/2006/09/net-windows-form.html

VB6 Backend OS Schedule

Copy Pattern
ini log Error email

Delphi (3.0) Form Form


Windows Form

1. BaseForm Inheritance consideration


2.Overrides
3.Overloads
4.
5.
6.Exception Notification &

Visual Studio
Class Library .Net 2.0

Project


CLass Diagram

Form
Parent Form
Error Handling Log
Form

BaseForm

Base Form Class Log Send Mail


Error Handling

BaseForm.vb
1.

Public Class BaseForm

2.

Protected RunTimer As Integer

3.

Protected sendmail As SendMail

4.

Protected log As Log

5.
6.

Private Sub BaseForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) H


andles Me.FormClosing

7.
8.
9.

mnuSwitch.Text = ""
mnuSwitch_Click(sender, e)
End Sub

10.
11.

Private Sub BaseForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

12.

sendmail = New SendMail()

13.

log = New Log()

14.

Timer1.Enabled = True

15.

ShowTimer()

16.

End Sub

17.
18.

Private Sub ShowTimer()

19.
20.

ToolStripStatusLabel2.Text = Now().ToString
End Sub

21.
22.
23.
24.

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick


ShowTimer()
End Sub

25.
26.

Private Sub mnuSwitch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSwitch.Click

27.

Timer2.Enabled = mnuSwitch.Text.Equals("")

28.

ListBox1.Items.Add(Now().ToString & " " & mnuSwitch.Text)

29.

log.Writeln(mnuSwitch.Text, TraceEventType.Information)

30.

mnuSwitch.Text = IIf(mnuSwitch.Text.Equals(""), "", "")

31.

End Sub

32.
33.
34.
35.
36.

Protected Sub ExceptionHandler(ByVal ex As Exception, ByVal ErrorMessage As String)


My.Application.Log.WriteException(ex, _
TraceEventType.Error, _
Now().ToString)

37.

sendmail.Message.Subject = ErrorMessage

38.

sendmail.Message.Body = "Message ---" & vbCrLf & ex.Message & vbCrLf & vbCrLf & _

39.

"Source ---" & vbCrLf & ex.Source & vbCrLf & vbCrLf & _

40.

"StackTrace ---" & vbCrLf & ex.StackTrace & vbCrLf & vbCrLf & _

41.

"TargetSite ---" & vbCrLf & ex.TargetSite.ToString()

42.
43.
44.

sendmail.Send()
End Sub

45. End Class

define ExceptionHandler() Log File


mail
SendMail FormTo SMTP Host Base Form

Log.vb
1.

Public Class Log

2.
3.

Public Sub New()

4.

End Sub

5.
6.

Public Sub Writeln(ByVal strLog As String, ByVal TraceEvent As Integer)

7.
8.

Try

9.

Application.DoEvents()

10.

My.Application.Log.WriteEntry(strLog & vbTab & Now().ToString, TraceEvent)

11.
12.

Catch ex As IO.IOException
My.Application.Log.WriteException(ex, _

13.

TraceEventType.Error, _

14.

Now().ToString)

15.

End Try

16.

End Sub

17. End Class

Exception Log
SendMail.vb
1.

Imports System.Net.Mail.SmtpClient

2.

Imports System.Net.Mail.MailMessage

3.
4.

Public Class SendMail

5.

Public Message As System.Net.Mail.MailMessage

6.

Public SmtpClient As System.Net.Mail.SmtpClient

7.
8.
9.
10.
11.

Public Sub New(ByVal host As String)


SmtpClient = New System.Net.Mail.SmtpClient(host)
Message = New System.Net.Mail.MailMessage()
End Sub

12.
13.

Public Sub New()

14.

SmtpClient = New System.Net.Mail.SmtpClient()

15.

Message = New System.Net.Mail.MailMessage()

16.

End Sub

17.
18.
19.
20.

Public Sub Send()


If Not IsNothing(SmtpClient.Host) And Not IsNothing(Message.From) And Not IsNothing(Message.To) Then
SmtpClient.Send(Message)

21.

End If

22.

End Sub

23. End Class

SendMail Constructor Overloadding host


Send Host FromTo

TimerBaseFormLibrary.dll

regsvr32 TimerBaseFormLibrary.dll

26. Form
Parent Form TimerBaseFormLibrary

,
.Net Framework
Application log , log
Application Event XML app.config

My.Application.Log
HOW TO Visual Basic

Exception Notification Import System.Net.Mail.SmtpClient &


System.Net.Mail.MailMessage , Config

Windows Form

Form Widnows Form

Form Class Diagram

Class Diagram
Form

Form2.vb
1.

Public Class Form2

2.
3.
4.

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick


If RunTimer >= My.Settings.RunTimer Then

5.

ToolStripStatusLabel1.Text = "Next Time:" & Now().AddSeconds(My.Settings.RunTimer).ToString

6.

ListBox1.Items.Add(Now().ToString & " Form2")

7.

RunTimer = 1

8.
9.
10.

doCheck()
Else
RunTimer += 1

11.

End If

12.

End Sub

13.
14.

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

15.

sendmail.SmtpClient.Host = My.Settings.SMTP

16.

sendmail.Message.From = New System.Net.Mail.MailAddress(My.Settings.From)

17.

sendmail.Message.To.Add(My.Settings.Rcpt)

18.

End Sub

19.
20.

Private Sub doCheck()

21.

Dim a As Integer

22.

Try

23.

a = "ABC"

24.
25.

Catch ex As Exception
ExceptionHandler(ex, Application.ProductName & ":" & Me.Name & ":doCheck")

26.

End Try

27.

End Sub

28. End Class

Form2_Load sendmail .Net


My Name Space
Parent Form implement Timer2_Tick() Method Parent Form
Implement Override Timer2_Tick()
doCheck

C:\Temp\ InheritanceTest.log

1.

DefaultSource Information 0 2009/10/30 01:17:15

2.

DefaultSource Error 2 "ABC" 'Integer' 2009/10/30 01:18:19

3.

DefaultSource Error 2 "ABC" 'Integer' 2009/10/30 01:18:43

4.

DefaultSource Information 0 2009/10/30 01:18:46

email

Base Form
mnuSwitch Form2_Load
1.

MyBase.mnuSwitch.PerformClick()

OK, log C:\Temp


ApplicationEvents.vb
1.

Namespace My

2.
3.

' MyApplication :

4.

'

5.

' Startup:

6.

' Shutdown:

7.

' UnhandledException:

8.

' StartupNextInstance:

9.

' NetworkAvailabilityChanged:

10.

Partial Friend Class MyApplication

11.
12.

Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationSe


rvices.UnhandledExceptionEventArgs) Handles Me.UnhandledException

13.

My.Application.Log.WriteException(e.Exception, _

14.

TraceEventType.Critical, _

15.

"Application shut down at " & _

16.

My.Computer.Clock.GmtTime.ToString)

17.

End Sub

18.

End Class

19.
20. End Namespace

My Name Space MyApplication Exception Handling Visual


Studio 2005 2008
app.config
1.
2.

<system.diagnostics>
<sources>

3.

<!-- My.Application.Log -->

4.

<source name="DefaultSource" switchName="DefaultSwitch">

5.

<listeners>

6.

<add name="FileLog"/>

7.

<add name="FileLogListener" />

8.

</listeners>

9.

</source>

10.

</sources>

11.

...

12.

<sharedListeners>

13.

<add name="FileLog"

14.

type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral,


PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"

15.
16.

initializeData="FileLogWriter"/>
<add name="FileLogListener"

17.

type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral,


PublicKeyToken=b03f5f7f11d50a3a"

18.

initializeData="FileLogListenerWriter"

19.

location="Custom"

20.

customlocation="c:\temp\" />

21.
22.

...
</sharedListeners>

23. </system.diagnostics>

log Exception Handling

27.--

Java Calendar Class


VB
1.

dim lastday as String

2.

dim yy as string, mm as string

3.
4.

yy=Year(Now)

5.

mm=Month(Now)

6.
7.
8.
9.
10.
11.
12.
13.
14.

select case mm
case 1,3,5,7,8,10,12
lastday = Format(Now,"yyyy/MM") + "/31"
case 4,6,9,11
lastday = Format(Now,"yyyy/MM") + "/30"
case 2
lastday = Format(Now,"yyyy/MM") + _
iif((yy mod 400) or _

15.

(yy mod 4 and not (yy mod 100)),"/29","/28)

16. end select

If ElseIf 12
Format Cstr(yy)+"/"+Cstr(mm)+"/31"
10 Cstr(yy)+"/0"+Cstr(mm)+"/31"

YES

1.

dim lastday as String

2.
3.

lastday = Format(Dateadd("d",-1,CDate(Format(Dateadd("m",1,Now),"yyyy/MM/01"))),"yyyy/MM/dd")

antijava

28.--Table V.S. Class


Class Table
Tool DB Table
Class

Event
Performance Debug Trace

Employee
1.

CREATE TABLE [dbo].[Employee] (

2.

[empy_id] [varchar] (6) NOT NULL ,

3.

[empy_nm] [varchar] (8) NOT NULL ,

4.

[dep_id] [varchar] (6) NOT NULL ,

5.

[status] [char] (1) NOT NULL ,

6.

[role] [char] (6) NOT NULL ,

7.

[email] [varchar] (50) NULL

8.

) ON [PRIMARY]

9.

GO

10.
11. ALTER TABLE [dbo].[Employee] ADD
12.

CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED

13.

14.
15.

[empy_id]
) WITH FILLFACTOR = 90 ON [PRIMARY]

16. GO

Employee ID, Employee Name, Department ID, Role, Email, Status


ClassclsEmployee
1.

Imports System.Data.SqlClient

2.
3.

Public Class clsEmployee

4.

Private m_empy_id As String

5.

Private m_empy_nm As String

6.

Private m_dep_id As String

7.

Private m_role As String

8.

Private m_email As String

9.

Private m_status As String

10.

11.
12.
13.

Public Property empy_id() As String


Get
Return m_empy_id

14.

End Get

15.

Set(ByVal value As String)

16.
17.
18.

m_empy_id = Value
End Set
End Property

19.
20.
21.
22.

Public Property empy_nm() As String


Get
Return m_empy_nm

23.

End Get

24.

Set(ByVal value As String)

25.
26.
27.

m_empy_nm = value
End Set
End Property

28.
29.
30.
31.

Public Property dep_id() As String


Get
Return m_dep_id

32.

End Get

33.

Set(ByVal value As String)

34.
35.
36.

m_dep_id = value
End Set
End Property

37.
38.
39.
40.

Public Property role() As String


Get
Return m_role

41.

End Get

42.

Set(ByVal value As String)

43.
44.
45.

m_role = value
End Set
End Property

46.
47.
48.
49.

Public Property email() As String


Get
Return m_email

50.

End Get

51.

Set(ByVal value As String)

52.
53.
54.

m_email = value
End Set
End Property

55.
56.
57.
58.
59.

Public Property status() As String


Get
Return m_status
End Get

60.
61.
62.
63.

Set(ByVal value As String)


m_status = value
End Set
End Property

64.
65.

Public Sub GetData(ByVal uid As String)

66.

Dim conn As New SqlConnection

67.

Dim cmd As New SqlCommand

68.

Dim dr As SqlDataReader

69.
70.

Try

71.
72.

conn.ConnectionString = My.Settings.ConnectionString

73.

conn.Open()

74.
75.

cmd.Connection = conn

76.
77.

cmd.CommandText = "select * from Employee where empy_id='" + uid + "'"

78.

dr = cmd.ExecuteReader()

79.
80.

Do While dr.Read()

81.

m_empy_id = dr.GetString(dr.GetOrdinal("empy_id"))

82.

m_empy_nm = dr.GetString(dr.GetOrdinal("empy_nm"))

83.

m_dep_id = dr.GetString(dr.GetOrdinal("dep_id"))

84.

m_role = dr.GetString(dr.GetOrdinal("role"))

85.

m_email = dr.GetString(dr.GetOrdinal("email"))

86.

m_status = dr.GetString(dr.GetOrdinal("status"))

87.

Loop

88.
89.
90.
91.
92.
93.
94.
95.

dr.Close()
Catch ex As Exception
Throw New System.Exception(ex.Message + vbCrLf + ex.StackTrace)
Finally
If conn.State = ConnectionState.Open Then
conn.Close()
End If

96.
97.
98.
99.

dr = Nothing
conn = Nothing
End Try

100. End Sub


101.
102. Public Sub SaveData()
103.

Dim conn As New SqlConnection

104.

Dim cmd As New SqlCommand

105.

Dim dr As SqlDataReader

106.

'Dim trans As SqlTransaction

107.
108.

Try

109.
110.

conn.ConnectionString = My.Settings.ConnectionString

111.

conn.Open()

112.
113.

'trans = conn.BeginTransaction()

114.
115.

cmd.Connection = conn

116.

'cmd.Transaction = trans

117.
118.

cmd.CommandText = "select * from Employee where empy_id='" + empy_id + "'"

119.

dr = cmd.ExecuteReader()

120.

If dr.HasRows Then

121.

dr.Close()

122.

cmd.CommandText = "delete from Employee where empy_id='" + empy_id + "'"

123.
124.

cmd.ExecuteNonQuery()
End If

125.
126.

If Not dr.IsClosed Then dr.Close()

127.
128.

cmd.CommandText = "insert into Employee (empy_id,empy_nm,dep_id,role,email,status) values (?,?,?,?,?,?)"

129.

cmd.Parameters.Clear()

130.

cmd.Parameters.Add(New SqlParameter("?", m_empy_id))

131.

cmd.Parameters.Add(New SqlParameter("?", m_empy_nm))

132.

cmd.Parameters.Add(New SqlParameter("?", m_dep_id))

133.

cmd.Parameters.Add(New SqlParameter("?", m_role))

134.

cmd.Parameters.Add(New SqlParameter("?", m_email))

135.

cmd.Parameters.Add(New SqlParameter("?", m_status))

136.

cmd.ExecuteNonQuery()

137.
138.

'trans.Commit()

139.
140.

Catch ex As Exception

141.

'If Not trans Is Nothing Then

142.

' trans.Rollback()

143.

'End If

144.

Throw New System.Exception(ex.Message + vbCrLf + ex.StackTrace)

145.
146.
147.
148.

Finally
If conn.State = ConnectionState.Open Then
conn.Close()
End If

149.
150.

'trans = Nothing

151.

dr = Nothing

152.
153.

conn = Nothing
End Try

154. End Sub


155. End Class

Global User
GetData() SaveData()
Table SQL
1.

Dim oEmp As New clsEmployee

2.
3.

oEmp.GetData("A0001")

4.
5.

MsgBox(oEmp.email)

Class DLL

29.

...

Code Complete

--

, , $_$

...XD

...XD

PEII PCWindows 3.1


MachintoshSUN Sparc
486
Windows 95 FormatFormat
...XD

Know How User User


User

PO

Copy & Paste Copy

...XD

Bill Gates

60
GWBasic

BBS Demo

Code Complete 1993 16 Software Construction

Design Pattern

Leader
15

Blog

30.

Team ...

100 100 100


100

A B

Promote

......XD

You might also like