How to read a text file

上一篇 / 下一篇  2010-03-28 00:15:47 / 个人分类:VBScript

Quick Check

 

Q.

How can the population of an array be automated?

A.

You can automate the population of an array by using the For...Next command.

Q.

If you do not know in advance how many elements are going to be in the array, how can you automate the population of an array?

A.

You can automate the population of an array with an unknown number of elements by using the For...Next command in conjunction with UBound.

ArrayReadTxtFile.vbs

through the split function to create a single dimension array and When you use the suffixes (0) and (i) in the WScript.Echo statement, VBScript. knows you want to refer to elements in the array

Option Explicit
Dim objFSO
Dim objTextFile
Dim strNextLine
Dim arrServiceList
Dim i
Const ForReading = 1
Set bjFSO = CreateObject("Scripting.FileSystemObject")
Set bjTextFile = objFSO.OpenTextFile("c:\Test.txt",ForReading)

Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.ReadLine
arrServiceList = Split(strNextLine,",")
WScript.Echo arrServiceList(0)
Loop

For i = 1 To UBound(arrServiceList)
WScript.Echo arrServiceList(i-1)
Next

WScript.Echo ("all done")


TAG:

 

评分:0

我来说两句

Open Toolbar