‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
‘VB SCRIPT PRACTICE SAMPLES FSO SET - 1
‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'Sample 1: FSO OBJECT
‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Public Function funcFSOObject()
Set objFSO = CreateObject("Scripting.FileSystemObject")
End Function
‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'Sample 2: CREATE TEXT FILE
‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Public Function funcCreateTextFile()
Dim objFile, strFilePah
strFilePath = "C:\VBSPractice.txt"
Set objFile = CreateObject("Scripting.FileSystemObject")
If objFile.FileExists(strFilePath) Then
MsgBox strFilePath & " Exists"
Else
Set MyFile = objFile.CreateTextFile (strFilePath)
MyFile.Close
End If
End Function
‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'Sample 3: WRITE TEXT FILE
‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Public Function funcWriteTextFile()
Dim objFile, strFilePah
Const ForWriting = 2
strFilePath = "C:\VBSPractive.txt"
Set objFile = CreateObject("Scripting.FileSystemObject")
If objFile.FileExists(strFilePath) Then
MsgBox strFilePath & " Exists"
Else
Set MyFile = objFile.CreateTextFile (strFilePath)
End If
MyFile.Close
Set MyFile = objFile.OpenTextFile(strFilePath, ForWriting, True)
MyFile.Write("WELCOME TO VB SCRIPT PRACTICE")
MyFile.WriteLine("WELCOME TO VB SCRIPT PRACTICE")
MyFile.Write("WELCOME TO VB SCRIPT PRACTICE")
MyFile.WriteBlankLines 1
MyFile.Close
End Function
‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'Sample 4: READ TEXT FILE
‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Public Function funcReadTextFile()
Dim objFile, strFilePah
Const ForWriting = 2
strFilePath = "C:\VBSPractive.txt"
Set objFile = CreateObject("Scripting.FileSystemObject")
If objFile.FileExists(strFilePath) Then
MsgBox strFilePath & " Exists"
Else
Set MyFile = objFile.CreateTextFile (strFilePath)
End If
MyFile.Close
Set MyFile = objFile.OpenTextFile(strFilePath, ForWriting, True)
MyFile.Write("WELCOME TO VB SCRIPT PRACTICE")
MyFile.WriteLine("WELCOME TO VB SCRIPT PRACTICE")
MyFile.Write("WELCOME TO VB SCRIPT PRACTICE")
MyFile.WriteBlankLines 1
MyFile.Close
Set MyFile = objFile.OpenTextFile(strFilePath, 1, True)
LineData = MyFile.ReadLine()
MsgBox LineData
MyFile.Close
objFile.DeleteFile(strFilePath)
End Function
‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'Sample 5: APPEND TEXT FILE
‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Public Function funcAppendTextFile()
Dim objFile, strFilePah
Const ForWriting = 2
strFilePath = "C:\VBSPractive.txt"
Set objFile = CreateObject("Scripting.FileSystemObject")
If objFile.FileExists(strFilePath) Then
MsgBox strFilePath & " Exists"
Else
Set MyFile = objFile.CreateTextFile (strFilePath)
End If
MyFile.Close
Set MyFile = objFile.OpenTextFile(strFilePath, ForWriting, True)
MyFile.Write("WELCOME TO VB SCRIPT PRACTICE")
MyFile.WriteLine("WELCOME TO VB SCRIPT PRACTICE")
MyFile.Write("WELCOME TO VB SCRIPT PRACTICE")
MyFile.WriteBlankLines 1
MyFile.Close
Set MyFile = objFile.OpenTextFile(strFilePath, 1, True)
LineData = MyFile.ReadLine()
MsgBox LineData
MyFile.Close
Set MyFile = objFile.OpenTextFile(strFilePath, 8, True)
MyFile.Write("WELCOME TO VB SCRIPT PRACTICE")
MyFile.WriteLine("WELCOME TO VB SCRIPT PRACTICE")
MyFile.Write("WELCOME TO VB SCRIPT PRACTICE")
MyFile.WriteBlankLines 1
MyFile.Write("WELCOME TO VB SCRIPT PRACTICE")
MyFile.Close
objFile.DeleteFile(strFilePath)
End Function
‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
No comments:
Post a Comment