作者MOONRAKER (㊣秘密情报员)
看板Visual_Basic
标题Re: [问题] VB程式怎麽开档呢?
时间Sat Jan 24 14:41:10 2009
这不是为你答的,
纯粹因为现在不答,以後还会有人问,所以总结一下
以後有人问可以叫他来看这篇。
---
VB6:
VB6档案处理有 open() 法和 filesystemobject 法,这里只介绍後面这种。
open() 法已经过时10年以上,拜托不要再用了。
读取档案: 见旧文章
#18PUiADX
写入档案: 见旧文章
#18tZrVgg
VB.NET读取档案
开档
dim inf as system.io.streamreader =
new system.io.streamreader(档名, false, system.text.encoding.default)
(分成两行,自己组合起来)
读取一行
inLine = inf.readline()
读取一个字
inChar = inf.read()
判断读完没
inf.endofstream()
读完关掉
inf.close()
范例
dim inf as system.io.streamreader = new system.io.streamreader(
档名, false, system.text.encoding.default)
while not inf.endofstream()
dim inline as string
inline = inf.readline()
textbox1.appendtext(inline & vbcrlf)
end while
inf.close
VB.NET写入档案
开档
dim outf as system.io.streamwriter =
new system.io.streamreader(档名, false, system.text.encoding.default)
写入字串
outf.write(字串)
写入字串并换行
outf.writeline(字串)
写完关掉
outf.close()
范例
dim logfile as system.io.streamwriter = New System.IO.StreamWriter(
"log0.log", True, System.Text.Encoding.Default)
logfile.Write("EXEC 8 terminated at " & Now.ToString() & vbCrLf)
logilfe.close()
其他请自己弄一本书看。图书馆对大家都很宽大的。
--
BATCH 03 : 买张床 - 切达大侠 - 伐木人之歌 -
http://tinyurl.com/3zpyx5
[B4准备中]: 讴歌金钱(7/02) - 单车超人(7/23) -
http://tinyurl.com/66v6vq
[ 番外篇 ]: 包租婆也有过当罗莉的时候(7/17) -
http://tinyurl.com/6j4ale
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
■ 蒙帝派松正体中文计画 ■ Spam-a-lot and enjoy the pythonesque delight!
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ https://www.youtube.com/user/JamesBondXD▄▄
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.115.205.26