现在有这样一段代码:
Private Sub SaveAs_Click() ' 文件保存
Dim S As String
Dim a, i As Integer
Dim j As Integer
CommonDialog1.Filter = "数据文件(*.data)|*.data"
CommonDialog1.ShowSave
If CommonDialog1.FileName <> "" Then
If Dir(CommonDialog1.FileName) <> vbNullString Then
If MsgBox("原文件存在,是否覆盖?", vbYesNo, "提示框") = vbYes Then
Kill CommonDialog1.FileName
Else
Exit Sub
End If
End If
Open CommonDialog1.FileName For Output As 1 '保存主窗口中MSHFLEXGRID里面的数据 与 子窗口中的text文件里的数据
For i = 0 To Grid.Rows - 1
For j = 0 To 5
Print #1, Grid.TextMatrix(i, j); IIf(j = Grid.Cols, "", ",");
Next
If i < Grid.Rows - 1 Then Print #1,
Next
End If
Print #1, a, b, c, d, e 'a,b,c,d,e均为全局变量。里面的值是另一个窗体中的text 中的值
Close #1
End Sub上面的代码文件能够成功保存,问题是打开文件代码Private Sub Look_Click() '文件打开操作
Dim j, a, i As Integer
Dim inputdata As String
Dim File, S As String
CommonDialog1.Filter = "数据文件(*.data)|*.data"
CommonDialog1.Action = 1
File = CommonDialog1.FileName
If File = "" Then
MsgBox "没有选择文件!", vbOKOnly, "文件选择"
Text1.SetFocus
Exit Sub
Else
Open CommonDialog1.FileName For Input As 1
Grid.Rows = 0
Line Input #1, S
a = Split(S, ",")
Grid.Cols = UBound(a) + 1
Seek 1, 1
Do While EOF(1) = False
Line Input #1, S
a = Split(S, ",")
Grid.AddItem vbNullString
For j = LBound(a) To UBound(a)
Grid.TextMatrix(i, j) = a(j)
Next
i = i + 1
Loop ’这里MSHFLEXGRID能根据对应的行列打开
End If
End Sub请问我同时保存的另一个窗体的text文件如何打开?代码如何加?谢谢各位大侠
Private Sub SaveAs_Click() ' 文件保存
Dim S As String
Dim a, i As Integer
Dim j As Integer
CommonDialog1.Filter = "数据文件(*.data)|*.data"
CommonDialog1.ShowSave
If CommonDialog1.FileName <> "" Then
If Dir(CommonDialog1.FileName) <> vbNullString Then
If MsgBox("原文件存在,是否覆盖?", vbYesNo, "提示框") = vbYes Then
Kill CommonDialog1.FileName
Else
Exit Sub
End If
End If
Open CommonDialog1.FileName For Output As 1 '保存主窗口中MSHFLEXGRID里面的数据 与 子窗口中的text文件里的数据
For i = 0 To Grid.Rows - 1
For j = 0 To 5
Print #1, Grid.TextMatrix(i, j); IIf(j = Grid.Cols, "", ",");
Next
If i < Grid.Rows - 1 Then Print #1,
Next
End If
Print #1, a, b, c, d, e 'a,b,c,d,e均为全局变量。里面的值是另一个窗体中的text 中的值
Close #1
End Sub上面的代码文件能够成功保存,问题是打开文件代码Private Sub Look_Click() '文件打开操作
Dim j, a, i As Integer
Dim inputdata As String
Dim File, S As String
CommonDialog1.Filter = "数据文件(*.data)|*.data"
CommonDialog1.Action = 1
File = CommonDialog1.FileName
If File = "" Then
MsgBox "没有选择文件!", vbOKOnly, "文件选择"
Text1.SetFocus
Exit Sub
Else
Open CommonDialog1.FileName For Input As 1
Grid.Rows = 0
Line Input #1, S
a = Split(S, ",")
Grid.Cols = UBound(a) + 1
Seek 1, 1
Do While EOF(1) = False
Line Input #1, S
a = Split(S, ",")
Grid.AddItem vbNullString
For j = LBound(a) To UBound(a)
Grid.TextMatrix(i, j) = a(j)
Next
i = i + 1
Loop ’这里MSHFLEXGRID能根据对应的行列打开
End If
End Sub请问我同时保存的另一个窗体的text文件如何打开?代码如何加?谢谢各位大侠
解决方案 »
- 我想把一个TEXT中输入的内容在打印时分成多行打印,如何实现?
- 关于在vb中嵌入excel
- 算法讨论~!
- 火星来的程序员 我又出新问题了
- 放出2001年我用vb写的pop3邮件服务器(包括全部源代码)
- 我碰到一个奇怪的问题:每当我输入inputb的时候,编辑环境总会自动把它改为input,这是怎么回事?我以前用得很好的啊!!
- 兄弟们有没有什么经典的加解密文件算法,我给分150
- 关于VB.NET的WEB应用程序无法调试运行的问题
- 关于winsock不能大量传送的问题。(比较难,请各位大虾不要在乎分数,请教)
- 请问各位高手:api类型MIXERCONTROLDETAILS如何用?????(请回[email protected] 谢谢!!!)
- vb 加载外部程序的显示位置问题
- vb 和VBA怎么样整合开发?
Open CommonDialog1.FileName For Input As 2
不知道是不是你的意思。
谢谢你的回复
不是那样。
我的意思是把主窗体中MSHFLEXGRID控件显示的内容和另外一个子窗体中text中的内容同时保存在一个文件中
然后读取这个文件的时候,能够在主窗体显示MSHflexgrid里的内容,另外一个子窗体中的text也能够对应的显示出来。
现在保存是可以了
就是读取,没法读取保存的子窗体中的text文件,只能读取mshflexgrid 文件
不知道该加一段什么样的代码?
这样读取的时候才能读取。
现在如何读取呢?
定义数组kk(i,j)kk1(i,j)和变量dd,dd1 ,a1,b1,c1,d1用语数据赋值保存文件将kk(i,j)=Grid.TextMatrix(i, j)
Open CommonDialog1.FileName For Output As 1
dd=Grid.Rows - 1
witer #10,dd'将总行数存盘,用于打开定义row 值
for i=1 to dd
for j=1 to 5witer #10,kk(i,j)
next j
next iwiter #1,a
witer #1,b
witer #1,c
witer #1,d
close #1打开文件
Open CommonDialog1.FileName For iutput As 1
input #1,dd1 '调取第一行的 row 存储值
for i=1 to dd1
for j=1 to 5
input #1,kk1(i,j)
next j
next i
input #1,a1
input #1,b1
input #1,c1
input #1,d1
close #1
然后可以将kk1(i,j),a1,b1,c1,d1 去赋给任何控件.