[jawsscripts] Re: Piping a string variable to a txt file as part of a script

  • From: "Logan McMullen" <loganmcmullen@xxxxxxxxxxxxxxx>
  • To: <jawsscripts@xxxxxxxxxxxxx>
  • Date: Thu, 28 Jan 2010 17:39:05 +1300

Hi Paul,

Thanks for this code..

Could you quickly(if possible) expand on the comments included in the source
code as to how I might use these functions?

I get the general idea but wondered if you, or someone else) might be able
to give me a brief example of using these functions.

Cheers

Logan.

-----Original Message-----
From: jawsscripts-bounce@xxxxxxxxxxxxx
[mailto:jawsscripts-bounce@xxxxxxxxxxxxx] On Behalf Of Paul Magill
Sent: Tuesday, 19 January 2010 11:44 p.m.
To: jawsscripts@xxxxxxxxxxxxx
Subject: [jawsscripts] Re: Piping a string variable to a txt file as part of
a script

Hi Logan,

- this is not as straight forward as it might seem.  There are no FS built 
in functions that write to text type files other than the INI functions, 
such as IniWriteString etc.

These do not provide for appending, other than creating additional keys etc.

Fortunately, especially for me, Jamal Masrui provided to the list, a set of 
functions that do that task very well.

Below are those functions, only slightly modified to suit my needs.

* The last one is what you are looking for.  It, and the other 2 file 
accessing functions need the first function. I included the other 2 as you 
may need them at some time.

Note 1: The read function reads the entire file into a string variable, & 
the Write function writes a file which will contain only the contents of the

string variable passed to it.  i e. anything already in the file will be 
overwritten. The append function adds to any text already in the file, but 
the file must already exist.
Note 2: you need to look after any linebreaks that you may need, as none are

provided by the functions. - this is very useful in most situations


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: "Logan McMullen" <loganmcmullen@xxxxxxxxxxxxxxx>


Hi everyone,

I'd like to use an input box to get some content from a user and to then
have the variable that is returned by the box save/piped to a txt file that
the script also creates.

The process would go like this(** note keystrokes are not what I'm using in
the actual script)

1. User hits ctrl+p and gets presented  with the  input box
1(a) A text file with a filename  of the current system time is created.
2. User inputs  content(text) in the box and hits enter(string variable is
then created by the input box
3.  String variable is appended to a txt file that has been created.

I have the time variable already sorted and could use a batch file to create
the txt file  but would rather use all script functions to achieve this if
possible to remove the need for the batch file to be on the users machine.

Thoughts appreciated.

Logan.

__________ 
Visit and contribute to The JAWS Script Repository http://jawsscripts.com

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


__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4785 (20100119) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


 

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4785 (20100119) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
  

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4786 (20100119) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
  

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4788 (20100120) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
  

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4791 (20100120) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
  

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4797 (20100122) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
  

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4800 (20100123) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
  

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4808 (20100126) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
  

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4811 (20100127) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
 

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4811 (20100127) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 

__________ 
Visit and contribute to The JAWS Script Repository http://jawsscripts.com

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

Other related posts: