关于二维数组。。。

pangxie887 2010-06-23 06:11:44
假设文件(C:\Data.txt)里面有15个数字,假设分别是1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
要让这15个数字分别写入二维数组里面
例如
1,2,3,4,5
6,7,8,9,10
11,12,13,14,15

这个要怎么写一个sub procedure




...全文
77 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
threenewbee 2010-06-23
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 pangxie887 的回复:]
这里能不能用streamreader
用读写的方法做呢?
我是初学者,现在在学readerLine
只要存进数字,逗号不管。。。。。

他原题是这样的
Assume that the file (C:\Data.txt) contains 15 intergers, one per line.
write the code for a sub procedure to read th……
[/Quote]
StreamReader是VB.NET的,VB没有。
of123 2010-06-23
  • 打赏
  • 举报
回复
按我的理解,文件大致是这个样子:

16
911
73
55
9981
...

写入二维数组的是行号和数值

Public Values(14, 1) As Integer

Dim i As Integer
Dim strTmp As String

Open "C:\Data.txt" For Input As #1
For i = 1 To 15
Line Input #1, strTmp
Values(i, 0) = i
Values(i, 1) = Val(strTmp)
Next i
Close #1
pangxie887 2010-06-23
  • 打赏
  • 举报
回复
这里能不能用streamreader
用读写的方法做呢?
我是初学者,现在在学readerLine
只要存进数字,逗号不管。。。。。

他原题是这样的
Assume that the file (C:\Data.txt) contains 15 intergers, one per line.
write the code for a sub procedure to read the file
into a two-dimensional array named Values.
Declare and dimension the array,
so that it can be used in other procedures
chinaboyzyq 2010-06-23
  • 打赏
  • 举报
回复

Private Sub Command1_Click()
Open "c:\1.txt" For Binary As #1
Dim a As String, b() As String
Dim c(2, 4), n As Integer
Dim i As Integer, j As Integer
a = StrConv(InputB(LOF(1), 1), vbUnicode): Close #1
b = Split(a, ",")

For i = 0 To 2
For j = 0 To 4
c(i, j) = b(j + n)
Next
n = n + j
Next

End Sub

threenewbee 2010-06-23
  • 打赏
  • 举报
回复
dim s as string
dim a() as string
dim result(,) as long
dim i as long
open "c:\dat.txt" for input as #1
s = input(lof(1), 1)
cloase #1
a = split(s, ", ")
'下面看你怎么放置到二维数组了。
'是变成
'1, 2
'3, 4
'5, 6
'...
'么?
'还是什么?
for i = 1 to ubound(a)
...
next

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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