Tuesday, November 24, 2009

Reading and Writing in Text File Vb Script

// VB Script
Sub WritetoFile( txtvalue)

dim fs,f
const ForReading=1,Forwriting=2,ForAppending=8,TristateFalse=0

path="d:\myfile.txt"

set fs=createObject("Scripting.FileSystemObject")
If not fs.FileExists(path) Then
set objFile=fs.CreateTextFile(path)
objfile.close()
End If
Set f=fs.OpenTextFile(path,ForAppending, TristateFalse)
f.write txtValue & vbCrLf
f.close()

End Sub


Sub ReadFile()

Const ForReading=1
Set fs=sys.OleObject("Scripting.FilesystemObject")
Set f= fs.OpenTextFile("d:\myfile.txt",ForReading)
f.skipline
While not f.AtEndOfstream
s=f.readline()
Count=getcsvcount(s)
For i=0 to count-1
Log.Message(Getcsvitem(s,i))
Next
Wend
f.close()

end Sub

sub test

call WritetoFile("Nitin")
call WritetoFile("Nitin")
call ReadFile()

end sub

No comments:

Post a Comment

I welcome your comment, will respond and post it at the earliest:)