天天看點

vsflexgrid+列印整理後的方法合計功能放在表格裡面合計功能指派給文本框選擇單元格變色,設定下拉框控制隻能輸入數字設定列不可編輯+設定資料庫下拉框選擇下拉框資料,其它資料更新快速查詢VSFlexGrid3事件查找字元串對于的行生成行号自動調整列寬表格裡面加多選按鈕自動增加行vsFlexGrid+VSprinter列印寫INI配置檔案儲存列印機到ini

目錄

合計功能放在表格裡面... 2

合計功能指派給文本框... 3

選擇單元格變色,設定下拉框... 3

控制隻能輸入數字... 4

設定列不可編輯+設定資料庫下拉框... 5

選擇下拉框資料,其它資料更新... 6

快速查詢... 9

VSFlexGrid3事件... 10

查找字元串對于的行... 17

生成行号... 17

自動調整列寬... 17

表格裡面加多選按鈕... 18

自動增加行... 19

vsFlexGrid+VSprinter列印... 33

寫INI配置檔案... 48

儲存列印機到ini50

合計功能放在表格裡面

'

'    With VSFlexGrid3

'

'        .Redraw = flexRDNone

'        .AllowUserResizing = flexResizeColumns

'        .SubtotalPosition = flexSTBelow

'        .OutlineBar = flexOutlineBarSimpleLeaf

'

'        .Subtotal flexSTSum, 1, 3, , , RGB(0,0, 255), True, "%s小計:"

'        .Subtotal flexSTSum, -1, 3, , ,RGB(255, 0, 0), True, "總合計:"

'        .Redraw = True

'    End With

合計功能指派給文本框

For a = 1 ToVSFlexGrid3.Rows - 1

    aa = Val(aa) +Val(VSFlexGrid3.TextMatrix(a, 2)) '統計第二列

    bb = Val(bb) +Val(VSFlexGrid3.TextMatrix(a, 13)) '統計第二列

Next a

Label_js = aa

選擇單元格變色,設定下拉框

    .ColComboList(7) = "按件|按重"      '設定第7列為下拉框

    .ColComboList(10) = "按件|按重"     '設定第10列為下拉框

    .FocusRect = flexFocusNone          '選中單元格高亮

    .Editable = flexEDKbd

    .BackColorSel = &HFF&               '選中單元格紅色

'.SelectionMode = flexSelectionByRow '選中整行紅色

控制隻能輸入數字

'判斷輸入的值是否為數字.

Private SubVSFlexGrid3_KeyPressEdit(ByVal Row As Long, ByVal Col As Long, KeyAscii AsInteger)

Dim Numbers AsString

If VSFlexGrid3.Col= 5 Or VSFlexGrid3.Col = 6 Or VSFlexGrid3.Col = 8 Or VSFlexGrid3.Col = 9 OrVSFlexGrid3.Col = 11 Or VSFlexGrid3.Col = 12 Or VSFlexGrid3.Col = 13 OrVSFlexGrid3.Col = 14 Then '第6列

    Numbers = "1234567890" + Chr(46)+ Chr(8) + Chr(13)

    If InStr(Numbers, Chr(KeyAscii)) = 0 Then

        MsgBox "請輸入數字!!!", 16, "提示資訊"

        KeyAscii = 0

    End If

End If

End Sub

設定列不可編輯+設定資料庫下拉框

Private SubVSFlexGrid3_BeforeEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)

'*******先将設editable=2

'限定不可編輯列,如有5列,全部不可編輯

'If Col = 0 ThenCancel = True

'If Col = 1 ThenCancel = True

'If Col = 2 ThenCancel = True

'If Col = 3 ThenCancel = True

'If Col = 4 ThenCancel = True

'If Col = 5 Then Cancel= True

Dim Rst11 As NewADODB.Recordset

Rst11.Open"select * from YSPF_JCBH ", gConn, adOpenStatic, adLockReadOnly, -1

VSFlexGrid3.ColComboList(1)= VSFlexGrid3.BuildComboList(Rst11, "BH")

End Sub

選擇下拉框資料,其它資料更新

Private SubVSFlexGrid3_CellChanged(ByVal Row As Long, ByVal Col As Long)

Dim Rst12 As NewADODB.Recordset

