?? 數據文件_編輯f2.frm
字號:
VERSION 5.00
Begin VB.Form frmText
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "使用文本框數組顯示和編輯,適用于少量數據"
ClientHeight = 8505
ClientLeft = 60
ClientTop = 345
ClientWidth = 12930
LinkTopic = "Form1"
ScaleHeight = 8505
ScaleWidth = 12930
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton cmdExit
Caption = "退出"
Height = 375
Left = 1680
TabIndex = 5
ToolTipText = "結束程序運行"
Top = 0
Width = 855
End
Begin VB.CommandButton cmdPrint
Caption = "打印"
Height = 375
Left = 840
TabIndex = 4
ToolTipText = "打印機打印數據"
Top = 0
Width = 855
End
Begin VB.TextBox txtEdit
Alignment = 2 'Center
Appearance = 0 'Flat
Height = 270
Index = 0
Left = 840
TabIndex = 3
Top = 600
Width = 855
End
Begin VB.CommandButton cmdSave
Caption = "保存"
Height = 375
Left = 0
TabIndex = 0
ToolTipText = "將編輯后的數據保存到數據文件"
Top = 0
Width = 855
End
Begin VB.Label lblRow
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
BorderStyle = 1 'Fixed Single
ForeColor = &H80000008&
Height = 255
Index = 0
Left = 0
TabIndex = 2
Top = 600
Width = 855
End
Begin VB.Label lblCol
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
BorderStyle = 1 'Fixed Single
ForeColor = &H80000008&
Height = 255
Index = 0
Left = 840
TabIndex = 1
Top = 360
Width = 855
End
End
Attribute VB_Name = "frmText"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'少量數據的顯示和編輯
'在屬性窗口設置txtEdit、lblRow、lblCol的Index屬性為0,形成控件數組
Option Explicit
Dim sngtxtHig As Single, sngtxtWid As Single
Dim snglblHig As Single, snglblWid As Single
Dim intI As Integer, intJ As Integer
Private Sub Form_Load()
Dim vntA As Variant
'使設計時安置在窗體的原型控件不可見
txtEdit(0).Visible = False
lblRow(0).Visible = False
lblCol(0).Visible = False
'利用原型控件的坐標參數
sngtxtHig = txtEdit(0).Height
sngtxtWid = txtEdit(0).Width
snglblHig = sngtxtHig
snglblWid = sngtxtWid
intFileNumber = FreeFile '取得文件號碼
Open strFileName For Input As intFileNumber '打開文件
'形成文本框數組
For intI = 1 To intRowAll
For intJ = 1 To intCol
Input #intFileNumber, vntA
Load txtEdit((intI - 1) * intCol + intJ)
txtEdit((intI - 1) * intCol + intJ).Move _
txtEdit(0).Left + (intJ - 1) * sngtxtWid, _
txtEdit(0).Top + (intI - 1) * sngtxtHig
txtEdit((intI - 1) * intCol + intJ).Visible = True
txtEdit((intI - 1) * intCol + intJ).Text = vntA
Next intJ
Next intI
'形成上部的標簽
For intI = 1 To intCol
Input #intFileNumber, vntA
Load lblCol(intI)
lblCol(intI).Move lblCol(0).Left + (intI - 1) * snglblWid, _
lblCol(0).Top
lblCol(intI).Visible = True
lblCol(intI).Caption = vntA
Next intI
'形成左邊的標簽
For intI = 1 To intRowAll
Input #intFileNumber, vntA
Load lblRow(intI)
lblRow(intI).Move lblRow(0).Left, _
lblRow(0).Top + (intI - 1) * snglblHig
lblRow(intI).Visible = True
lblRow(intI).Caption = vntA
Next intI
Close
End Sub
'打印機打印
Private Sub cmdPrint_Click()
Dim intI1 As Integer, intI2 As Integer
On Error Resume Next
intI1 = 1: intI2 = 8
If intCol <= 8 Then intI2 = intCol
Printer.Print
AA1:
Printer.Print ,
For intI = intI1 To intI2
Printer.Print lblCol(intI).Caption, '打印列標記
Next intI
For intI = 1 To intRowAll
Printer.Print
Printer.Print lblRow(intI), '打印行標記
For intJ = intI1 To intI2
'打印數據
Printer.Print txtEdit((intI - 1) * intCol + intJ).Text,
Next intJ
Next intI
If intCol > 8 And intI2 <= 8 Then
'如果超過8列將分兩批打印
intI1 = intI1 + 8
intI2 = intCol
Printer.Print
Printer.Print
GoTo AA1 '打印其余的列
End If
Printer.EndDoc '執行打印
End Sub
'形成數組并保存為數據文件
Private Sub cmdSave_Click()
Dim intFileNumber As Integer
Dim vntA As Variant
MsgBox "現在存盤,請耐心等待!"
intFileNumber = FreeFile '取得空閑的文件號
Open strFileName For Output As intFileNumber '打開文件
'保存數據
For intI = 1 To intRowAll
For intJ = 1 To intCol
Write #intFileNumber, txtEdit((intI - 1) * intCol + intJ);
Next intJ
Next intI
'保存上部標簽
For intI = 1 To intCol
Write #intFileNumber, lblCol(intI).Caption;
Next intI
'保存左邊標簽
For intI = 1 To intRowAll
Write #intFileNumber, lblRow(intI).Caption;
Next intI
Close '關閉文件
MsgBox "存盤完成,請繼續進行!"
End Sub
'退出
Private Sub cmdExit_Click()
Unload Me
End
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -