Wednesday, January 13, 2010

Write a program to Write or read or Delete or Move or Copy data from a text file

Const ForReading = 1, ForWriting = 2
Dim FSOj, oF, oFDel
'Create the Notepad
Set FSOj = CreateObject("Scripting.FileSystemObject")
Set oF = FSOj.OpenTextFile("c:\testfile.txt", ForWriting, True)
'Write the Data in to Notepad
oF.write "Notepad Testing using VBScript"
oF.writeblanklines (3)
oF.write "Check your Mobile"
oF.writeblanklines (3)
oF.writeline " More about You "
'Read the Data from file
Set oFRead = FSOj.OpenTextFile("c:\testfile.txt", ForReading)
oFRd = oFRead.Readall()
MsgBox "File Info = '" & oFRd & "'"
'Move the file
Set oFMove = FSOj.Getfile("c:\testfile.txt")
oFMove.Move ("C:\test\testfile.txt")
'copy the file
oFMove.Copy ("C:\test\testfile.txt")
'Delete the file
Set oFDel = FSOj.Getfile("c:\testfile.txt")
oFDel.Delete
oF.Close

Print Hello World

Msgbox “ Hello World”
Or
a = " Hello world"
If a <> 0 Then
Debug.Print "True"
MsgBox a
Else
Debug.Print "False"
End If