Hi,
I have a text file with two items per line. E.g.
I need to be able to reference the day and it's corresponding boolean value.
I have a function with an array to split this out. Due to lack of skill, I am trying to use a dictionary object to return outside of the function.
This function reads the file and populates the dictionary object.
The following sub attemps to call the returned dictionary:
sub process:
This sub error with "Object not a collection: 'myDict.items'
I'd be very grateful if someone could point me in the write direction. I believe there is a better way to return the actual 2D array directly from the function without having to read it into a dictionary object, however my skill is not that great.
Many thanks
I have a text file with two items per line. E.g.
Code:
Monday=True
Tuesday=True
Wednesday=False
I need to be able to reference the day and it's corresponding boolean value.
I have a function with an array to split this out. Due to lack of skill, I am trying to use a dictionary object to return outside of the function.
This function reads the file and populates the dictionary object.
Code:
Function readCronTab(sFilePath)
Const ForReading = 1
Set oFile = fso.opentextfile(sFilePath,ForReading)
Dim strString, i, el
Dim arrArray(), arrTMP
' set init values
i = 0
Do Until oFile.AtEndOfStream
strNextLine = oFile.Readline
If InStr(strNextLine,"#") = False Then
arrTMP = Split(strNextLine,"=")
' arrange all elements into 2-dimensional array
For el = 0 to Ubound(arrTMP) step 2
'WScript.echo i
ReDim Preserve arrArray(2,i)
arrArray(1,i) = arrTMP(el)
arrArray(2,i) = arrTMP(el+1)
i = i + 1 ' increase index counter
'WScript.Echo arrTMP(el)& "=" & arrTMP(el+1)
oDict.add arrTMP(el) , arrTMP(el+1)
Next
' display arrARRAY contents:
End If
Loop
Set readCronTab = oDict
oFile.Close
End Function
The following sub attemps to call the returned dictionary:
sub process:
Code:
Sub process()
sFilePath = "CronTab.txt"
Set myDict = readCronTab(sFilePath)
For Each sDay In myDict
WScript.Echo sDay & " " & myDict.items(sDay)
Next
End Sub
This sub error with "Object not a collection: 'myDict.items'
I'd be very grateful if someone could point me in the write direction. I believe there is a better way to return the actual 2D array directly from the function without having to read it into a dictionary object, however my skill is not that great.
Many thanks