Author Options:

How would i save text in a VBScript code? Answered

so far i can create a text file with this code :

set objFile= CreateObject ("Scripting.FileSystemObject")
Set textfile = objFile.CreateTextFile("Results.txt")

but i dont know how i would save text to that file. any help?




Best Answer 8 years ago

Thats not a problem. WriteLine or Write is what you need. The question is where does the text come from?

well i comes from an inputbox and then changes to a variable "nm" and "em" but i could combine the variables to make one

Try this:

Dim nm, em, FSO, oFile

nm = InputBox("Please enter the 1st line:", "Value for ""nm""")
em = InputBox("Please enter the 2nd line:", "Value for ""em""")

Set FSO = CreateObject("Scripting.FileSystemObject")
Set oFile = FSO.OpenTextFile("Results.txt", 2, True)
oFile.Write(nm & vbCrLf & em)

Set oFile = Nothing
Set FSO = Nothing

i just used wright twice it works though thnk

That is the VB - constant for the line break.