取出数据是不是第一条是1,第二条是2,每条一个数据? 如果是这样直接写进txt文件不就可以了么? while not rs.eof 写第一个数据rs.field(0):rs.movenext if not rs.eof 写第二个数据rs.field(0):rs.movenext if not rs.eof 写第三个数据rs.field(0):rs.movenext if not rs.eof 写第四个数据rs.field(0):rs.movenext:txt文件中写入换行符 wend
是的,是每条记录为1个值. 但是现在把记录写入文本文件时,结果不是我想要的.Open "E:\Global_Urban\convert\temp.txt" For Output As #1 For i = 0 To 1 tmpDemData = "" For j = 0 To 3 tmpDemData = CStr(MatA(i, j)) tmpDemData = tmpDemData & "," Print #1, tmpDemData, ; Next j Next i Close #1结果是: 1, 2, 3, 4, 5, 6, 7, 8,现在,前面的数据都可以输出,只是输入到文本文件出现错误. 我想要的结果是: 1 2 3 4 5 6 7 8 数字中间是空格
i = 0 j = 0 Dim tmpDemData As String Open "E:\temp.txt" For Output As #1 For i = 0 To 1 tmpDemData = "" For j = 0 To 2 tmpDemData = CStr(MatA(i, j)) If j < 2 Then tmpDemData = tmpDemData & "" Print #1, tmpDemData, ; ElseIf j = 2 Then Print #1, tmpDemData End If Next j Next i Close #1以上是重新修改的程序,可以输出结果为: 1 2 3 4 5 6但是,每行各数值间有13个空格,这是怎么回事?请教
If j < 2 Then tmpDemData = tmpDemData & "" Print #1, tmpDemData, ; ElseIf j = 2 Then Print #1, tmpDemData End If '************************* 你的这段程序里面,第一个print语句写错了,导致这么多空格,逗号本身的间隔就很大,占多少个空格我不记得了,现在我的这个电脑上没有装VB,你自己试试看,还有分号,也占一定的空格的,如果你把第一句改成这样,应该就没有问题了. Print #1, tmpDemData & " " 其实下面这句是没有用的 tmpDemData = tmpDemData & "" 你的本意是想tmpDemData后面接个空格,但是""不是空格,是空串,如果这样就奏效了" "
Private Sub Command1_Click() Dim i As Integer Dim j As Integer Dim tmpDemData As String Open "c:\temp.txt" For Output As #1 For i = 0 To 7 Step 4 tmpDemData = "" For j = 0 To 3 c = CStr(MatA(i + j)) tmpDemData = tmpDemData & c & " " Next j Print #1, tmpDemData Next i Close #1 End SubFunction MatA(i As Integer) As String Dim arr(7) As Integer arr(0) = 1 arr(1) = 2 arr(2) = 3 arr(3) = 4 arr(4) = 5 arr(5) = 6 arr(6) = 7 arr(7) = 8 MatA = arr(i) End Function
例如:
1 2 3 4 5 6 7 8
放到a(1,3)里,
求中间循环语句?
如果是这样直接写进txt文件不就可以了么?
while not rs.eof
写第一个数据rs.field(0):rs.movenext
if not rs.eof 写第二个数据rs.field(0):rs.movenext
if not rs.eof 写第三个数据rs.field(0):rs.movenext
if not rs.eof 写第四个数据rs.field(0):rs.movenext:txt文件中写入换行符
wend
但是现在把记录写入文本文件时,结果不是我想要的.Open "E:\Global_Urban\convert\temp.txt" For Output As #1 For i = 0 To 1
tmpDemData = ""
For j = 0 To 3
tmpDemData = CStr(MatA(i, j))
tmpDemData = tmpDemData & ","
Print #1, tmpDemData, ;
Next j
Next i
Close #1结果是:
1, 2, 3, 4, 5, 6, 7, 8,现在,前面的数据都可以输出,只是输入到文本文件出现错误.
我想要的结果是:
1 2 3 4
5 6 7 8
数字中间是空格
j = 0
Dim tmpDemData As String
Open "E:\temp.txt" For Output As #1 For i = 0 To 1
tmpDemData = ""
For j = 0 To 2
tmpDemData = CStr(MatA(i, j))
If j < 2 Then
tmpDemData = tmpDemData & ""
Print #1, tmpDemData, ;
ElseIf j = 2 Then
Print #1, tmpDemData
End If
Next j
Next i
Close #1以上是重新修改的程序,可以输出结果为:
1 2 3
4 5 6但是,每行各数值间有13个空格,这是怎么回事?请教
tmpDemData = tmpDemData & ""
Print #1, tmpDemData, ;
ElseIf j = 2 Then
Print #1, tmpDemData
End If
'*************************
你的这段程序里面,第一个print语句写错了,导致这么多空格,逗号本身的间隔就很大,占多少个空格我不记得了,现在我的这个电脑上没有装VB,你自己试试看,还有分号,也占一定的空格的,如果你把第一句改成这样,应该就没有问题了.
Print #1, tmpDemData & " "
其实下面这句是没有用的
tmpDemData = tmpDemData & ""
你的本意是想tmpDemData后面接个空格,但是""不是空格,是空串,如果这样就奏效了" "
Dim i As Integer
Dim j As Integer
Dim tmpDemData As String
Open "c:\temp.txt" For Output As #1
For i = 0 To 7 Step 4
tmpDemData = ""
For j = 0 To 3
c = CStr(MatA(i + j))
tmpDemData = tmpDemData & c & " "
Next j
Print #1, tmpDemData
Next i
Close #1
End SubFunction MatA(i As Integer) As String
Dim arr(7) As Integer
arr(0) = 1
arr(1) = 2
arr(2) = 3
arr(3) = 4
arr(4) = 5
arr(5) = 6
arr(6) = 7
arr(7) = 8
MatA = arr(i)
End Function