ShackDaddy
MIS
Ok, I'm working through a book and came upon this code example, but I don't understand its output:
Here are the contents of the input file:
And here's what I get when I run it:
I'm expecting the value of UBound to be 4, not 3. I understand that arrays are zero-based, so it makes sense that if there were five items stored in the array, then the UBound value would be 4. I just can't fathom why it would be 3.
Can someone explain this?
Thanks,
ShackDaddy
Shackelford Consulting
Code:
TxtFile = "C:\ServersAndServices.txt"
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
(TxtFile, ForReading)
Do Until objTextFile.AtEndOfStream
boundary = Ubound(arrServiceList)
wscript.Echo "upper boundary = " & boundary
strNextLine = objTextFile.Readline
arrServiceList = Split(strNextLine , ",")
WScript.Echo "Server name: " & arrServiceList(0)
For i = 1 To Ubound(arrServiceList)
WScript.Echo "Service: " & arrServiceList(i)
Next
Loop
wscript.Echo "upper boundary = " & boundary
WScript.Echo("all done")
Here are the contents of the input file:
Code:
VORPAL,netlogon
VORPAL,netlogon,dhcpclient,spooler
VORPAL,netlogon,dhcpclient,spooler,iisadmin,w3svc
And here's what I get when I run it:
Code:
upper boundary =
Server name: VORPAL
Service: netlogon
upper boundary = 1
Server name: VORPAL
Service: netlogon
Service: dhcpclient
Service: spooler
upper boundary = 3
Server name: VORPAL
Service: netlogon
Service: dhcpclient
Service: spooler
Service: iisadmin
Service: w3svc
upper boundary = 3
all done
I'm expecting the value of UBound to be 4, not 3. I understand that arrays are zero-based, so it makes sense that if there were five items stored in the array, then the UBound value would be 4. I just can't fathom why it would be 3.
Can someone explain this?
Thanks,
ShackDaddy
Shackelford Consulting