Professional Documents
Culture Documents
20 ...
DOS Basic, C, Pascal, Fortran... Windows Visual Basic, Delphi, .Net, Java.../
...DHTML Ajax
3GL
Code Complete
.
.
.
.
.
.Error Handling
.
.
.
.
1.--
Runtime
1.
100
1.
. "Devided by Zero"
0
1.
x=a/b
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.
3.
4.
x=a/b
1.
dim x as integer
2.
3.
4.
x=a/b
.Overflow
16 2^16 - 1 65536
32767 Runtime
.Intermediate results
3.--
0 1
5, 6
OK
.
1000000.00+0.01 1000000.00
Compiler
(1000000*100+0.01*100)/100
.""
0.1 1.0
1.
2.
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.
2.
...
, , scan , ,
,
, (Constant),
, ,
, ,
,
, , , , , ,
, , ,
,
, IS ,
, ,
5.--
0false) 1(true) -1 1
Boolean
1.
2.
or (ElementIdx=LastElementIdx) then
3.
...
4.
end if
1.
2.
RepeatedEntry=(ElementIdx=LastElementIdx)
3.
4.
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.
4.
5.
6.
7.
8.
9.
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.
10.
11. ispassed=(a or b or otrs)
1.
'
2.
if ispassed then
3.
4.
5.
6.
6.--
Enum
.
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.
5.
Norman = 1
6.
Mike = 2
7.
Reece = 3
8.
End Enum
9.
10.
11.
12.
13.
14.
15.
End Sub
http://www.java2s.com/Code/VB/Language-Basics/EnumdataDemo.htm
7.--
Constant
OK
Editor Replace
8.--
Link List BASIC
...
...XD
.
Dynamic
1.
2.
3.
i=0
4.
Do while i<n
5.
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
1.
2.
3.
instance.Add("a")
4.
instance.Add("c")
5.
instance.Insert(1,"b")
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.
2.
3.
4.
EasyWayRoutine(EmployeeRec)
Structured Data
.
Basic
Structured Data
Structured Data
10.--
.
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
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.
2.
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.
2.
3.
4.
Sub init()
5.
a=""
6.
b=""
7.
8.
i=0
9.
j=0
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.
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.
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()
. case case
case if-else case
1.
2.
3.
if x="ABC" then
4.
5.
end if
6.
end select
if
. default
defalut default case
15.--
statement
User ...XD for-loopwhile-loop, do-until...
1.
2.
3.
1.
do while dr.read()
2.
...
3.
loop
.
while(!rs.eof) i++;
.
console waiting
1.
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.
}
}
. goto continue
VB6 continue goto
1.
2.
3.
4.
5.
6.
2.
read(Record, File)
3.
if (Record.type<>TargetType) then
4.
continue
5.
....
6.
loop
continue
Goto
Goto
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.
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.
2.
3.
ret=0
4.
5.
6.
7.
if SomeExpress then
ret=1
end if
8.
9.
A=ret
. Return
Return Return
Return
17.
Block
( { () {}
Leader
Follow
Tab
Capital
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.
2.
3.
4.
...
Mark ^^b
. 80
80 A4
80
.
1.
ReadEmployeeData(MaxEmps,EmpData,InputFile,EmpCount,InputError)
. ,
1.
.
Pascal
18.
1.
'*****************************************************************
2.
'* CopyString
3.
'*
4.
'* (Source$)(Target$)
5.
'*
6.
7.
'*
Source$
8.
'*
Target$
9.
'*
Blog
.
.
.
.
.
.
HTML
[b].
Open Source
.
.
.
Open
19.
--
API JavaDoc
JavaDoc
JavaDoc
API
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
Try
' Your Code
Catch e as ExceptionTypeI
' Error Handling
Catch e as ExceptionTypeII
' Error Handling
Catch e as ExceptionTypeIII
' Error Handling
Finally
' Release Object
1.
2.
3.
4.
5.
ExitSub:
6.
7.
8.
9.
10.
Resume ExitSub
Error Handling
1.
2.
ErrorHandling:
msgbox Err.Description
VB
1.
2.
ErrorHandling:
msgbox ""
Validation
Google Chrome
User
^^b
...XD
22.
DOS Widnows
Encapsulation
Abstraction
Class
Instance
Reuse Inheritance
Polymorphism
Interface)Implement
DLL
23.
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.
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.
Class () Method
1.
2.
o ;
3.
4.
5.
6.
return o .;
}
[0]-> [1]-> ()
1.
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
Copy Pattern
ini log Error email
Visual Studio
Class Library .Net 2.0
Project
CLass Diagram
Form
Parent Form
Error Handling Log
Form
BaseForm
BaseForm.vb
1.
2.
3.
4.
5.
6.
7.
8.
9.
mnuSwitch.Text = ""
mnuSwitch_Click(sender, e)
End Sub
10.
11.
12.
13.
14.
Timer1.Enabled = True
15.
ShowTimer()
16.
End Sub
17.
18.
19.
20.
ToolStripStatusLabel2.Text = Now().ToString
End Sub
21.
22.
23.
24.
25.
26.
27.
Timer2.Enabled = mnuSwitch.Text.Equals("")
28.
29.
log.Writeln(mnuSwitch.Text, TraceEventType.Information)
30.
31.
End Sub
32.
33.
34.
35.
36.
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.
42.
43.
44.
sendmail.Send()
End Sub
Log.vb
1.
2.
3.
4.
End Sub
5.
6.
7.
8.
Try
9.
Application.DoEvents()
10.
11.
12.
Catch ex As IO.IOException
My.Application.Log.WriteException(ex, _
13.
TraceEventType.Error, _
14.
Now().ToString)
15.
End Try
16.
End Sub
Exception Log
SendMail.vb
1.
Imports System.Net.Mail.SmtpClient
2.
Imports System.Net.Mail.MailMessage
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
End Sub
17.
18.
19.
20.
21.
End If
22.
End Sub
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
Windows Form
Class Diagram
Form
Form2.vb
1.
2.
3.
4.
5.
6.
7.
RunTimer = 1
8.
9.
10.
doCheck()
Else
RunTimer += 1
11.
End If
12.
End Sub
13.
14.
15.
sendmail.SmtpClient.Host = My.Settings.SMTP
16.
17.
sendmail.Message.To.Add(My.Settings.Rcpt)
18.
End Sub
19.
20.
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
C:\Temp\ InheritanceTest.log
1.
2.
3.
4.
Base Form
mnuSwitch Form2_Load
1.
MyBase.mnuSwitch.PerformClick()
Namespace My
2.
3.
' MyApplication :
4.
'
5.
' Startup:
6.
' Shutdown:
7.
' UnhandledException:
8.
' StartupNextInstance:
9.
' NetworkAvailabilityChanged:
10.
11.
12.
13.
My.Application.Log.WriteException(e.Exception, _
14.
TraceEventType.Critical, _
15.
16.
My.Computer.Clock.GmtTime.ToString)
17.
End Sub
18.
End Class
19.
20. End Namespace
<system.diagnostics>
<sources>
3.
4.
5.
<listeners>
6.
<add name="FileLog"/>
7.
8.
</listeners>
9.
</source>
10.
</sources>
11.
...
12.
<sharedListeners>
13.
<add name="FileLog"
14.
15.
16.
initializeData="FileLogWriter"/>
<add name="FileLogListener"
17.
18.
initializeData="FileLogListenerWriter"
19.
location="Custom"
20.
customlocation="c:\temp\" />
21.
22.
...
</sharedListeners>
23. </system.diagnostics>
27.--
2.
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.
If ElseIf 12
Format Cstr(yy)+"/"+Cstr(mm)+"/31"
10 Cstr(yy)+"/0"+Cstr(mm)+"/31"
YES
1.
2.
3.
lastday = Format(Dateadd("d",-1,CDate(Format(Dateadd("m",1,Now),"yyyy/MM/01"))),"yyyy/MM/dd")
antijava
Event
Performance Debug Trace
Employee
1.
2.
3.
4.
5.
6.
7.
8.
) ON [PRIMARY]
9.
GO
10.
11. ALTER TABLE [dbo].[Employee] ADD
12.
13.
14.
15.
[empy_id]
) WITH FILLFACTOR = 90 ON [PRIMARY]
16. GO
Imports System.Data.SqlClient
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
End Get
15.
16.
17.
18.
m_empy_id = Value
End Set
End Property
19.
20.
21.
22.
23.
End Get
24.
25.
26.
27.
m_empy_nm = value
End Set
End Property
28.
29.
30.
31.
32.
End Get
33.
34.
35.
36.
m_dep_id = value
End Set
End Property
37.
38.
39.
40.
41.
End Get
42.
43.
44.
45.
m_role = value
End Set
End Property
46.
47.
48.
49.
50.
End Get
51.
52.
53.
54.
m_email = value
End Set
End Property
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
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.
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
104.
105.
Dim dr As SqlDataReader
106.
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.
119.
dr = cmd.ExecuteReader()
120.
If dr.HasRows Then
121.
dr.Close()
122.
123.
124.
cmd.ExecuteNonQuery()
End If
125.
126.
127.
128.
129.
cmd.Parameters.Clear()
130.
131.
132.
133.
134.
135.
136.
cmd.ExecuteNonQuery()
137.
138.
'trans.Commit()
139.
140.
Catch ex As Exception
141.
142.
' trans.Rollback()
143.
'End If
144.
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
Global User
GetData() SaveData()
Table SQL
1.
2.
3.
oEmp.GetData("A0001")
4.
5.
MsgBox(oEmp.email)
Class DLL
29.
...
Code Complete
--
, , $_$
...XD
...XD
PO
...XD
Bill Gates
60
GWBasic
BBS Demo
Design Pattern
Leader
15
Blog
30.
Team ...
A B
Promote
......XD