将txt文件中的内容下载到变量 [英] Downloading content from txt file to a variable
问题描述
我做了一个计数器,当你按下按钮作为 VBScript 中的动作时它会起作用.
I made a counter that works when you press the button as the action in VBScript.
我的代码:
Licznik_ID = Licznik_ID + 1
Dim Stuff, myFSO, WriteStuff, dateStamp
Stuff = "Whatever you want written"
Set myFSO = CreateObject("Scripting.FileSystemObject")
Set WriteStuff = myFSO.OpenTextFile("c:\tmp\yourtextfile.txt", 2, True)
WriteStuff.WriteLine(Licznik_ID)
WriteStuff.Close
SET WriteStuff = NOTHING
SET myFSO = NOTHING
名为Licznik_ID"的计数器变量箭头所指.
the counter variable named "Licznik_ID" indicated by the arrow.
写入文件c:\tmp\yourtextfile.txt"它运作良好.每次数字增加一并被替换并存储在txt文件中.
It is written to the file "c:\tmp\yourtextfile.txt" And it works well. For each time the number increases by one and is replaced and stored in the txt file.
文件包含数字1,txt文件中增加出现数字2等等......
The file contains the number 1 and the increase in the txt file appears the number 2 and so on ...
现在如何将与文件c:\tmp\yourtextfile.txt"一起存储的数据下载回变量以使用它,以便在您启动 NiceForm 或按钮时已将 txt 文件的内容加载到一个变量?
How now download the data stored with the file "c: \tmp\yourtextfile.txt" back to the variable to use it in such a way that when you start NiceForm or button has been loaded with the contents of txt file into a variable?
推荐答案
Set myFSO = CreateObject("Scripting.FileSystemObject")
Licznik_ID = myFSO.OpenTextFile("C:\tmp\yourtextfile.txt").ReadAll
Licznik_ID = Licznik_ID + 1
myFSO.OpenTextFile("C:\tmp\yourtextfile.txt",2,True).Write(Licznik_ID)
FSO 有时处理文件模式的方式有点奇怪.
FSO is kinda weird the way it does its file modes sometimes.
如果您想允许它在不存在的情况下创建没有错误的文件,请将第 2 行替换为:
edit: If you want to allow this to create the file without errors if it doesn't exist, replace line 2 with this:
If myFSO.FileExists("C:\tmp\yourtextfile.txt") Then
Licznik_ID = myFSO.OpenTextFile("C:\tmp\yourtextfile.txt").ReadAll
End If
如果文件不存在,Licznik_ID
将为 Empty
.Empty + 1 = 1
在 vbscript 中.
If the file doesn't exist, Licznik_ID
will be Empty
. Empty + 1 = 1
in vbscript.
这篇关于将txt文件中的内容下载到变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!