OK I have created this VBScript and for the most part it works ok. However I am adding functionality to go through the entire file I am reading. I added a Do Until and now it is broken. The error I get is Object Variable not set on line 54. Any Ideas?
quote:
Dim directory, fso, xmldir
Set fso = CreateObject("Scripting.FileSystemObject") ' File System Object
Set WshShell = WScript.CreateObject("WScript.Shell") ' Windows Scripting Host Shell
directory = "E:\Development\DATfiles\" ' Directory DAT Files are stored
xmldir = "E:\Development\XMLfiles\" ' Directory XML Files should be stored
scriptdir = "E:\Development\WeatherStationConversionScript\" ' Directory scripts are stored
dim folder, file
Set folder = fso.GetFolder(directory) ' Reads the specified Directory
Set file = folder.Files ' Reads a list of all the files in above directory
For Each fl in file
CreateXML(fl.name)
Next
Function CreateXML(filename)
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set content = fspenTextFile(directory & filename, ForReading, False)
'Remove the .DAT from the end of the filename for naming purposes
FileLength = Len(filename)
newfilename = Left(filename, FileLength -4)
Set XMLfile = fso.CreateTextFile(xmldir & newfilename & ".XML", True) 'CREATE XML FILE
Do until content.AtEndOfStream
info = content.ReadLine
linetype = mid(info,1,3)
fileyear = mid(info,5,4)
dayofyear = mid(info,10,3)
hours = mid(info,14,4)
'Write data to XML File
XMLfile.Writeline "<Weather_Data>"
XMLfile.Writeline "<LineType>" & linetype & "</LineType>"
XMLfile.Writeline "<FileYear>" & fileyear & "</FileYear>"
XMLfile.Writeline "<DayOfYear>" & dayofyear & "</DayOfYear>"
XMLfile.Writeline "<Hours>" & hours & "</Hours>"
XMLfile.Writeline "</Weather_Data>"
XMLfile.Close
Loop
content.Close
End Function
quote:
Dim directory, fso, xmldir
Set fso = CreateObject("Scripting.FileSystemObject") ' File System Object
Set WshShell = WScript.CreateObject("WScript.Shell") ' Windows Scripting Host Shell
directory = "E:\Development\DATfiles\" ' Directory DAT Files are stored
xmldir = "E:\Development\XMLfiles\" ' Directory XML Files should be stored
scriptdir = "E:\Development\WeatherStationConversionScript\" ' Directory scripts are stored
dim folder, file
Set folder = fso.GetFolder(directory) ' Reads the specified Directory
Set file = folder.Files ' Reads a list of all the files in above directory
For Each fl in file
CreateXML(fl.name)
Next
Function CreateXML(filename)
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set content = fspenTextFile(directory & filename, ForReading, False)
'Remove the .DAT from the end of the filename for naming purposes
FileLength = Len(filename)
newfilename = Left(filename, FileLength -4)
Set XMLfile = fso.CreateTextFile(xmldir & newfilename & ".XML", True) 'CREATE XML FILE
Do until content.AtEndOfStream
info = content.ReadLine
linetype = mid(info,1,3)
fileyear = mid(info,5,4)
dayofyear = mid(info,10,3)
hours = mid(info,14,4)
'Write data to XML File
XMLfile.Writeline "<Weather_Data>"
XMLfile.Writeline "<LineType>" & linetype & "</LineType>"
XMLfile.Writeline "<FileYear>" & fileyear & "</FileYear>"
XMLfile.Writeline "<DayOfYear>" & dayofyear & "</DayOfYear>"
XMLfile.Writeline "<Hours>" & hours & "</Hours>"
XMLfile.Writeline "</Weather_Data>"
XMLfile.Close
Loop
content.Close
End Function