如何讀取TXT文件內(nèi)容?
作者:金字塔 來源:cxh99.com 發(fā)布時(shí)間:2015年08月23日
- 咨詢內(nèi)容:
我們知道,在后臺,可以用debugfile將變量輸出到文件,反過來,要將TXT文件中的一個(gè)數(shù)值,如何讀取到金字塔后臺的變量中?深度請教!
- 金字塔客服:
3.1版已經(jīng)增加了INI文本文件的讀寫函數(shù),你可以直接使用這個(gè)來操作了
參考
http://www.weistock.com/bbs/dispbbs.asp?boardid=2&Id=59406
[此貼子已經(jīng)被作者于2014/1/18 14:10:47編輯過]
- 用戶回復(fù):
Sub WriteTxt()
Set WSHShell = CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
xFile = DesktopPath & "\config.txt"
MyTxt = Application.AppPath & " 文件創(chuàng)建時(shí)間 " & Now()
Set fso = CreateObject("scripting.FileSystemObject") '綁定fso對象
Set MyFile = fso.CreateTextFile(xFile, True)
MyFile.WriteLine (MyTxt)
MyFile.Close
Set MyFile = Nothing
Set fso = NothingEnd SubSub ReadTxt()
Set WSHShell = CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
xFile = DesktopPath & "\config.txt"
Set fso = CreateObject("scripting.FileSystemObject") '綁定fso對象
Set MyFile = fso.openTextFile(xFile, 1, True) '用.open方法打開文件
Do Until MyFile.AtEndOfStream
strLine = MyFile.ReadLine
application.MsgOut strLine
Loop
MyFile.Close
Set MyFile = Nothing
Set fso = NothingEnd Sub
- 網(wǎng)友回復(fù):
請問樓上這個(gè)是在自定義函數(shù)里面實(shí)現(xiàn)嗎?