Computer Hope

Software => Computer software => Topic started by: shrshr429 on August 23, 2009, 03:19:28 PM

Title: How can i get a vbscript to write in a text file.
Post by: shrshr429 on August 23, 2009, 03:19:28 PM
Trying to make a vbscript to write in text file, lets say i have C:\example.txt how can i modify this script to write in that text file?

Dim objFileSystem, objOutputFile
Dim strOutputFile

Const OPEN_FILE_FOR_APPENDING = 8

' generate a filename base on the script name
strOutputFile = "./writefile.out"

Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.OpenTextFile(strOutputFile, _
  OPEN_FILE_FOR_APPENDING)

objOutputFile.WriteLine("Hello world (" & Now & ")")
objOutputFile.Close

Set objFileSystem = Nothing

WScript.Quit(0)
Title: Re: How can i get a vbscript to write in a text file.
Post by: smeezekitty on August 23, 2009, 03:21:39 PM
i am not very good at vb
i think that BC_programmer will help here
but i think you change strOutputFile = "./writefile.out"
to
strOutputFile = "./example.txt"
Title: Re: How can i get a vbscript to write in a text file.
Post by: shrshr429 on August 23, 2009, 04:17:12 PM
I somewhat figured it out, it'll add text to the file only if it is near it. For example, if the vbs file was located in my documents folder then the text file i am adding has to be there as well. Is there anyway to change it so it will add text to a file in a different location. Anyone?
Title: Re: How can i get a vbscript to write in a text file.
Post by: BC_Programmer on August 23, 2009, 04:21:35 PM
use the full path. right now your using .\, which means the current directory.
Title: Re: How can i get a vbscript to write in a text file.
Post by: shrshr429 on August 23, 2009, 04:24:44 PM
That's really weird, i could of swore i tried that and it didn't work and then i just tried it again after i read your post and it did.

Well anyway, thanks alot BC!
Title: Re: How can i get a vbscript to write in a text file.
Post by: BC_Programmer on August 23, 2009, 04:25:33 PM
oh yeah, I almost forgot, is this a virus?

ha ha, just kidding.  :P
Title: Re: How can i get a vbscript to write in a text file.
Post by: Quantos on August 23, 2009, 04:28:39 PM
oh yeah, I almost forgot, is this a virus?

ha ha, just kidding.  :P

Whoosh.  I don't get it.
Title: Re: How can i get a vbscript to write in a text file.
Post by: shrshr429 on August 23, 2009, 04:39:24 PM
I had a long argument in a previous post because some guy thought i was developing a virus. BC is just messing around.
Title: Re: How can i get a vbscript to write in a text file.
Post by: Quantos on August 23, 2009, 04:42:22 PM
I had a long argument in a previous post because some guy thought i was developing a virus. BC is just messing around.

Ah, you are referring to this thread (http://www.computerhope.com/forum/index.php/topic,90294.0/all.html).

Now I get it.
Title: Re: How can i get a vbscript to write in a text file.
Post by: smeezekitty on August 23, 2009, 05:05:21 PM
i anoy evreyone
salmon anoys evreyone
salmon anoys me
i anoy salmon so there
Title: Re: How can i get a vbscript to write in a text file.
Post by: Quantos on August 23, 2009, 05:07:21 PM
That's not true.

salmon doesn't bother me in the slightest.  I prefer it smoked, but....
Title: Re: How can i get a vbscript to write in a text file.
Post by: smeezekitty on August 23, 2009, 05:13:30 PM
I prefer it smoked, but....
hahaha
thats very funny
and carbon dude dont get to mad for me going off topic again
Title: Re: How can i get a vbscript to write in a text file.
Post by: patio on August 23, 2009, 06:42:45 PM
i anoy evreyone
salmon anoys evreyone
salmon anoys me
i anoy salmon so there

What are you saying here ? ?
Title: Re: How can i get a vbscript to write in a text file.
Post by: BC_Programmer on August 23, 2009, 06:44:21 PM
What are you saying here ? ?

Something about his Salmon being narcoleptic, I think. But how could you tell anyway- fish don't close their eyes when they fall asleep.
Title: Re: How can i get a vbscript to write in a text file.
Post by: Quantos on August 23, 2009, 06:58:44 PM
What are you saying here ? ?

You really want to know?
Title: Re: How can i get a vbscript to write in a text file.
Post by: BatchFileBasics on August 24, 2009, 10:56:11 PM
quantos, if you tell him, this forums will not be 'g' rated anymore  ;)
Title: Re: How can i get a vbscript to write in a text file.
Post by: smeezekitty on August 24, 2009, 11:06:58 PM
so i assume people what i mean