[jawsscripts] Re: writing strings to text file using jaws scripting techniques

  • From: "Paul Magill" <magills@xxxxxxxxxxx>
  • To: <jawsscripts@xxxxxxxxxxxxx>
  • Date: Sun, 13 Jan 2013 20:34:00 +1100

Hi,

I have been using the functions at the bottom of this post since Jaws 10, & 
they continue to work very reliably.

They were provided on this list by Jamal Mazrui, & are in his "homer 
utilities" file at:
http://grabbag.alacorncomputer.com/jawsscripting.html





The first function gives access to the Windows file system, & the following 
3 functions, read text from a text file into a Jaws string variable, the 
second write text from a Jaws string variable to a text file, & the third 
appends text to a text file from a Jaws string variable.



I have made only superficial changes to Jamal's original scripts.



the first 1 is called by all of the following 3.



Your looking for the function called WriteFileFromString.



Sample usage:

Script TestStringWrite ()

var

String  MyStringVariable



Let MyStringVariable = "On a cold and bleak winters day"



WriteFileFromString (MyStringVariable, "c:\\Sample.txt")

EndScript



will write only the quoted text into the text file titled sample.text in the 
root directory of C drive.



*** Note, In a Jaws script, any quoted file path must have it back slashes 
doubled, \\.







Object Function ObjectCreate (string S_Object)

Var

Object o_return

Let o_return =CreateObjectEx (s_object, True)

;SayString ("first")

If !o_return Then

Let o_return =CreateObjectEx(s_object, False)

;SayString ("second")

EndIf

If !o_return Then

Let o_return =GetObject(s_object)

;SayString ("third")

EndIf

Return o_return

EndFunction

?

String Function ReadStringFromFile (string S_File)

Var

Object Null,

Object o_system,

Object o_file,

String s_return

Let o_system =ObjectCreate("Scripting.FilesystemObject")

Let o_file =o_system.OpenTextFile(s_file, 1, 0)

Let s_return =o_file.ReadAll()

o_file.close()

Let o_file =Null

Let o_system =Null

Return s_return

EndFunction

?

Int Function WriteFileFromString (string S_Text, string S_File)

Var

Object Null,

Object o_system,

Object o_file

Let o_system =ObjectCreate("Scripting.FilesystemObject")

Let o_file =o_system.CreateTextFile(s_file, 1, 0)

o_file.write(s_text)

o_file.close()

Let o_file =Null

Let o_system =Null

EndFunction

?

?

Int Function AppendStringToFile (string S_Text, string S_File)

; *** this function *ONLY* appends to already existing files. use 
WriteFileFromString to create the file

; each append adds to the previous record without line breaks etc

Var

Object Null,

Object o_system,

Object o_file

Let o_system =ObjectCreate("Scripting.FilesystemObject")

Let o_file =o_system.OpenTextFile (s_file, 8, 0)

o_file.write (s_text)

o_file.close()

Let o_file =Null

Let o_system =Null

EndFunction

?

?

----- Original Message ----- 
From: "Kaveinthran Pulanthran" <kavein2211@xxxxxxxxx>


hi there,

Do any one have an idea how to write strings into a text file using
scripting techniques?
That means, it will not contain equal sign like an ini file, just the
string we want will be in it.

thanks

__________�

View the list's information and change your settings at 
//www.freelists.org/list/jawsscripts

Other related posts: