Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading and writing value from a textfile by using vbscript code

Tags:

vbscript

i have a variable named 'data' i need to write in to a textfile named "listfile.txt".Can you tell me the vbscript code to do that..And i need vbscript code for reading value from textfile "listfile.txt" also

like image 641
peter Avatar asked Jun 25 '10 10:06

peter


People also ask

How do I read a VBScript file?

How to open a VBS file. You can open and edit VBS files using any text editor, such as Notepad++ (Windows), Apple TextEdit (Mac), or GitHub Atom.

How do I write code in VBScript?

Step 1: Press Ctrl + Shift + S on the keyboard, Or click File>Save As on the notepad window, this will open up a Save As dialog window asking where to save the current notepad document. Step 2: Now write any file name of your choice for this notepad document but make sure you write . vbs as its extension.


2 Answers

To Write

Set objFileToWrite = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\listfile.txt",2,true)
objFileToWrite.WriteLine(data)
objFileToWrite.Close
Set objFileToWrite = Nothing

OpenTextFile parameters:

<filename>, IOMode (1=Read,2=write,8=Append), Create (true,false), Format (-2=System Default,-1=Unicode,0=ASCII)

To Read the entire file

Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\listfile.txt",1)
strFileText = objFileToRead.ReadAll()
objFileToRead.Close
Set objFileToRead = Nothing

To Read line by line

Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\listfile.txt",1)
Dim strLine
do while not objFileToRead.AtEndOfStream
     strLine = objFileToRead.ReadLine()
     'Do something with the line
loop
objFileToRead.Close
Set objFileToRead = Nothing
like image 118
Tester101 Avatar answered Nov 09 '22 10:11

Tester101


Need help reading and writing text file using vbscript - Dev Shed

http://forums.devshed.com/asp-programming-51/need-help-reading-and-writing-text-file-using-vbscript-355967.html

VBScript - FileSystemObject

http://ezinearticles.com/?VBScript---FileSystemObject&id=294348

like image 22
ratty Avatar answered Nov 09 '22 08:11

ratty