?? module1.bas
字號:
Attribute VB_Name = "Module1"
Option Explicit
Global Const pIP As String = "amymax"
Global Const pConn As String = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Documents;Data Source=" & pIP
Dim Dxsgx(40, 1 To 4) As Variant '*****PrintNum——要打印的字段的個數*****
Public Sub EXEPrint(ByVal PrintSource As String, ByVal PrintString As String)
'打印施工單
On Error GoTo cmdPrint_err
Dim strContent() As String
Dim strPrint As String '為要打印的字符串
Dim i As Long
Dim j As Long
Printer.ScaleMode = vbMillimeters '設置打印精度為毫米
Printer.Font = "宋體" '定義字體
'初始化打印位置
Init_Print PrintSource
strContent = Split(PrintString, Chr(255)) '用Chr(255)分隔
For j = 0 To UBound(strContent, 1) - 1 '打印項數
If Trim(strContent(j)) <> "" Then '該項傳入了非空字符時才打印
If Dxsgx(j, 1) = 0 Then
Printer.CurrentX = (Printer.ScaleWidth - Printer.ScaleLeft - Len(strContent(j)) * Dxsgx(j, 3) * 20 / 56.7) / 2
Else
Printer.CurrentX = Dxsgx(j, 1)
End If
Printer.CurrentY = Dxsgx(j, 2)
Printer.FontSize = Dxsgx(j, 3)
Printer.FontBold = Dxsgx(j, 4)
'用一個中文全角空格替換兩個英文半角空格
strPrint = Replace(strContent(j), " ", " ")
Select Case PrintSource
Case "FaWenGaoZhi"
Select Case j '*****j——需要換行的字段的序號*****
Case 3
FormatStr strPrint, 9, 6, Printer.CurrentX, Printer.CurrentY, False '*****9——每行幾個漢字*****
Case 4
FormatStr strPrint, 8, 6, Printer.CurrentX, Printer.CurrentY, False '*****6——行距*****
Case 5
FormatStr strPrint, 12, 6, Printer.CurrentX, Printer.CurrentY, False '*****Printer.CurrentX——打印的起始位置X*****
Case 6
FormatStr strPrint, 10, 6, Printer.CurrentX, Printer.CurrentY, False '*****Printer.CurrentX——打印的起始位置Y*****
Case 21
FormatStr strPrint, 28, 15, Printer.CurrentX, Printer.CurrentY, True, 7, 16 '*****True——是否需要換頁*****
Case Else '*****7——第一頁要打印的行數*****
Printer.Print strPrint '*****16——第二頁要打印的行數*****
End Select
Case "QianBao"
Select Case j
Case 1
FormatStr strPrint, 32, 15, Printer.CurrentX, Printer.CurrentY, True, 5, 16
Case Else
Printer.Print strPrint
End Select
Case "BianHan"
Select Case j
Case 1
FormatStr strPrint, 30, 12, Printer.CurrentX, Printer.CurrentY, True, 18, 22
Case Else
Printer.Print strPrint
End Select
Case "FaWen"
Select Case j
Case 3
FormatStr strPrint, 30, 10, Printer.CurrentX, Printer.CurrentY, True, 12, 22
Case Else
Printer.Print strPrint
End Select
End Select
End If
Next
Printer.EndDoc '發送到打印機
Exit Sub
cmdPrint_err:
Select Case Err.Number
Case 482
MsgBox "出錯,請確定打印連接是否正常!", vbOKOnly + vbExclamation, "提示信息"
Case Else
MsgBox "出錯:" & Chr(13) & "錯誤號=" & Err.Number & ";錯誤描述:" & Err.Description, vbOKOnly + vbInformation, "提示信息"
End Select
End Sub
'*****初始化打印數組,確定打印位置X、打印位置Y、字號*****
Private Sub Init_Print(ByVal PrtSource As String)
Select Case PrtSource
Case "FaWenGaoZhi"
'發文標題
Dxsgx(0, 1) = 105
Dxsgx(0, 2) = 9
Dxsgx(0, 3) = 20
Dxsgx(0, 4) = False
'密級
Dxsgx(1, 1) = 60
Dxsgx(1, 2) = 19
Dxsgx(1, 3) = 13
Dxsgx(1, 4) = False
'緩急
Dxsgx(2, 1) = 138
Dxsgx(2, 2) = 19
Dxsgx(2, 3) = 13
Dxsgx(2, 4) = False
'簽發
Dxsgx(3, 1) = 28
Dxsgx(3, 2) = 30
Dxsgx(3, 3) = 13
Dxsgx(3, 4) = False
'復核
Dxsgx(4, 1) = 78
Dxsgx(4, 2) = 30
Dxsgx(4, 3) = 13
Dxsgx(4, 4) = False
'核稿
Dxsgx(5, 1) = 122
Dxsgx(5, 2) = 30
Dxsgx(5, 3) = 13
Dxsgx(5, 4) = False
'主辦單位和擬稿人
Dxsgx(6, 1) = 138
Dxsgx(6, 2) = 48
Dxsgx(6, 3) = 13
Dxsgx(6, 4) = False
'相關文件
Dxsgx(7, 1) = 140
Dxsgx(7, 2) = 62
Dxsgx(7, 3) = 13
Dxsgx(7, 4) = False
'會簽
Dxsgx(8, 1) = 40
Dxsgx(8, 2) = 73
Dxsgx(8, 3) = 13
Dxsgx(8, 4) = False
'事由
Dxsgx(9, 1) = 40
Dxsgx(9, 2) = 87
Dxsgx(9, 3) = 13
Dxsgx(9, 4) = False
'主送機關
Dxsgx(10, 1) = 50
Dxsgx(10, 2) = 101
Dxsgx(10, 3) = 13
Dxsgx(10, 4) = False
'主送附件
Dxsgx(11, 1) = 140
Dxsgx(11, 2) = 101
Dxsgx(11, 3) = 13
Dxsgx(11, 4) = False
'抄送機關
Dxsgx(12, 1) = 50
Dxsgx(12, 2) = 115
Dxsgx(12, 3) = 13
Dxsgx(12, 4) = False
'抄送附件
Dxsgx(13, 1) = 140
Dxsgx(13, 2) = 115
Dxsgx(13, 3) = 13
Dxsgx(13, 4) = False
'主題詞
Dxsgx(14, 1) = 50
Dxsgx(14, 2) = 129
Dxsgx(14, 3) = 13
Dxsgx(14, 4) = False
'發文字
Dxsgx(15, 1) = 43
Dxsgx(15, 2) = 140
Dxsgx(15, 3) = 13
Dxsgx(15, 4) = False
'發文號
Dxsgx(16, 1) = 81
Dxsgx(16, 2) = 140
Dxsgx(16, 3) = 13
Dxsgx(16, 4) = False
'打印份數
Dxsgx(17, 1) = 165
Dxsgx(17, 2) = 140
Dxsgx(17, 3) = 13
Dxsgx(17, 4) = False
'打字人
Dxsgx(18, 1) = 40
Dxsgx(18, 2) = 152
Dxsgx(18, 3) = 13
Dxsgx(18, 4) = False
'校對人
Dxsgx(19, 1) = 89
Dxsgx(19, 2) = 152
Dxsgx(19, 3) = 13
Dxsgx(19, 4) = False
'封發日期
Dxsgx(20, 1) = 137
Dxsgx(20, 2) = 152
Dxsgx(20, 3) = 13
Dxsgx(20, 4) = False
'內容
Dxsgx(21, 1) = 25
Dxsgx(21, 2) = 170
Dxsgx(21, 3) = 16
Dxsgx(21, 4) = False
Case "QianBao"
'標題
Dxsgx(0, 1) = 50
Dxsgx(0, 2) = 180
Dxsgx(0, 3) = 14
Dxsgx(0, 4) = False
'內容
Dxsgx(1, 1) = 28
Dxsgx(1, 2) = 196
Dxsgx(1, 3) = 14
Dxsgx(1, 4) = False
Case "BianHan"
'標題
Dxsgx(0, 1) = 0
Dxsgx(0, 2) = 56
Dxsgx(0, 3) = 16
Dxsgx(0, 4) = True
'內容
Dxsgx(1, 1) = 26
Dxsgx(1, 2) = 66
Dxsgx(1, 3) = 14
Dxsgx(1, 4) = False
Case "FaWen"
'文件編號
Dxsgx(0, 1) = 70
Dxsgx(0, 2) = 116
Dxsgx(0, 3) = 14
Dxsgx(0, 4) = False
'簽發人
Dxsgx(1, 1) = 142
Dxsgx(1, 2) = 116
Dxsgx(1, 3) = 14
Dxsgx(1, 4) = False
'標題
Dxsgx(2, 1) = 0
Dxsgx(2, 2) = 138
Dxsgx(2, 3) = 16
Dxsgx(2, 4) = True
'內容
Dxsgx(3, 1) = 26
Dxsgx(3, 2) = 148
Dxsgx(3, 3) = 14
Dxsgx(3, 4) = False
End Select
End Sub
Private Sub FormatStr(ByVal InputStr As String, _
ByVal LineLength As Integer, _
ByVal LineHeight As Integer, _
BeginX As Integer, _
BeginY As Integer, _
blnPage As Boolean, _
Optional FirstN As Integer = 0, _
Optional SecondN As Integer = 0)
Dim tmpX As Integer
Dim tmpY As Integer
Dim i, p As Integer
Dim iPos As Integer
Dim tempStr As String
tmpX = BeginX
tmpY = BeginY
tempStr = Left(InputStr, LineLength)
iPos = InStr(1, tempStr, Chr(13))
If Len(InputStr) > LineLength Then
Do While Len(InputStr) > LineLength Or iPos > 0
If iPos > 0 Then
If Len(InputStr) > LineLength Then
InputStr = Right(tempStr, Len(tempStr) - iPos - 1) & Right(InputStr, Len(InputStr) - LineLength)
Else
InputStr = Right(tempStr, Len(tempStr) - iPos - 1)
End If
tempStr = Left(tempStr, iPos - 1)
Else
InputStr = Right(InputStr, Len(InputStr) - LineLength)
End If
Printer.CurrentX = tmpX
Printer.CurrentY = tmpY + i * LineHeight
Printer.Print tempStr
i = i + 1
If blnPage And p = 0 And i = FirstN Then '*****p——第幾頁*****
Printer.NewPage '*****6——第一頁打印行數*****
p = 1
i = 0
tmpX = tmpX
tmpY = 30
End If
If blnPage And p > 0 And i = SecondN Then '*****15——后續頁打印行數*****
Printer.NewPage
p = p + 1
i = 0
tmpX = tmpX
tmpY = 30
End If
tempStr = Left(InputStr, LineLength)
iPos = InStr(1, tempStr, Chr(13))
Loop
End If
Printer.CurrentX = tmpX
Printer.CurrentY = tmpY + i * LineHeight
Printer.Print InputStr
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -