使用VBScript逐一读取值

时间:2018-10-24 06:31:05

标签: vbscript properties

我有一个如下的属性文件:

FileToRead=project.xml,CheckFile.ini
RunTimeFile=MyRuntime.xml

我想通过使用VBScript的FileToRead循环来逐一读取参数For的逗号分隔值。

我已经尝试过如下脚本进行测试的脚本:

Set fso = CreateObject("Scripting.FileSystemObject")

Const ForReading = 1
Const ForWriting = 2

listFile = fso.OpenTextFile("MyFile.properties").ReadLine
listcheck = Split(listFile, vbCrLf)

For Each MyValue In listcheck
    segments = Split(line, ",")
    WScript.Echo "SimpleCheck" 
Next

是否有可能在VBS的Or块内使用If条件?

1 个答案:

答案 0 :(得分:1)

您可以使用类似的

Set fso = CreateObject("Scripting.FileSystemObject")

'Dictionary to store all the lines in form of key value pair
Set dict = CreateObject("Scripting.Dictionary")

Set file = fso.OpenTextFile ("<InputFilePath>", 1)

'Reading the file and storing properties in the dictionary
Do Until file.AtEndOfStream
  line = file.Readline
  splittedLine = Split(line,"=")
  if UBound(splittedLine)=1 then
    dict.Add splittedLine(0),splittedLine(1)
  end if
Loop
file.Close

'Now get the value from dictionary using key name FileToRead
valFileToRead = dict.item("FileToRead")
arrFiles=Split(valFileToRead,",")
for i=0 to UBound(arrFiles)
  'Do anything with the values
  msgBox(arrFiles(i))
next

是的,您可以在内部使用OR关键字

if Condition1 OR Condition 2 then
   'Code
end if