Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Help Needed

Status
Not open for further replies.

TGK80

IS-IT--Management
Jan 27, 2008
2
US
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 = fso_OpenTextFile(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
 
Replace this:
XMLfile.Close
Loop
content.Close

with this:
Loop
XMLfile.Close
content.Close

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Worked like a charm thanks so much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top