第1个回答 2008-12-04
给你个最简单的吧,随机生成90个数,在文本中以四列形式显示。
Private Sub Command2_Click()
Dim i, j, a(1 To 25, 1 To 4) As Integer
For i = 1 To 25
For j = 1 To 4
a(i, j) = Int(Rnd() * 90 + 10)
Next j, i
Open "d:\data.txt" For Output As #1
For i = 1 To 25
Print #1, Tab(1); a(i, 1); Tab(6); a(i, 2); Tab(11); a(i, 3); Tab(16); a(i, 4)
Next
Close #1
End Sub
完全能够满足你的要求了。
第2个回答 2008-12-04
你是想"e:\test.txt"这个文件的内容格式跟一个数据库的格式一样的吧,..
如果你非用open文本的代码来操作 我看只能对i这个变量的内容进行操作来实现你的要求了..
既然这么麻烦 为什么不用操作数据库的SQL语言呢..
增加一列:alter table tabelname add columnname varchar2(8) NULL
删除一列:alter table tablename drop column columnname
第3个回答 2008-12-04
用for循环
让变量 i 从1循环到4,一次写入一列
第4个回答 2008-12-04
也许下面的正是你需要的:
Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer, s As String
Open "c:\1.txt" For Output As #1
For i = 1 To 23
s = ""
For j = 1 To 4
k = 9 + i + (j - 1) * 23
If k < 100 Then s = s & k & vbTab
Next
Print #1, s
Next
Close #1
msgbox "文件写入完毕!"
End Sub本回答被网友采纳