With VSFlexGrid3

    If .Rows > 2 Then

        bh1 = .TextMatrix(.Row, 1)

        If bh1 <> "" And bh1<> "編号" Then

            Rst12.Open "select * fromYSPF_JCBH where BH='" & bh1 & "'", gConn, adOpenStatic,adLockReadOnly, -1

            .TextMatrix(.Row, 2) =Rst12("MC")

            .TextMatrix(.Row, 3) =Rst12("KH")

            .TextMatrix(.Row, 4) =Rst12("GG")

            .TextMatrix(.Row, 7) =Rst12("DJLX")

            .TextMatrix(.Row, 8) =Rst12("DJ")

            .TextMatrix(.Row, 10) =Rst12("GFLX")

            .TextMatrix(.Row, 11) =Rst12("GF")

            djlx = .TextMatrix(.Row, 7)

            gflx = .TextMatrix(.Row, 10)

            If djlx = "按件" Then

                .TextMatrix(.Row, 9) =Val(.TextMatrix(.Row, 5)) * Val(.TextMatrix(.Row, 8))

            End If

            If djlx = "按重" Then

                .TextMatrix(.Row, 9) =Val(.TextMatrix(.Row, 6)) * Val(.TextMatrix(.Row, 8))

            End If

            If gflx = "按件" Then

                .TextMatrix(.Row, 12) =Val(.TextMatrix(.Row, 5)) * Val(.TextMatrix(.Row, 11))

            End If

            If gflx = "按重" Then

                .TextMatrix(.Row, 12) =Val(.TextMatrix(.Row, 6)) * Val(.TextMatrix(.Row, 11))

            End If

                .TextMatrix(.Row, 13) =Val(.TextMatrix(.Row, 9)) + Val(.TextMatrix(.Row, 12))

        End If

    End If

End With

Call CalTotal

End Sub

快速查詢

部件用VSFlexGrid8.0(OLEDB)

Dim Rst1 As New ADODB.Recordset '定義一個資料庫記錄對象

Dim SqlDef As String '定義字元串變量

Screen.MousePointer = 11

SqlDef = "select * from YSPF_ZC_PLRKDMX "

Rst1.Open SqlDef, gConn, adOpenStatic, adLockReadOnly, -1 '進入資料庫查詢,并把查詢結果指派給rst記錄對象

Set VSFlexGrid1.DataSource = Rst1

VSFlexGrid3事件

事件

'單元得到選擇焦點。這五個事件執行順序為:

'BeforeSelChange,RowColChange,AfterRowColChange,SelChange,AfterSelChange

'滑鼠單擊單元。這五個事件執行順序為:

'BeforeMouseDown,BeforeEdit,MouseDown,MouseUp,Click

AfterCollapse()

AfterDataRefresh()    當綁定到資料庫時發生

AfterEdit()           單元按下任何鍵并離開目前單元後

AfterMoveColumn()

AfterMoveRow()        調整行高時

AfterRowColChange()   單元得到焦點時,不包括啟動窗體時

AfterScroll()         滾動條滑塊改變位置後(當ScrollTrack為True時,該事件同時發生,否則停止拖拉時才發生)

AfterSelChange()      單元得到焦點時,不包括啟動窗體時

AfterSort()

AfterUserFreeze()      調整當機的行列後

AfterUserResize()      調整行列大小時

BeforeCollapse()

BeforeDataRefresh()

BeforeEdit()           從表格顯示時的任何鍵盤或滑鼠欲改資料動作前

BeforeMouseDown()      當在表格任何地方按下滑鼠,相應在 MouseDown 之前

BeforeMoveColumn()

BeforeMoveRow()

BeforePageBreak()

BeforeRowColChange()  單擊或離開單元時

BeforeScroll()        滾動條滑塊改變位置後,AfterScroll事件前,基本同AfterScroll()事件

BeforeScrollTip()

BeforeSelChange()     單元得到焦點時,不包括啟動窗體時

BeforeSort()

BeforeUserResize()    當滑鼠指向欲調整行列寬度或高度時

CellButtonClick()

CellChanged()         當單元内容改變并離開時,無改變時不發生

ChangeEdit()          按下一個有效字元鍵時

Click()               用滑鼠單擊單元後

ComboCloseUp()        當單元中的下拉框按鈕拉出并複位時

ComboDropDown()       當單元中的下拉框按鈕拉下時

Compare()

DblClick()            用滑鼠輕按兩下單元後

DragDrop()

DragOver()

DrawCell()            當 OwnerDraw 屬性值大于 0 時執行表格重新整理動作

EnterCell()           離開或選擇目前單元時

Error()               表格發生錯誤時

FilterData()

GetHeaderRow()

GotFocus()            當表格得到焦點時

KeyDown()             按下任意鍵後字元顯示前

KeyDownEdit()         按下一個有效鍵後欲改前

KeyPress()            按下一個任意鍵後

KeyPressEdit()        按下一個有效字元鍵時,字元輸入前

KeyUp()               任意鍵盤操作時

KeyUpEdit()           按下一個任意鍵資料被改變後

LeaveCell()           離開單元焦點前

LostFocus()           離開表格焦點後

MouseDown()           滑鼠選中或移動時

MouseMove()           滑鼠晃動時

MouseUp()             滑鼠按下彈起後

OLECompleteDrag()

OLEDragDrop()

OLEDragOver()

OLEGiveFeedback()

OLESetCustomDataObject()

OLESetData()

OLEStartDrag()

RowColChange()        單元得到焦點時,包括窗體啟動時

SelChange()           得到焦點時

SetupEditStyle()      當欲改變單元内容前

SetupEditWindow()     單元被鍵盤欲改變前

StartEdit()           單元被鍵盤欲改變前

StartPage()

Validate()            離開表格焦點在LostFocus事件前

ValidateEdit()        單元内容被改變或離開目前單元時

'這四個事件執行順序為:

'ValidateEdit,AfterEdit,StartEdit,SetupEditWindow

