高手救命,遇到了读写文件的困难,帮我解决了要什么都可以

f1c2h31 2002-06-25 10:28:22
救急,遇到了写文件的困难,帮我解决了给你打电话致谢并且今后来长沙免费招待一次


我有一个100个元素的数组,已经输入数值
比如为:a(i)=(1,2,3,4,5,6……100)
现在要输出到一个abc.txt文本文件中去,在文本文件中要排列成一下矩阵(10×91)形式:

1 2 3 4 5……91
2 3 4 5 6……92
3 4 5 6 7……93
……
……
10 11 12 13 14……100

其中第二行的第一个数据从数组的第二个元素开始取起
第三行的第一个数从数组的第三个元素取起,依次类推

如果帮我解决了,贴出代码的话,给分给什么都好说
...全文
11 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
jlt2000 2002-06-26
2.0版的,呵呵!直接粘贴!

Sub Main()
Dim iNum(1 To 100) As Integer
Dim strS As String
For n = 1 To 100
iNum(n) = n
Next
Open "D:\abc.txt" For Output As #1
Write #1, NumToFile(iNum)
Close #1
End Sub
Function NumToFile(iNum() As Integer) As String
Dim strOut As String
Dim m As Integer
Dim n As Integer

For m = 1 To 10
For n = m To m + 90
strOut = strOut & vbTab & CStr(iNum(n))
Next
strOut = strOut & vbCrLf
Next
NumToFile = strOut
End Function
回复
jlt2000 2002-06-25
Open "D:\abc.txt" For OutPut As #1
Write #1,NumToFile(你的数组名())
Close #1

Function NumToFile(iNum() As Integer)As String
Dim strOut As String
Dim m as Integer
Dim n as Integer

For m=1 to 10
For n=n to n+90
strOut=strOut & vbTab & iNum(m)
Next
If m<10 then strOut=strt & vbCrLf
Next
End Function
回复
footballboy 2002-06-25
呵呵,刚才回答过这个问题,不介意我再答一次吧
Private Sub Command1_Click()
Dim a(99) As Long
Dim i As Long, j As Long
Dim str As String

For i = 0 To 99
a(i) = Int(99 * Rnd(i))
Next

For i = 0 To 9
For j = i To i + 89
str = str & a(j) & " "
Next
If i <> 9 Then
str = str & a(i + 90) & vbCrLf
Else
str = str & a(i + 90)
End If
Next

Dim filenum As Long
filenum = FreeFile

Open "c:\abc.txt" For Output As #filenum
Print #filenum, str
Close #filenum
End Sub
回复
IsMe 2002-06-25
private function getFmtString(aNum()as integer)as string
dim strT as string
dim I as integer
dim J as integer

strt=""
for i=1 to 10
for j=i to i+90
strt=strt & vbtab & aNum(j)
next j
if i<10 then
strt=strt & vbcrlf
end if
getfmtstring=mid(strt,2)
end function
使用上面函数,生成的字符串包含了要求的内容,然后将该字符串写入文件即可
回复
发帖
VB基础类
创建于2007-09-28

7478

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2002-06-25 10:28
社区公告
暂无公告