当前位置:编程学习 > VB >>

MSHFLEXGRID数据保存问题

如何将MSHFLEXGRID中的数据保存成TXT格式,保存成TXT格式文件名称以当天日期命名,假如今天保存是:2011-11-1
明天的就是2011-11-2。这样日积月累就形成多个TXT文件,用DTPicker1控件来查询2011-11-1.txt文件到MSHFLEXGRID中,这二个步骤怎么实现,求代码或实倒,谢谢! --------------------编程问答-------------------- 建议定义一个自定义类型,参考如下:

Option Explicit
Private Type MSHFlexGridRow
    RowNo As String * 5
    Cell1 As String * 20   '定义为定长字符串或其他类型,这个看你的具体情况而定
    Cell2 As String * 20   '每个列定义一个元素
    Cell3 As String * 20
    Cell4 As String * 20
End Type
Dim RowRecord() As MSHFlexGridRow

Private Sub Command1_Click()
    Dim intRow As Integer
    Dim intFileNo As Integer
    ReDim RowRecord(0 To MSHFlexGrid1.Rows - 1)
    For intRow = 0 To MSHFlexGrid1.Rows - 1
        RowRecord(intRow).RowNo = MSHFlexGrid1.TextMatrix(intRow, 0)
        RowRecord(intRow).Cell1 = MSHFlexGrid1.TextMatrix(intRow, 1)
        RowRecord(intRow).Cell2 = MSHFlexGrid1.TextMatrix(intRow, 2)
        RowRecord(intRow).Cell3 = MSHFlexGrid1.TextMatrix(intRow, 3)
        RowRecord(intRow).Cell4 = MSHFlexGrid1.TextMatrix(intRow, 4)
        
        intFileNo = FreeFile
        Open App.Path & "\1.txt" For Random As intFileNo Len = Len(RowRecord(intRow))
        Put intFileNo, intRow + 1, RowRecord(intRow)
        Close intFileNo
    Next intRow
    
    
End Sub

Private Sub Form_Load()
    Dim intRow As Integer
    Dim intCol As Integer
    Dim strP As String
    With MSHFlexGrid1
        .FixedRows = 1
        .FixedCols = 1
        .Rows = 100
        .Cols = 4
        .FormatString = "^序号|列1|^列2|^列3|^列4"
    End With
    For intRow = 1 To 99
        For intCol = 0 To 4
            Select Case intCol
                Case 0
                    strP = intRow
                Case 1
                    strP = "中"
                Case 2
                    strP = "国"
                Case 3
                    strP = "人"
                Case 4
                    strP = "强"
            End Select
            MSHFlexGrid1.TextMatrix(intRow, intCol) = strP
        Next intCol
    Next intRow
End Sub

--------------------编程问答--------------------   RowRecord(intRow).RowNo = MSHFlexGrid1.TextMatrix(intRow, 0)
        RowRecord(intRow).Cell1 = MSHFlexGrid1.TextMatrix(intRow, 1)
        RowRecord(intRow).Cell2 = MSHFlexGrid1.TextMatrix(intRow, 2)
        RowRecord(intRow).Cell3 = MSHFlexGrid1.TextMatrix(intRow, 3)
        RowRecord(intRow).Cell4 = MSHFlexGrid1.TextMatrix(intRow, 4)
提示缺少对像
还有就是查询 的问题呢,保存的TXT要以当前日期来保存的,
假如我要第二行每5个单元格和每二行,每6 8进行计算公式为:加和乘,怎么用代码实现
补充:VB ,  数据库(包含打印,安装,报表)
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,