Dim Rst12 As NewADODB.Recordset

bh1 =VSFlexGrid3.TextMatrix(VSFlexGrid3.Row, 1)

If bh1 <>"" Then

    Rst12.Open "select * from YSPF_JCBHwhere BH='" & bh1 & "'", gConn, adOpenStatic,adLockReadOnly, -1

    VSFlexGrid3.TextMatrix(VSFlexGrid3.Row, 3)= Rst12(2)

End If

查找字元串對于的行

行号= VSFlexGrid1.FindRow(字元串, 1, 1, True, 1)

生成行号

For i = 1 To VSFlexGrid1.Rows - 1

    VSFlexGrid1.TextMatrix(i, 0)= i

Next i

自動調整列寬

VSFlexGrid1.AutoSize 0, 22 '自動調整列寬

表格裡面加多選按鈕

       For r = 1 ToVSFlexGrid1.Rows - 1

            For j = 1 ToVSFlexGrid1.Cols - 1

           VSFlexGrid1.Cell(flexcpChecked, r, j) = flexUnchecked

           'VSFlexGrid1.Cell(flexcpText, r, 1) = "Row " & r

            Next j

        Next r

        VSFlexGrid1.Editable =flexEDKbdMouse

自動增加行

If VSFlexGrid3.TextMatrix(VSFlexGrid3.Rows - 1, 1) <>"" Then

With VSFlexGrid3

    .Rows = .Rows + 1

    For i = 1 To .Rows - 1

            .TextMatrix(i, 0) = i

    Next i

End With

End If

vsFlexGrid是ComponentOne公司的一個ActiveX控件,它與MS的MSHFlexGrid控件在功能上是相容的,即MSHFlexGrid所具備的屬性和方法,它也都具備,隻有少數幾個屬性名稱略有不同,使用MSHFlexGrid編寫的程式,隻需要作較小的調整就可以轉換過來;但相比MSHFlexGrid,vsFlexGrid多了很多功能,它的屬性和事件非常豐富,可以實作非常靈活的控制和快捷的編碼,下面主要對一些常用和實用的功能進行介紹:

一、資料批量操作

l  利用Cell屬性批量存取資料

比如要清除一塊區域的文本,或者設定一塊區域的字型,不用循環處理,隻需要一條語句就可以完成,如:

vsFlexGrid.Cell(flexcpText,1,1,5,5) = “” ‘設定(1,1)-(5,5)這塊單元格區域的文本都為空

vsFlexGrid.Cell(flexcpFontBold,1,1,5,5)=True ‘設定(1,1)-(5,5)這塊單元格區域的字型都為粗體

類似還可以設定的有單元格對齊、圖檔、顔色等。

而語句:strText = vsFlexGrid.Cell(flexcpText,1,1,5,5)

傳回一個用vbTab間隔列,vbCr間隔行的字元串,當然也可以反過來指派,這樣該區域内的每個單元格都可以賦不同的值。

l  使用-1對所有行列進行處理

RowHeight(-1)=300 ‘将所有行的高度設定為300Twip,可以類似使用的屬性有:

RowHidden,ColWidth,ColHidden,ColAlignment等

二、大量資料存放

vsFlexGrid可以存放資料的地方有:CellText,CellData,ColData,RowData

除了CellText是String類型外,其他都是Variant類型,也就是說你可以将任意類型的資料存放在表格中,比如日期(Date),類型變量(Type),集合(Collection),數組,記錄集(RecordSet),以及各種對象(Object),這對于關聯資料比較多的程式非常有用。

注意:vsFlexGrid.Cell(flexcpText,1,1)= rsData!Name實際是存放了一個ADO.Field對象,應該使用CStr(rsData!Name)對類型進行明确。

三、編輯特性

vsFlexGrid的單元格是可以編輯的,并且有以下幾種編輯形式:

l  文本框:隻要Editable設定為可編輯,每個單元格預設就是TextBox編輯樣式

l  下拉框:

設定目前單元格的ComboList屬性或者指定列的ColComboList屬性,即可實作VB.ComboBox樣式的單元編輯,而且下拉界面中可以顯示多列,如:

vsFlexGrid.ComboList = _

“|#100*1;張三” & vbTab & “男” & vbTab & “28歲” & _

“|#101;李四” & vbTab & “男” & vbTab & “29歲” & _

“|#102;王五” & vbTab & “男” & vbTab & “30歲”

其中”|”間隔的是各行資料,vbTab間隔的是各列資料;第1個”|”表示下拉框可以輸入,”#”後面的是每行的ItemData,第一個ItemData後面”*1”表示是第1列的資料在選擇後顯示在ComboBox中。

l  複選框:

設定指定列的ColDataType = flexDTBoolean,或者指定目前元單格的CellChecked屬性即可。

l  選擇按鈕:

設定目前單元格的ComboList屬性或者指定列的ColComboList屬性為”…”即可,主要配合CellButtonClick事件使用。

四、界面特性

1)         邊框

除了表格線之外,vsFlexGrid還可以類似Excel一樣,設定單元格式的邊框線條,包括顔色、粗細,有無:

