MSHFLEXGRID数据保存问题

beelin2010 2011-11-01 12:20:49
如何将MSHFLEXGRID中的数据保存成TXT格式,保存成TXT格式文件名称以当天日期命名,假如今天保存是:2011-11-1
明天的就是2011-11-2。这样日积月累就形成多个TXT文件,用DTPicker1控件来查询2011-11-1.txt文件到MSHFLEXGRID中,这二个步骤怎么实现,求代码或实倒,谢谢!
...全文
61 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
贝隆 2011-11-01
  • 打赏
  • 举报
回复
建议定义一个自定义类型,参考如下:

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

beelin2010 2011-11-01
  • 打赏
  • 举报
回复
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进行计算公式为:加和乘,怎么用代码实现

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