📄 数据文件_编辑f4.frm
字号:
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form frmGrid
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "使用网格显示和编辑"
ClientHeight = 11115
ClientLeft = 60
ClientTop = 345
ClientWidth = 13290
LinkTopic = "Form1"
ScaleHeight = 11115
ScaleWidth = 13290
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton cmdExit
Caption = "退 出"
Height = 375
Left = 6480
TabIndex = 5
TabStop = 0 'False
ToolTipText = "结束程序运行"
Top = 0
Width = 1335
End
Begin VB.CommandButton cmdPrint
Caption = "打 印"
Height = 375
Left = 5160
TabIndex = 4
TabStop = 0 'False
ToolTipText = "打印机打印数据"
Top = 0
Width = 1335
End
Begin VB.CommandButton cmdSave
Caption = "保 存"
Height = 375
Left = 3840
TabIndex = 3
TabStop = 0 'False
ToolTipText = "将编辑后的数据保存到数据文件"
Top = 0
Width = 1335
End
Begin VB.TextBox Text1
Alignment = 2 'Center
Appearance = 0 'Flat
Height = 375
Left = 2400
TabIndex = 2
Top = 0
Width = 1335
End
Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1
Height = 10000
Left = 0
TabIndex = 0
TabStop = 0 'False
Top = 360
Width = 13215
_ExtentX = 23310
_ExtentY = 17648
_Version = 393216
BackColorFixed = -2147483639
BackColorBkg = 16777215
AllowUserResizing= 3
End
Begin VB.Label Label1
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
ForeColor = &H80000008&
Height = 375
Left = 0
TabIndex = 1
Top = 0
Width = 2415
End
End
Attribute VB_Name = "frmGrid"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'大量数据的显示和编辑
Option Explicit
Dim intI As Integer, intJ As Integer
Dim intStartRow As Integer
Private Sub Form_Load()
Dim vntA As Variant, strA As String
ReDim vntArray(1 To intRowAll, 1 To intCol)
MSFlexGrid1.Rows = intRowAll + 1
MSFlexGrid1.Cols = intCol + 1
'MSFlexGrid1.Cols-1为网格总列数
'MSFlexGrid1.Rows-1为网格总行数
intFileNumber = FreeFile
Open strFileName For Input As intFileNumber
'读数据
For intI = 1 To intRowAll
MSFlexGrid1.Row = intI
For intJ = 1 To intCol
Input #intFileNumber, vntA
MSFlexGrid1.Col = intJ
MSFlexGrid1.Text = vntA
Next intJ
Next intI
'读上部标签
MSFlexGrid1.Row = 0
For intI = 1 To intCol
Input #intFileNumber, vntA
MSFlexGrid1.Col = intI
MSFlexGrid1.Text = vntA
Next intI
'读左边标签
MSFlexGrid1.Col = 0
For intI = 1 To intRowAll
Input #intFileNumber, vntA
MSFlexGrid1.Row = intI
MSFlexGrid1.Text = vntA
Next intI
Close #intFileNumber
MSFlexGrid1.Row = 1
MSFlexGrid1.Col = 1
Label1.Caption = "第1行:第1列"
End Sub
'用户单击单元时,将该单元内容复制到文本框控件
'然后可以进行编辑
Private Sub MSFlexGrid1_EnterCell()
'将当前说明列和当前说明行赋予标签
Label1 = MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 0) & ":" _
& MSFlexGrid1.TextMatrix(0, MSFlexGrid1.Col)
'将当前单元格内容赋予文本框
Text1.Text = MSFlexGrid1.Text
End Sub
'文本框数据处理,按Enter键或Tab键结束一个网格数据的编辑
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim intR As Integer, intC As Integer
If KeyAscii = 13 Or KeyAscii = 9 Then '13为Enter键,9为Tab键
MSFlexGrid1.Text = Text1.Text '文本框数据送入网格
intC = MSFlexGrid1.Col + 1 '焦点移到同行的下一列
intR = MSFlexGrid1.RowSel '单元格返回当前行
If intC = MSFlexGrid1.Cols Then '如果到了最后一列
intC = MSFlexGrid1.FixedRows 'intC=1,FixedRows的缺省设置
'如果intR没有到边界行则取下一行
If intR < MSFlexGrid1.Rows - MSFlexGrid1.FixedRows Then _
intR = intR + 1
End If
MSFlexGrid1.Row = intR '新的当前行
MSFlexGrid1.Col = intC '新的当前列
MSFlexGrid1.ColSel = intC '为单元格设置的当前列
Text1.Text = MSFlexGrid1.Text '单元格数据赋予文本框
Text1.SetFocus '文本框取得焦点
End If
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
MSFlexGrid1.Row = intI
For intJ = 1 To intCol
MSFlexGrid1.Col = intJ
Write #intFileNumber, MSFlexGrid1.Text;
Next intJ
Next intI
'保存上部标签
MSFlexGrid1.Row = 0
For intI = 1 To intCol
MSFlexGrid1.Col = intI
Write #intFileNumber, MSFlexGrid1.Text;
Next intI
'保存左边标签
MSFlexGrid1.Col = 0
For intI = 1 To intRowAll
MSFlexGrid1.Row = intI
Write #intFileNumber, MSFlexGrid1.Text;
Next intI
Close #intFileNumber '关闭文件
MsgBox "存盘结束,请继续进行!"
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
AA1:
Printer.Print ,
For intI = intI1 To intI2
MSFlexGrid1.Row = 0 '设定保存标志列的行(0行)
MSFlexGrid1.Col = intI '设定当前列
Printer.Print MSFlexGrid1.Text, '打印列标志
Next intI
For intI = 1 To intRowAll
Printer.Print
MSFlexGrid1.Col = 0 '设定保存标志行的列(0列)
MSFlexGrid1.Row = intI '设定当前行
Printer.Print MSFlexGrid1.Text, '打印行标志
For intJ = intI1 To intI2 '打印数据
MSFlexGrid1.Col = intJ
Printer.Print MSFlexGrid1.Text,
Next intJ
Next intI
If intI2 < intCol Then
intI1 = intI1 + 8
intI2 = intI2 + 8
If intI2 > intCol Then intI2 = intCol
Printer.Print
Printer.Print
GoTo AA1
End If
Printer.EndDoc '执行打印
End Sub
'退出
Private Sub cmdExit_Click()
Unload Me
End
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -