Search code examples
textvbscript

I need to save data to text files using wscript


I am making a script that will log you in to your Facebook account without having to go on the go internet and enter it yourself. I want to add an option to save your login information. I need to be able to write the data to a file and to put that data back into a variable. Here is what I have so far:

On Error Resume Next
set ie = CreateObject("InternetExplorer.Application")
sub loading
do while ie.busy
wscript.sleep 350
loop
end sub
username=inputbox("Please Enter Your Facebook Username/Email:","Facebook LogIn")
password=inputbox("Please Enter Your Facebook Password:","Facebook LogIn")
ie.left=0
ie.top=0
ie.toolbar=0
ie.statusbar=0
ie.height=135
ie.width=1020
ie.resizable=0
ie.navigate"https://www.facebook.com/"
call loading
ie.document.all.item("email").value=(username)
ie.document.all.item("pass").value=(password)
ie.Document.All.Item("login_form").Submit
call loading
ie.width=1200
ie.height=700
ie.resizable=true
ie.visible=true

Solution

  • To write to a file:

    Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
    Dim file : Set file = fso.OpenTextFile("C:\temp\myfile.txt", 2, True)
    file.Write "some text"
    file.Close
    

    To read file content into a var:

    Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
    Dim file : Set file = fso.OpenTextFile("C:\temp\myfile.txt", 1, False)
    myvar = file.ReadAll
    file.Close
    

    It goes without saying that you'll have to modify this - you don't necessarily want to read the whole file content into your variable. But that's the basics.