⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 数据文件f4(窗体模块frmgrid).frm

📁 这个程序
💻 FRM
字号:
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form frmGrid 
   Appearance      =   0  'Flat
   BackColor       =   &H80000005&
   BorderStyle     =   0  'None
   Caption         =   "使用网格录入或编辑"
   ClientHeight    =   8775
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   12720
   LinkTopic       =   "Form1"
   ScaleHeight     =   8775
   ScaleWidth      =   12720
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  '窗口缺省
   Begin VB.TextBox txtWrite 
      Appearance      =   0  'Flat
      Height          =   270
      Left            =   2640
      TabIndex        =   5
      Top             =   2280
      Width           =   1095
   End
   Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
      Height          =   8175
      Left            =   0
      TabIndex        =   0
      TabStop         =   0   'False
      Top             =   480
      Width           =   12615
      _ExtentX        =   22251
      _ExtentY        =   14420
      _Version        =   393216
      BackColorFixed  =   -2147483639
      BackColorBkg    =   16777215
      AllowUserResizing=   1
   End
   Begin VB.CommandButton cmdExit 
      Cancel          =   -1  'True
      Caption         =   "退  出"
      Height          =   375
      Left            =   3480
      TabIndex        =   3
      TabStop         =   0   'False
      ToolTipText     =   "结束程序运行"
      Top             =   0
      Width           =   975
   End
   Begin VB.CommandButton cmdPrint 
      Caption         =   "打  印"
      Height          =   375
      Left            =   2520
      TabIndex        =   2
      TabStop         =   0   'False
      ToolTipText     =   "打印机打印录入数据"
      Top             =   0
      Width           =   975
   End
   Begin VB.CommandButton cmdSave 
      Caption         =   "保  存"
      Height          =   375
      Left            =   1560
      TabIndex        =   1
      TabStop         =   0   'False
      ToolTipText     =   "将录入数据保存到数据文件"
      Top             =   0
      Width           =   975
   End
   Begin VB.Label lblRowCol 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000005&
      Caption         =   "lblRowCol"
      ForeColor       =   &H80000008&
      Height          =   180
      Left            =   360
      TabIndex        =   4
      Top             =   240
      Width           =   825
   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 strA As String

Private Sub Form_Load()
    On Error Resume Next
    intCol = 2 * intCol
    Me.Top = 0: Me.Left = 0
    MSFlexGrid1.Rows = intRow + 1                   '网格的行数
    MSFlexGrid1.Cols = intCol + 1                   '网格的列数
    lblRowCol.Caption = "第1行:初值"
'将编辑用的文本框放入被单击的单元格
    txtWrite.Move MSFlexGrid1.CellLeft + MSFlexGrid1.Left, _
        MSFlexGrid1.CellTop + MSFlexGrid1.Top, MSFlexGrid1.CellWidth, _
        MSFlexGrid1.CellHeight
    If intEdit = 1 Then                             '编辑
'读数据
        For intI = 1 To intRow
            MSFlexGrid1.Row = intI
            For intJ = 1 To intCol
                Input #intFileNumber, strA
                MSFlexGrid1.Col = intJ
                MSFlexGrid1.Text = strA
            Next intJ
        Next intI
'读上部标签
        MSFlexGrid1.Row = 0
        For intI = 1 To intCol
            Input #intFileNumber, strA
            MSFlexGrid1.Col = intI
            MSFlexGrid1.Text = strA
        Next intI
'读左边标签
        MSFlexGrid1.Col = 0
        For intI = 1 To intRow
            Input #intFileNumber, strA
            MSFlexGrid1.Row = intI
            MSFlexGrid1.Text = strA
        Next intI
        Close #intFileNumber                        '关闭文件
    Else                                            '新建
'建立说明列
        For intI = 1 To MSFlexGrid1.Cols - 1
            MSFlexGrid1.Row = 0                     '说明列在第0行
            MSFlexGrid1.Col = intI                  '设定当前列
            If (intI \ 2) * 2 = intI Then
                MSFlexGrid1.Text = "终值"
            Else
                MSFlexGrid1.Text = "初值"
            End If
        Next intI
'建立说明行
        For intI = 1 To MSFlexGrid1.Rows - 1
            MSFlexGrid1.Col = 0                     '说明行在第0列
            MSFlexGrid1.Row = intI                  '设定当前行
            MSFlexGrid1.Text = intI & "行"
        Next intI
    End If
    MSFlexGrid1.Row = 1
    MSFlexGrid1.Col = 1
End Sub

'用户单击单元格时,将该单元格内容复制到文本框控件
'再单击后,则单元格文本框取得焦点,这时可以进行编辑
Private Sub MSFlexGrid1_EnterCell()
'将当前说明列和当前说明行赋予标签
    lblRowCol.Caption = MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 0) & ":" _
        & MSFlexGrid1.TextMatrix(0, MSFlexGrid1.Col)
'将当前单元格内容赋予文本框
    txtWrite.Text = MSFlexGrid1.Text
'将录入用的文本框放入被单击的单元格
    txtWrite.Move MSFlexGrid1.CellLeft + MSFlexGrid1.Left, _
        MSFlexGrid1.CellTop + MSFlexGrid1.Top, MSFlexGrid1.CellWidth, _
        MSFlexGrid1.CellHeight
End Sub

'文本框数据处理,按Enter键或Tab键结束一个网格数据的录入
Private Sub txtWrite_KeyPress(KeyAscii As Integer)
    Dim intR As Integer, intC As Integer
    If KeyAscii = 13 Or KeyAscii = 9 Then   '13为Enter键,9为Tab键
        MSFlexGrid1.Text = txtWrite.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           '为单元格设置的当前列
        txtWrite.Text = MSFlexGrid1.Text    '单元格数据赋予文本框
'将录入用的文本框放入下一个单元格
    txtWrite.Move MSFlexGrid1.CellLeft + MSFlexGrid1.Left, _
        MSFlexGrid1.CellTop + MSFlexGrid1.Top, MSFlexGrid1.CellWidth, _
        MSFlexGrid1.CellHeight
    txtWrite.SetFocus                       '文本框取得焦点
    End If
End Sub

'保存
Private Sub cmdSave_Click()
    Dim intFileNumber As Integer
    On Error Resume Next
    MsgBox "开始保存数据,请耐心等待!"
    intFileNumber = FreeFile                        '取得空闲的文件号
    Open strFileName For Output As intFileNumber    '打开文件
    Write #intFileNumber, intRow; intCol \ 2
    For intI = 1 To intRow
        For intJ = 1 To intCol
'将数组中的数据写到文件上
            strA = MSFlexGrid1.TextMatrix(intI, intJ)
            If intCol <> intJ Then
                Write #intFileNumber, strA;
            Else
                Write #intFileNumber, strA
            End If
        Next intJ
    Next intI
'将列标写入文件
    For intI = 1 To intCol
        strA = MSFlexGrid1.TextMatrix(0, intI)
        If intI <> intCol Then
            Write #intFileNumber, strA;
        Else
            Write #intFileNumber, strA
        End If
    Next intI
'将行标写入文件
    For intI = 1 To intRow
        strA = MSFlexGrid1.TextMatrix(intI, 0)
        If intI <> intRow Then
            Write #intFileNumber, strA;
        Else
            Write #intFileNumber, strA
        End If
    Next intI
    Close                                           '关闭文件
    MsgBox "保存数据完成,请继续进行!"
End Sub

'打印
Private Sub cmdPrint_Click()
    Dim intI1 As Integer, intI2 As Integer
    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 intRow
        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 + -