VSFlexGrid.CellBorder Color As OLE_COLOR, Left As Integer, Top As Integer, Right As Integer, Bottom As Integer, Vertical As Integer, Horizontal As Integer

2)         自動行高,列寬

使用AutoSize方法,可以使列寬、或者行高根據單元格的内容進行自适應調整。

其中列寬也可以通過輕按兩下表頭進行自适應調整。

3)         樹形縮進(TreeList)

通過設定表格行的IsSubtotal、RowOutlineLevel屬性,可以實作樹形風格的縮進層次樣式,這樣vsFlexGrid就可以實作TreeView和ListView的結合。

4)         自繪

通過設定OwnerDraw屬性,可對實作對單元格内容的自繪處理,主要結合DrawCell事件進行:

DrawCell(ByVal hDC As Long, ByVal Row As Long, ByValcol As Long, ByVal left As Long, ByVal top As Long, ByVal right As Long, ByValbottom As Long, done As Boolean)

5)         背景

可以為vsFlexGrid設定背景圖,背景圖相對單元格式内容是透明的,并且可以設定對齊和平鋪屬性。

6)         列排序,行、列拖動

設定vsFlexGrid.ExplorerBar屬性,就可以實作類似Windows的資料總管一樣,點選列頭進行列資料排序,或者用滑鼠拖動改變列、行的順序。

7)         當機行列

除了固定行列頭外,還可以類似Excel一樣,通過vsFlexGrid.FrozenCols/FrozenRows設定當機行列,當機行列在滾動時,和固定行列是一樣的效果,但是光标可以進入到當機行列範圍内的單元格中去。

五、豐富的事件控制:

vsFlexGrid一共有50多個事件,這些事件主要用于編輯和界面控制,在使用過程中,經常可能會發現某個事件特别有用;是以充分利用這些事件,可以很友善地實作很多功能,下面是它支援的事件及對應清單,粗體是較常用的,從定義基本就可以看出它的作用;詳細的事件說明,可以檢視幫助。

l  AfterCollapse(ByValRow As Long, ByVal State As Integer)

l  AfterDataRefresh()

l  AfterEdit(ByVal RowAs Long, ByVal Col As Long)

l  AfterMoveColumn(ByValCol As Long, Position As Long)

l  AfterMoveRow(ByValRow As Long, Position As Long)

l  AfterRowColChange(ByVal OldRow As Long, ByVal OldCol As Long, ByVal NewRow As Long, ByValNewCol As Long)

l  AfterScroll(ByValOldTopRow As Long, ByVal OldLeftCol As Long, ByVal NewTopRow As Long, ByValNewLeftCol As Long)

l  AfterSelChange(ByValOldRowSel As Long, ByVal OldColSel As Long, ByVal NewRowSel As Long, ByValNewColSel As Long)

l  AfterSort(ByValCol As Long, Order As Integer)

l  AfterUserFreeze()

l  AfterUserResize(ByValRow As Long, ByVal Col As Long)

l  BeforeCollapse(ByValRow As Long, ByVal State As Integer, Cancel As Boolean)

l  BeforeDataRefresh(CancelAs Boolean)

l  BeforeEdit(ByValRow As Long, ByVal Col As Long, Cancel As Boolean)

l  BeforeMouseDown(ByValButton As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y AsSingle, Cancel As Boolean)

l  BeforeMoveColumn(ByVal Col As Long, Position As Long)

l  BeforeMoveRow(ByValRow As Long, Position As Long)

l  BeforePageBreak(ByValRow As Long, BreakOK As Boolean)

l  BeforeRowColChange(ByVal OldRow As Long, ByVal OldCol As Long, ByVal NewRow As Long, ByValNewCol As Long, Cancel As Boolean)

l  BeforeScroll(ByValOldTopRow As Long, ByVal OldLeftCol As Long, ByVal NewTopRow As Long, ByValNewLeftCol As Long, Cancel As Boolean)

l  BeforeScrollTip(ByValRow As Long)

l  BeforeSelChange(ByValOldRowSel As Long, ByVal OldColSel As Long, ByVal NewRowSel As Long, ByValNewColSel As Long, Cancel As Boolean)

l  BeforeSort(ByVal ColAs Long, Order As Integer)

l  BeforeUserResize(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)

l  CellButtonClick(ByVal Row As Long, ByVal Col As Long)

l  CellChanged(ByVal RowAs Long, ByVal Col As Long)

l  ChangeEdit()

l  Click()

l  ComboCloseUp(ByValRow As Long, ByVal Col As Long, FinishEdit As Boolean)

l  ComboDropDown(ByValRow As Long, ByVal Col As Long)

l  Compare(ByVal Row1As Long, ByVal Row2 As Long, Cmp As Integer)

l  DblClick()

l  DragDrop(Source AsControl, X As Single, Y As Single)

l  DragOver(Source AsControl, X As Single, Y As Single, State As Integer)

l  DrawCell(ByVal hDCAs Long, ByVal Row As Long, ByVal Col As Long, ByVal Left As Long, ByVal Top AsLong, ByVal Right As Long, ByVal Bottom As Long, Done As Boolean)

l  EndAutoSearch()

l  EnterCell()

l  Error(ByValErrorCode As Long, ShowMsgBox As Boolean)

l  FilterData(ByValRow As Long, ByVal Col As Long, Value As String, ByVal SavingToDB As Boolean,WantThisCol As Boolean)

l  GetHeaderRow(ByValRow As Long, HeaderRow As Long)

l  GotFocus()

l  KeyDown(KeyCode AsInteger, Shift As Integer)

l  KeyDownEdit(ByValRow As Long, ByVal Col As Long, KeyCode As Integer, ByVal Shift As Integer)

l  KeyPress(KeyAsciiAs Integer)

l  KeyPressEdit(ByVal RowAs Long, ByVal Col As Long, KeyAscii As Integer)

l  KeyUp(KeyCode AsInteger, Shift As Integer)

l  KeyUpEdit(ByValRow As Long, ByVal Col As Long, KeyCode As Integer, ByVal Shift As Integer)

l  LeaveCell()

l  LostFocus()

l  MouseDown(ButtonAs Integer, Shift As Integer, X As Single, Y As Single)

l  MouseMove(ButtonAs Integer, Shift As Integer, X As Single, Y As Single)

l  MouseUp(Button AsInteger, Shift As Integer, X As Single, Y As Single)

l  OLECompleteDrag(EffectAs Long)

l  OLEDragDrop(DataAs VSFlex8Ctl.VSDataObject, Effect As Long, ByVal Button As Integer, ByValShift As Integer, ByVal X As Single, ByVal Y As Single)

l  OLEDragOver(DataAs VSFlex8Ctl.VSDataObject, Effect As Long, ByVal Button As Integer, ByValShift As Integer, ByVal X As Single, ByVal Y As Single, State As Integer)

l  OLEGiveFeedback(EffectAs Long, DefaultCursors As Boolean)

l  OLESetCustomDataObject(CustomDataObjectAs Variant)

l  OLESetData(Data AsVSFlex8Ctl.VSDataObject, DataFormat As Integer)

l  OLEStartDrag(DataAs VSFlex8Ctl.VSDataObject, AllowedEffects As Long)

l  RowColChange()

l  SelChange()

l  SetupEditStyle(ByValRow As Long, ByVal Col As Long, ByVal IsCombo As Boolean, Style As Long,StyleEx As Long)

l  SetupEditWindow(ByValRow As Long, ByVal Col As Long, ByVal EditWindow As Long, ByVal IsCombo AsBoolean)

l  StartAutoSearch()

l  StartEdit(ByVal RowAs Long, ByVal Col As Long, Cancel As Boolean)

l  StartPage(ByValhDC As Long, ByVal Page As Long, Cancel As Boolean)

l  Validate(Cancel AsBoolean)

l  ValidateEdit(ByVal RowAs Long, ByVal Col As Long, Cancel As Boolean)

六、附加功能:

1)         屬性頁:

在vsFlexGrid的屬性頁中,可以對表格進行格式和内容設計,這樣可以省去一些代碼(這部分屬性頁處理的内容儲存在窗體的frx檔案中)。

2)         導入/導出:

通過LoadGrid/SaveGrid方法,可以對表格内容進行導入導出;導入導出的格式有幾種:

l  它自已的二進制格式。

l  帶一定分隔符的文本檔案。

l  Excel97格式(不需要安裝 Excel,速度很快,但有一些屬性不支援)。

3)         列印

通過PrintGrid方法,可以将vsFlexGrid按照目前的格式和資料進行列印輸出,但這個功能比較簡單,比如不能進行預覽,設定頁眉頁腳等。(ComponentOne的另一套控件vsView與vsFlexGrid配合可以實作強大的列印相關功能)

作為一個隻有600多K大小的控件(vsFlexGrid.ocx),功能這麼強大确實非常不錯,在ZLHIS中也進行了大量的使用,上面隻是簡略列舉了它的部分功能,更詳細的功能可以運作它的Demo進行展示,也可以檢視它的幫助檔案,都比較詳盡

vsFlexGrid+VSprinter列印

'''''''''''''''''''''''''''''''''----------------------------------------測試列印機支援紙張

'

'    For p = 1 To 256

'

'      If VSPrinter1.PaperSizes(p)Then Debug.Print " paper size "; p; " is available"

'    Next p

'''''''''''''''''''''''''''''''''----------------------------------------讀ini檔案裡面的列印機

Dim lng As Long

Dim dyj As String

dyj = Space$(1000)

lng = GetPrivateProfileString("列印機", "列印機名稱","", dyj, 1000, App.Path & "\dy.ini")

dyj = Replace(dyj, Chr(0), "")

dyj = Trim(dyj)

If bblx = "入庫明細表" Then

SqlDef = "select DH,GYS,JDR,RQ,BZ from YSPF_ZC_PLRKD whereDH='" & rkdydh & "'"

Rst1.Open SqlDef, gConn, adOpenStatic, adLockReadOnly, -1 '進入資料庫查詢,并把查詢結果指派給rst記錄對象

