【发布时间】:2015-03-06 01:14:39
【问题描述】:
我已经进行了一些基本的编程,但从未将任何输入保存到文本文件中。如果有人可以请帮助我,我将不胜感激。
我已经让脚本在网页中运行并且它可以工作,但现在我需要将信息保存到文本文件中。我希望它显示在 cmets 代码末尾的格式。
谢谢
<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 ("读取的页数:") &startpage filetxt.WriteLine(" - ") &stoppage 这些我宁愿格式化为同一行,类似于: filetxt.WriteLine ("读取的页数:") &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>
【问题讨论】:
标签: vbscript