📄 数据文件_编辑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 + -