0
我已經進行了一些基本的編程,但從未將任何輸入保存到文本文件。如果任何人可以請幫助我,我將不勝感激。vbscript中的Msgbox輸入保存/添加到文本文件
我已經得到腳本運行在網頁上,它的工作原理,但現在我需要將信息保存到文本文件。我希望它在評論中的代碼末尾顯示的格式。
感謝
<script type="text/vbscript">
<!--
Option Explicit
DIM newbook, title, author, startpage, stoppage, timeread, dateread
DIM pagesread, pagesperminute
'input
newbook = inputbox("Is this the first time reading this book? y -or- n")
'decision
if newbook = "y" then
title = inputbox("What is the book title?")
author = inputbox("Who wrote the book?")
startpage = 1
else
title = "******"
author = "******"
startpage = inputbox("What page did you start reading on")
end if
'input
stoppage = inputbox("What page did you stop reading on?")
timeread = inputbox("How long did you read?")
dateread = inputbox("What was the date you read on? MM/DD")
'calculation
pagesread = stoppage - startpage
pagesperminute = pagesread/timeread
'output
document.write "Date Read: " &(dateread)
document.write "<br>Book Title: " &(title)
document.write "<br>Author: " &(author)
document.write "<br>Pages Read: " &(startpage)
document.write " - " &(stoppage)
document.write "<br>Time Read: " &(timeread)
document.write "<br>Pages Read Per Minute: " &(pagesperminute)
'output to text log
進一步研究我想出了這個,它創建的文件或附加額外的數據文件幾乎像我想要的。我想改變的唯一事情是這樣的: filetxt.WriteLine(「的頁面閱讀:‘)&起始頁 filetxt.WriteLine(’ - 」)&停止 這些我寧願格式類似於在同一行: filetxt .WriteLine(「Pages Read:」)& startpage(「 - 」)& stoppage 產生於: 頁面閱讀:1 - 22 目前我無法弄清楚如何在不出錯的情況下完成此操作。
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.OpenTextFile("readlog.txt", ForAppending, True)
path = filesys.GetAbsolutePathName("C:\readlog\readlog.txt")
getname = filesys.GetFileName(path)
filetxt.WriteLine ("")
filetxt.WriteLine ("Date Read: ") &dateread
filetxt.WriteLine ("Book Title: ") &title
filetxt.WriteLine ("Author: ") &author
filetxt.WriteLine ("Pages Read: ") &startpage
filetxt.WriteLine (" - ") &stoppage
filetxt.WriteLine ("Time Read: ") &timeread
filetxt.WriteLine ("Pages Read Per Minute: ") &pagesperminute
' -->
</script>
感謝彌敦道,我想知道除了我以外是否有人在看這個。你碰巧知道如何做格式化,所以它會像我想要的那樣保存到日誌文件中? – 2015-03-05 15:34:47
我更新了我的答案。 – 2015-03-05 17:14:55