SqlDef1 = "select BH AS 編号,MC AS 名稱,KH AS 款号,GG AS 規格,JS AS 件數,ZL AS 重量g,DJLX AS 類型," & _

     "DJ AS 單價,JE AS 金額,GFLX AS 類型,GF AS 工費,GFJE AS 工費金額,ZJE AS 總金額,DJ AS 單價,BZ AS 備注 fromYSPF_ZC_PLRKDMX where DH='" & rkdydh & "'"

Rst2.Open SqlDef1, gConn, adOpenStatic, adLockReadOnly, -1 '進入資料庫查詢,并把查詢結果指派給rst記錄對象

With VSFlexGrid_dy

    .Row = 0         '活動單元格的列數

    .Col = 0: .Text = "格式":.CellAlignment = 4 '給每列标題指派,并居中對齊

    .SubtotalPosition = flexSTBelow'合計調整到最後一行

    .AllowUserResizing =flexResizeColumns '設定可以手動調整列寬

    Set .DataSource = Rst2

    For i = 1 To .Rows - 1 '添加行号

        .TextMatrix(i, 0) = i

    Next i

    .Subtotal flexSTSum, -1, 5,"0.00", , RGB(0, 0, 255), False, "%s合計:"

    .Subtotal flexSTSum, -1, 6,"0.00", , RGB(0, 0, 255), False

    .Subtotal flexSTSum, -1, 9,"0.00", , RGB(0, 0, 255), False

    .Subtotal flexSTSum, -1, 12,"0.00", , RGB(0, 0, 255), False

    .Subtotal flexSTSum, -1, 13,"0.00", , RGB(0, 0, 255), False

    .AutoSize 0, 15

End With

'讀取配置檔案資訊

If GetPrivateProfileInt("列印入庫單", "序号",Check_dy1, App.Path & "\dy.ini") = 0 ThenVSFlexGrid_dy.ColHidden(0) = True  '隐藏

If GetPrivateProfileInt("列印入庫單", "編号",Check_dy2, App.Path & "\dy.ini") = 0 Then VSFlexGrid_dy.ColHidden(1)= True  '隐藏

If GetPrivateProfileInt("列印入庫單", "名稱",Check_dy3, App.Path & "\dy.ini") = 0 ThenVSFlexGrid_dy.ColHidden(2) = True '隐藏

If GetPrivateProfileInt("列印入庫單", "款号",Check_dy4, App.Path & "\dy.ini") = 0 ThenVSFlexGrid_dy.ColHidden(3) = True '隐藏

If GetPrivateProfileInt("列印入庫單", "規格",Check_dy5, App.Path & "\dy.ini") = 0 ThenVSFlexGrid_dy.ColHidden(4) = True '隐藏

If GetPrivateProfileInt("列印入庫單", "件數",Check_dy6, App.Path & "\dy.ini") = 0 ThenVSFlexGrid_dy.ColHidden(5) = True '隐藏

If GetPrivateProfileInt("列印入庫單", "重量g",Check_dy7, App.Path & "\dy.ini") = 0 ThenVSFlexGrid_dy.ColHidden(6) = True '隐藏

If GetPrivateProfileInt("列印入庫單", "單價類型",Check_dy8, App.Path & "\dy.ini") = 0 ThenVSFlexGrid_dy.ColHidden(7) = True '隐藏

If GetPrivateProfileInt("列印入庫單", "單價",Check_dy9, App.Path & "\dy.ini") = 0 ThenVSFlexGrid_dy.ColHidden(8) = True '隐藏

If GetPrivateProfileInt("列印入庫單", "金額",Check_dy10, App.Path & "\dy.ini") = 0 ThenVSFlexGrid_dy.ColHidden(9) = True '隐藏

If GetPrivateProfileInt("列印入庫單", "工費類型", Check_dy11,App.Path & "\dy.ini") = 0 Then VSFlexGrid_dy.ColHidden(10) = True'隐藏

If GetPrivateProfileInt("列印入庫單", "工費",Check_dy12, App.Path & "\dy.ini") = 0 ThenVSFlexGrid_dy.ColHidden(11) = True '隐藏

If GetPrivateProfileInt("列印入庫單", "工費金額",Check_dy13, App.Path & "\dy.ini") = 0 ThenVSFlexGrid_dy.ColHidden(12) = True '隐藏

If GetPrivateProfileInt("列印入庫單", "總金額",Check_dy14, App.Path & "\dy.ini") = 0 ThenVSFlexGrid_dy.ColHidden(13) = True '隐藏

If GetPrivateProfileInt("列印入庫單", "售價",Check_dy15, App.Path & "\dy.ini") = 0 ThenVSFlexGrid_dy.ColHidden(14) = True '隐藏

