1
2
1-1 Visual Basic 3
1-2 3/8-3/21 3/22-4/4 4/5-4/18 4/19-5/2 5/3-5/16 5/17-5/30 5/31-6/13 6/14-6/27 6/28-7/11 7/12-7/25 7/26-8/8 8/9-8/22 8/25-9/5 9/6-9/19 9/20-10/3 10/4-10/17 10/18-10/31 11/15-11/28 11/29-12/12 4
1-3 5
RS232 2-1 RS-232C RS-232C EIA RS-2322 1 RS-232C -25V~25V TTL 0V~5V 1 RS-232C TTL? RS-232C TTL 0V~0.5V 0 3.5V~5V 1 1 0 爲 -15V~+15V -3V~-15V 1 3V~+15V 0-12V~+12V -3V~-12V 1 3V~+12V 0 6
RS-232 3.5V~5.0V +5V~25V +5V~+25V 1 0 1 0.5V~3.5V -5V~+5V -5V~+5V 0V~0.5V 5V~25V -5V~25V 0 1 0 TTL 1 RS-232C TTL 2 爲 0V~+5V 8051 TTL5V MAX232 5V 12V RS-232C -12V~12V CPU TTL5V I / O MAX232 5V/12V 8051 TTL5 V 7
2 2RS232C RS-232C 9PIN25PIN D 3 1 3 5 7 9 19 Pin 2 4 6 8 10 12 14 16 18 20 22 24 225 Pin 3 3 爲 RS-232C 9PIN 25PIN D 9PIN 25PIN 1 8 DCD DCD=0 2 3 RXD 3 2 TXD 4 19 DTR 8
5 7 GND DTR=0 6 6 DSR DSR=0 7 4 RTS RTS=0 DSR=0 8 5 CTS 9 22 RI RI=0 3 9
3 RS-232C RS-232C 15 20KBps 4 PC PC LAN 10
4 1 F ASCII 69 46H 5 7~8 / 1~2 爲 1 爲 0 1 2 1 F LSB MSB 6 4 MSB F LSB 0 1 0 0 0 1 1 0 0 ASCII=46H 1 0 5 11
2-2 一維條碼的定義 12
圖 1 條碼的技術層面 13
14
圖 2 15
16
17
18
Visual Basic 19
20
3-2 Visual Basic GUI 3-3 Visual Basic Visual Basic VB Microsoft Visual Basic GUIGraphic User Interface 21
Windows ObjectWindows Windows DOS Windows Windows Windows Windows Borland C++Delphi Visual Basic 1964 Dartmouth John Kemery Thomas Basic 1980 Apple II Apple II Basic GW BasicTurbo BasicQuick Basic 22
1988 Quick Basic Basic 1991 Quick Basic Window 3.0 Visual Basic 1.0 Windows Visual Basic Windows Visual Basic 6.0 Visual Basic 6.0 ( )( )( ) Windows 98 Windows Windows NT MSDN (Microsoft Developer Network) Active X Internet Information Visual Active HTML Visual DatabaseData EnvironmentInternet Information Server Application DesignerDynamic HTML PAGE designerado (Active Data Object) 23
Visual Basic 6.0( ) 1. FilterJoinReplaceSplit StrReverseInstrRev 2. Dictionary Collection 3. 4. CallByName Internet 1. DHTML (Dynamic Hyper Text Markup Language) DHTML Visual Basic 2. IIS(Internet Information Server) Visual Basic Internet Server 24
DataGridDatalistData Combo DataRepeaterDataTimePickerFlat ScrollbarADO DataCoolbar ADO(ActiveX Data Object) Web Data Repeater Data Report Data Environment Command Data Repeater (Data Environment) SOL SQL ServerMicrosoft Transaction Server Internet Information ServerVisual Source SafeSNA Server ( ) ( ) 3-4 Visual Basic 25
Visual Basic 26
Visual Basic Checkbox True/False Yes/No ComboBox CommandButton 27
Data DirListBox DriveListBox FileListBox Frame HscrollBar VscrollBar Image Windows JPEGGIF Label Line 28
ListBox OLE OptionButton Visual Basic Option Button PictureBox Windows JPEG GIF Shape Text box Timer 29
30
Visual Basic Visual Basic 31
32
4-1 33
34
, 35
36
37
4-2 38
4-3 (form7) Private Sub Command1_Click() 39
Unload Me Form1.Show.. FORM1.,. Private Sub Command2_Click() Unload Me Form9.Show Private Sub Command3_Click() End. Private Sub Command4_Click() Unload Me Form8.Show (form1) Private Sub Command1_Click() Unload Me Form7.Show Private Sub Command2_Click() Form1.Enabled = False Form5.Show Private Sub Command3_Click() Form1.Enabled = False Form2.Show Private Sub Command4_Click() Form1.Enabled = False Form1 Enabled False 40
Form3.Show Private Sub Command5_Click() Form1.Enabled = False Form4.Show Private Sub Form_Load() Timer1.Interval = 100 0.1..(1000=1 ) Private Sub Option1_Click() DataGrid1.Enabled = True Private Sub Option2_Click() DataGrid1.Enabled = False Private Sub Timer1_Timer() Label1 = Time Label1 41
. (form2) 42
Private Sub Comm1_OnComm() Select Case Comm1.CommEvent Case comevcd Case comevcts Case comevdsr Case comevring Case comevreceive Text5.Text = Text5.Text + Trim(Comm1.Input) Text5 Text2.Text = Now Text2 Case comevsend End Select Private Sub Command1_Click() Dim con As ADODB.Connection Dim rs1 As New ADODB.Recordset Set con = New ADODB.Connection If Text1.Text = "" Or Text5.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then MsgBox " ",, " ( ) Exit Sub End If con.connectionstring = "provider=microsoft.jet.oledb.3.51;" _ & "Data Source=D:\ \ \123.mdb" con.open rs1.open " ", con, adopenstatic, adlockoptimistic If Not rs1.bof = True Then pp: If Text5.Text = rs1! Then MsgBox (" ") rs1.update con.close GoTo ww Else rs1.movenext If rs1.eof = True Then rs1.addnew rs1! = Text1.Text 43
rs1! = Text5.Text rs1! = Text3.Text rs1! = Text4.Text rs1! = Text2.Text rs1.update con.close GoTo ww Else GoTo pp End If End If Else rs1.addnew rs1! = Text1.Text rs1! = Text5.Text rs1! = Text3.Text rs1! = Text4.Text rs1! = Text2.Text rs1.update con.close GoTo ww End If ww: Unload Me Unload Form1 Form1.Show Form1.Enabled = True Private Sub Command2_Click() Unload Me Form1.Show Form1.Enabled = True Private Sub Form_Load() Comm1.PortOpen = True Timer1.Interval = 1000 44
, (form4) 45
Dim I Sub your() Dim wei As ADODB.Connection Dim rs2 As New ADODB.Recordset Set wei = New ADODB.Connection wei.connectionstring = "provider=microsoft.jet.oledb.3.51;" _ & "Data Source=D:\ \ \321.mdb" wei.open rs2.open " ", wei, adopenstatic, adlockoptimistic pp: If Text3.Text = rs2! Then rs2.find " ='" + Text3.Text + "'" Text2 = rs2! Text1 = rs2! wei.close Exit Sub Else rs2.movenext If rs2.eof = True Then MsgBox " ",, " wei.close Exit Sub Else GoTo pp End If End If Sub my() Dim con As ADODB.Connection Dim rs1 As New ADODB.Recordset Set con = New ADODB.Connection con.connectionstring = "provider=microsoft.jet.oledb.3.51;" _ & "Data Source=D:\ \ \123.mdb" con.open rs1.open " ", con, adopenstatic, adlockoptimistic pp: 46
If Text3.Text = rs1! Then rs1.find " ='" + Text3.Text + "'" Te2 = rs1! Te3 = rs1! Te4 = rs1! Te5 = rs1! Te1 = rs1! I = 0 Exit Sub Else rs1.movenext If rs1.eof = True Then MsgBox " ",, " Text3.Text = "" con.close I = 0 Exit Sub Else GoTo pp End If End If Private Sub Comm1_OnComm() Select Case Comm1.CommEvent Case comevcd Case comevcts Case comevdsr Case comevring Case comevreceive I = I + 1 Select Case I Case 1 Text3.Text = Text3.Text + Trim(Comm1.Input) Exit Sub Case 2 Text3.Text = Text3.Text + Trim(Comm1.Input) Call my 47
Call your Text3.Text = "" End Select Case comevsend End Select ' Private Sub Command1_Click() f772.show Private Sub Command2_Click() Unload Me Form1.Show Form1.Enabled = True Private Sub Form_Load() Comm1.PortOpen = True 48
, (form3) 49
Dim wei As ADODB.Connection Dim rs2 As New ADODB.Recordset Dim con As ADODB.Connection Dim rs1 As New ADODB.Recordset Dim I Sub my() Set con = New ADODB.Connection con.connectionstring = "provider=microsoft.jet.oledb.3.51;" _ & "Data Source=D:\ \ \123.mdb" con.open rs1.open " ", con, adopenstatic, adlockoptimistic pp: If Text1.Text = rs1! Then rs1.find " ='" + Text1.Text + "'" Te1 = rs1! Te2 = rs1! Te3 = rs1! I = 0 con.close Exit Sub Else rs1.movenext If rs1.eof = True Then MsgBox " ",, " " Text1.Text = "" con.close Exit Sub Else GoTo pp End If End If Private Sub Comm1_OnComm() Select Case Comm1.CommEvent Case comevcd Case comevcts Case comevdsr 50
Case comevring Case comevreceive I = I + 1 Select Case I Case 1 Text1.Text = Text1.Text + Trim(Comm1.Input) Exit Sub Case 2 Text1.Text = Text1.Text + Trim(Comm1.Input) Call my End Select Case comevsend End Select ' Private Sub Command1_Click() Set wei = New ADODB.Connection Set con = New ADODB.Connection wei.connectionstring = "provider=microsoft.jet.oledb.3.51;" _ & "Data Source=D:\ \ \321.mdb" wei.open rs2.open " ", wei, adopenstatic, adlockoptimistic con.connectionstring = "provider=microsoft.jet.oledb.3.51;" _ & "Data Source=D:\ \ \123.mdb" con.open rs1.open " ", con, adopenstatic, adlockoptimistic If Not rs2.bof = True Then ee: If Text1.Text = rs2! Then MsgBox (" ") rs1.update con.close rs2.update wei.close GoTo ww Else rs2.movenext If rs2.eof = True Then 51
If rs1! <= "Text2.Text" Then rs1.find " ='" + Text1.Text + "'" rs2.addnew rs2! = rs1! rs2! = rs1! rs2! = rs1! rs2! = Text2.Text rs2! = rs1! rs2! = Now rs1! = rs1! - Text2.Text rs1.update con.close rs2.update wei.close GoTo ww Else MsgBox " " Exit Sub End If Else GoTo ee End If End If Else rs1.find " ='" + Text1.Text + "'" rs2.addnew rs2! = rs1! rs2! = rs1! rs2! = rs1! rs2! = Text2.Text rs2! = rs1! rs2! = Now rs1! = rs1! - Text2.Text rs1.update con.close rs2.update wei.close GoTo ww 52
End If ww: Unload Me Unload Form1 Form1.Show Private Sub Command2_Click() Unload Me Form1.Show Form1.Enabled = True Private Sub Form_Load() Comm1.PortOpen = True 53
(form5) 54
Private Sub Comm1_OnComm() Select Case Comm1.CommEvent Case comevcd Case comevcts Case comevdsr Case comevring Case comevreceive Text1.Text = Text1.Text + Trim(Comm1.Input) Case comevsend End Select ' Private Sub Command1_Click() Dim con As ADODB.Connection Dim rs1 As New ADODB.Recordset Dim nn As String Set con = New ADODB.Connection con.connectionstring = "provider=microsoft.jet.oledb.3.51;" _ & "Data Source=D:\ \ \123.mdb" con.open rs1.open " ", con, adopenstatic, adlockoptimistic pp: If rs1.eof = True Then MsgBox " ",, " " Text1.Text = "" Exit Sub End If If Text1.Text = rs1! Then rs1.find " ='" + Text1.Text + "'" nn = MsgBox("?", vbyesno, " ") If nn = vbyes Then rs1.delete con.close Text1.Text = "" GoTo oo End If 55
If nn = vbno Then ww: MsgBox " ",, " " con.close Text1.Text = "" Exit Sub End If Else rs1.movenext GoTo pp End If oo: Unload Me Unload Form1 Form1.Show Private Sub Command2_Click() Unload Me Form1.Show Form1.Enabled = True Private Sub Form_Load() Comm1.PortOpen = True 56
a a = a + a, (form9) 57
Dim n n Dim con As ADODB.Connection Dim oon As ADODB.Connection Dim rs1 As New ADODB.Recordset Dim rs2 As New ADODB.Recordset Sub add() rs1.addnew rs1! = rs2! rs1! = rs2! rs1! = rs2! rs1! = 1 rs1! = Now rs1! = rs1! * rs1! rs1.update con.close rs2.update oon.close Sub mtt() Dim a a L2.Caption = "" Set con = New ADODB.Connection con.connectionstring = "provider=microsoft.jet.oledb.3.51;" _ & "Data Source=D:\ \ \321.mdb" con.open rs1.open " ", con, adopenstatic, adlockoptimistic aa: a = L2.Caption If rs1.eof = True Then con.close Exit Sub Else L2.Caption = Val(a) + Val(rs1! ) rs1.movenext GoTo aa End If Sub you() 58
Set con = New ADODB.Connection Set oon = New ADODB.Connection oon.connectionstring = "provider=microsoft.jet.oledb.3.51;" _ & "Data Source=D:\ \ \321.mdb" con.connectionstring = "provider=microsoft.jet.oledb.3.51;" _ & "Data Source=D:\ \ \321.mdb" con.open oon.open rs1.open " ", con, adopenstatic, adlockoptimistic rs2.open " ", oon, adopenstatic, adlockoptimistic '******************************************************************** pp: If Text1.Text = rs2! Then rs2.find " ='" + Text1.Text + "'" rs2! = rs2! - 1 rs2.update If Not rs2.bof = True Then If rs1.bof = True Then Call add GoTo ww Else dd: If Text1.Text = rs1! Then rs1.find " ='" + Text1.Text + "'" rs1! = rs1! + 1 rs1! = rs1! * rs1! rs1.update con.close rs2.update oon.close GoTo ww Else rs1.movenext End If End If If rs1.eof = True Then Call add 59
GoTo ww Else GoTo dd End If Else rs2.movenext End If If rs2.eof = True Then MsgBox " ",, " n = 0 Text1.Text = "" oon.close con.close Exit Sub Else GoTo pp End If Else MsgBox " ",, " n = 0 Text1.Text = "" oon.close con.close Exit Sub End If '------------------------------------------- ww: n = 0 Unload Me Form9.Show Private Sub Comm1_OnComm() Select Case Comm1.CommEvent Case comevcd Case comevcts Case comevdsr Case comevring 60
Case comevreceive n = n + 1 Select Case n Case 1, 2 Text1.Text = Text1.Text + Trim(Comm1.Input) If n = 2 Then Call you End If Exit Sub End Select Case comevsend Case comevsend End Select Private Sub Command1_Click() Call you Private Sub Command2_Click() If Text2.Text = "" Then MsgBox "!!",, " Exit Sub End If Form6.Show Private Sub Command3_Click() Unload Me Form7.Show Private Sub Command4_Click() Unload Me Form8.Show Private Sub Command5_Click() 61
L3.Caption = Val(Text2) - Val(L2) Private Sub Command7_Click() Form6.Show Private Sub Form_Load() Comm1.PortOpen = True Timer1.Interval = 100 Private Sub Timer1_Timer() tl6 = Time Call mtt 62
,,, (Form6) 63
Dim con As ADODB.Connection Dim rs3 As New ADODB.Recordset Sub del() Set con = New ADODB.Connection dd: con.connectionstring = "provider=microsoft.jet.oledb.3.51;" _ & "Data Source=D:\ \ \321.mdb" con.open rs3.open " ", con, adopenstatic, adlockoptimistic If rs3.bof Then GoTo 123 Else rs3.delete rs3.update con.close GoTo dd End If 123: con.close Unload Me Unload Form9 Form9.Show Private Sub Command1_Click() Call del Private Sub Form_activate() Set con = New ADODB.Connection con.connectionstring = "provider=microsoft.jet.oledb.3.51;" _ & "Data Source=D:\ \ \321.mdb" con.open rs3.open " ", con FontSize = 18 Print " " FontSize = 12 Print Format(Now) 64
Print " "; Tab(10); " "; Tab(20); " "; Tab(30); " " Print "============================================================ ========================" pp: Print rs3! ; Tab(10); rs3! ; Tab(20); rs3! ; Tab(30); rs3! rs3.movenext If Not rs3.eof = True Then GoTo pp End If Print Print Print Tab(20); " :"; Tab(30); Form9.L2 Print Tab(20); "Cash:"; Tab(30); Form9.Text2 Print Tab(20); "Change:"; Tab(30); Form9.L3 con.close 65
RS-232C 66
,,,,,,, RS-232, VB VB, VB. 67
Visual Basic Visual Basic Visual Basic Visual Basic PLC PLC Visual Basic 68
VB VB VB 69
Visual Basic Visual Basic RS232 Visual Basic Visual Basi 70
Visual Basic 6.0 / Visual Basic RS232 / / / Visual Basic 6.0 / Visual Basic 6.0 / 71