If GetPrivateProfileInt("列印入庫單", "備注",Check_dy16, App.Path & "\dy.ini") = 0 ThenVSFlexGrid_dy.ColHidden(15) = True '隐藏

    With VSPrinter1

        .ZOrder 0

        .Device = dyj '選擇列印機

         .PaperSize = 256

         .Orientation =orPortrait

        .PaperWidth = 24.1 * 567

        .PaperHeight = 5 * 567

        '.Orientation =orLandscape '配置橫向列印4010

        '.TableBorder = tbAll

        '配置頁面四邊的邊距

        .MarginTop = 2200

        .MarginBottom = 500

        .MarginLeft = 500

        .MarginRight = 500

        .StartDoc

        .TextAlign =taCenterMiddle

       .RenderControl =Form_print.VSFlexGrid_dy.hWnd

        .EndDoc

        For i = 1 To .PageCount

            .StartOverlay i

            .TextAlign =taCenterMiddle

            .FontName = "黑體"

            .FontSize = 20

            .CurrentY =.MarginTop - 1800

            .Text = "PH7銀飾批發"

            .StartOverlay i

            .TextAlign =taCenterMiddle

            .FontName = "黑體"

            .FontSize = 16

            .CurrentY =.MarginTop - 1400

            .Text = bblx

            .CurrentX = 500

            .CurrentY =.MarginTop - 900

            .TextAlign =taLeftTop

            .FontName = "宋體"

            .FontSize = 12

            .Text = "入庫單号:" &rkdydh

            .CurrentX = 5000

            .CurrentY =.MarginTop - 600

            .TextAlign =taLeftTop

            .FontName = "宋體"

            .FontSize = 12

            .Text = "建 單 人:" &Rst1("JDR")

            .CurrentX = 500

            .CurrentY =.MarginTop - 600

            .TextAlign =taLeftTop

            .FontName = "宋體"

            .FontSize = 12

            .Text = "供 應 商:" &Rst1("GYS")

            .CurrentX = 5000

            .CurrentY =.MarginTop - 900

            .TextAlign =taLeftTop

            .FontName = "宋體"

            .FontSize = 12

            .Text = "入庫日期:" &Rst1("RQ")

            .CurrentX = 9000

            .CurrentY = .MarginTop - 600

            .TextAlign =taLeftTop

            .FontName = "宋體"

            .FontSize = 12

            .Text = "打 印 人:" &Sys_Ccy

            .CurrentX = 9000

            .CurrentY =.MarginTop - 900

            .TextAlign =taLeftTop

            .FontName = "宋體"

            .FontSize = 12

            .Text = "列印日期:" &Format(Date, "yyyy年mm月dd日")

            .CurrentX = 500

            .CurrentY =.MarginTop - 300

            .TextAlign =taLeftTop

            .FontName = "宋體"

            .FontSize = 12

            .Text = "備    注:" &Rst1("BZ")

            .FontSize = 10

            .FontName = "宋體"

            .CurrentX = 10000

            .CurrentY =.MarginTop - 1300

            .TextAlign =taLeftTop ' taRightTop

            .Text = "第" & i& "頁 共" & .PageCount& "頁"

'            .CurrentX = 1600

'            .CurrentY =.PageHeight - .MarginBottom + 50

'            .FontName = "宋體"

'            .FontSize = 10

'            .TextAlign =taLeftBottom

'            .Text = "頁腳1"

'

'            .FontSize = 10

'            .FontName = "宋體"

'            .TextAlign =taRightBottom

'            .Text = "頁腳2"

'            .FontSize = 10

'            .FontName = "宋體"

'            .TextAlign =taRightBottom

'            .Text = "列印日期:" &Format(Date, "yyyy年mm月dd日")

            .EndOverlay

        Next i

    End With

End If

寫INI配置檔案

'讀取INI檔案API

Declare Function GetPrivateProfileString Lib"kernel32" Alias "GetPrivateProfileStringA" (ByVallpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String,ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName AsString) As Long

Declare Function WritePrivateProfileStringLib "kernel32" Alias "WritePrivateProfileStringA" (ByVallpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any,ByVal lpFileName As String) As Long

Declare Function GetPrivateProfileInt Lib"kernel32" Alias "GetPrivateProfileIntA" ( _

   ByVal lpApplicationName As String, _

   ByVal lpKeyName As String, _

   ByVal nDefault As Long, _

ByVallpFileName As String) As Long

Dim A As Long

'寫資訊

'修改dy.ini檔案中各字段中關鍵字的值

'如果該檔案不存在會自動建立,當函數傳回值為0時說明修改不成功

A = WritePrivateProfileString("列印入庫單","序号", str$(Check_dy1.Value), App.Path & "\dy.ini")

A =WritePrivateProfileString("列印入庫單", "編号", str$(Check_dy2.Value), App.Path & "\dy.ini")

A =WritePrivateProfileString("列印入庫單", "名稱", str$(Check_dy3.Value), App.Path & "\dy.ini")

A =WritePrivateProfileString("列印入庫單", "款号", str$(Check_dy4.Value), App.Path & "\dy.ini")

A =WritePrivateProfileString("列印入庫單", "規格", str$(Check_dy5.Value), App.Path & "\dy.ini")

A =WritePrivateProfileString("列印入庫單", "件數", str$(Check_dy6.Value), App.Path & "\dy.ini")

A =WritePrivateProfileString("列印入庫單", "重量g", str$(Check_dy7.Value), App.Path & "\dy.ini")

A =WritePrivateProfileString("列印入庫單", "單價類型", str$(Check_dy8.Value), App.Path & "\dy.ini")

A =WritePrivateProfileString("列印入庫單", "單價", str$(Check_dy9.Value), App.Path & "\dy.ini")

A =WritePrivateProfileString("列印入庫單", "金額", str$(Check_dy10.Value), App.Path & "\dy.ini")

A =WritePrivateProfileString("列印入庫單", "工費類型", str$(Check_dy11.Value), App.Path & "\dy.ini")

A =WritePrivateProfileString("列印入庫單", "工費", str$(Check_dy12.Value), App.Path & "\dy.ini")

A =WritePrivateProfileString("列印入庫單", "工費金額", str$(Check_dy13.Value), App.Path & "\dy.ini")

A =WritePrivateProfileString("列印入庫單", "總金額", str$(Check_dy14.Value), App.Path & "\dy.ini")

A = WritePrivateProfileString("列印入庫單","售價", str$(Check_dy15.Value), App.Path & "\dy.ini")

A =WritePrivateProfileString("列印入庫單", "備注", str$(Check_dy16.Value), App.Path & "\dy.ini")

If A = 0 ThenMsgBox ("寫檔案時出錯")

Frame5.Visible= False

Call Form_Load

'讀取INI資訊

Check_dy1 =GetPrivateProfileInt("列印入庫單", "序号", Check_dy1, App.Path & "\dy.ini")

Check_dy2 =GetPrivateProfileInt("列印入庫單", "編号", Check_dy2, App.Path & "\dy.ini")

Check_dy3 =GetPrivateProfileInt("列印入庫單", "名稱", Check_dy3, App.Path & "\dy.ini")

Check_dy4 = GetPrivateProfileInt("列印入庫單","款号", Check_dy4, App.Path & "\dy.ini")

Check_dy5 =GetPrivateProfileInt("列印入庫單", "規格", Check_dy5, App.Path & "\dy.ini")

Check_dy6 =GetPrivateProfileInt("列印入庫單", "件數", Check_dy6, App.Path & "\dy.ini")

Check_dy7 =GetPrivateProfileInt("列印入庫單", "重量g", Check_dy7, App.Path & "\dy.ini")

Check_dy8 =GetPrivateProfileInt("列印入庫單", "單價類型", Check_dy8, App.Path & "\dy.ini")

Check_dy9 =GetPrivateProfileInt("列印入庫單", "單價", Check_dy9, App.Path & "\dy.ini")

Check_dy10 =GetPrivateProfileInt("列印入庫單", "金額", Check_dy10, App.Path & "\dy.ini")

Check_dy11 =GetPrivateProfileInt("列印入庫單", "工費類型", Check_dy11, App.Path & "\dy.ini")

Check_dy12 =GetPrivateProfileInt("列印入庫單", "工費", Check_dy12, App.Path & "\dy.ini")

Check_dy13 =GetPrivateProfileInt("列印入庫單", "工費金額", Check_dy13, App.Path & "\dy.ini")

Check_dy14 =GetPrivateProfileInt("列印入庫單", "總金額", Check_dy14, App.Path & "\dy.ini")

Check_dy15 =GetPrivateProfileInt("列印入庫單", "售價", Check_dy15, App.Path & "\dy.ini")

Check_dy16 =GetPrivateProfileInt("列印入庫單", "備注", Check_dy16, App.Path & "\dy.ini")

Frame5.Visible= True

儲存列印機到ini

Private Sub Command3_Click()

'清空組合清單框

   Combo_dyj.Clear

    '擷取列印機。如果系統安裝了列印機則添加到組合清單框中

   Dim p As Printer

   For Each p In Printers

       Combo_dyj.AddItem p.DeviceName

   Next

    '如果組合清單框中有列印機資訊,顯示第一項

   If Combo_dyj.ListCount > 0 Then

       Combo_dyj.ListIndex = 0

    '否則提示:系統未安裝列印機

   Else

       MsgBox "本計算機上未安裝列印機”"

   End If

Frame1.Visible = True

End Sub

Private Sub Command5_Click()

Dim A As Long

'寫資訊

'修改dy.ini檔案中各字段中關鍵字的值

'如果該檔案不存在會自動建立,當函數傳回值為0時說明修改不成功

A = WritePrivateProfileString("列印機","列印機名稱", Combo_dyj.Text, App.Path & "\dy.ini")

   If A = 0 Then MsgBox ("寫檔案時出錯")

MsgBox "列印機儲存成功!!",vbInformation, "提示資訊"

Frame1.Visible = False

Call Form_Load

End Sub

'''''''''''''''''''''''''''''''''----------------------------------------讀ini檔案裡面的列印機

Dim lng As Long

Dim dyj As String

dyj = Space$(1000)

lng = GetPrivateProfileString("列印機", "列印機名稱","", dyj, 1000, App.Path & "\dy.ini")

dyj = Replace(dyj, Chr(0), "")

dyj = Trim(dyj)