How does one write to a file and then read the file contents with
out closing the file inbetween (if it is possible)? I'm tinkering
with the serial com port to see if the input buffer can be read
after writing to the output buffer. I can write bytes and such to
the comport by treating it like a file (substitute "COM1:" for
the "test.txt"), so the next question is can I get the contents
of the input buffer by reading the open file before closing it.
Can the below code be fixed such that it can read the contents of
the test.txt file after writing to it with out closing the file
first?

===================

Set fs=CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("test.txt",True)

a.write "this is a test"

Wscript.Sleep 1000

'get test.txt file contents here

'wscript.echo test.txt file contents here

a.Close()

Re: Writing to a file and then reading the file contents by Steven

Steven
Sat Feb 18 15:03:10 CST 2006

You really need to improve your naming conventions .... and yes, it can.

*********************************
Option Explicit
Dim objFSO, objFile, sFile
sFile = "test.txt"
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(sFile,True)
objFile.write "this is a test"
Wscript.Sleep 1000
'// get test.txt file contents here
Set objFile = objFSO.OpenTextFile(sFile)
'// wscript.echo test.txt file contents here
WScript.Echo objFile.ReadAll
objFile.Close: Set objFSO = Nothing: Set objFile = Nothing
*********************************

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Si Ballenger" <shb*NO*SPAM*@comporium.net> wrote in message
news:43f7798b.9812028@news.comporium.net...
> How does one write to a file and then read the file contents with
> out closing the file inbetween (if it is possible)? I'm tinkering
> with the serial com port to see if the input buffer can be read
> after writing to the output buffer. I can write bytes and such to
> the comport by treating it like a file (substitute "COM1:" for
> the "test.txt"), so the next question is can I get the contents
> of the input buffer by reading the open file before closing it.
> Can the below code be fixed such that it can read the contents of
> the test.txt file after writing to it with out closing the file
> first?
>
> ===================
>
> Set fs=CreateObject("Scripting.FileSystemObject")
> Set a = fs.CreateTextFile("test.txt",True)
>
> a.write "this is a test"
>
> Wscript.Sleep 1000
>
> 'get test.txt file contents here
>
> 'wscript.echo test.txt file contents here
>
> a.Close()
>



Re: Writing to a file and then reading the file contents by shb*NO*SPAM*

shb*NO*SPAM*
Sat Feb 18 15:39:28 CST 2006

What you put won't work substituting "com1:" in place of the
"test.txt". You appear to make the file, then "open" it a second
time to get the contents. What I need is to open or create a file
and write to it and then read from it with out using a second
"open" evolution. It needs to either be opened or created, then
write and read while open, then close it.

On Sat, 18 Feb 2006 21:03:10 -0000, "Steven Burn"
<somewhere@in-time.invalid> wrote:

>You really need to improve your naming conventions .... and yes, it can.
>
>*********************************
>Option Explicit
>Dim objFSO, objFile, sFile
>sFile = "test.txt"
>Set objFSO=CreateObject("Scripting.FileSystemObject")
>Set objFile = objFSO.CreateTextFile(sFile,True)
>objFile.write "this is a test"
>Wscript.Sleep 1000
>'// get test.txt file contents here
>Set objFile = objFSO.OpenTextFile(sFile)
>'// wscript.echo test.txt file contents here
>WScript.Echo objFile.ReadAll
>objFile.Close: Set objFSO = Nothing: Set objFile = Nothing
>*********************************
>
>--
>Regards
>
>Steven Burn
>Ur I.T. Mate Group
>www.it-mate.co.uk
>
>Keeping it FREE!
>
>"Si Ballenger" <shb*NO*SPAM*@comporium.net> wrote in message
>news:43f7798b.9812028@news.comporium.net...
>> How does one write to a file and then read the file contents with
>> out closing the file inbetween (if it is possible)? I'm tinkering
>> with the serial com port to see if the input buffer can be read
>> after writing to the output buffer. I can write bytes and such to
>> the comport by treating it like a file (substitute "COM1:" for
>> the "test.txt"), so the next question is can I get the contents
>> of the input buffer by reading the open file before closing it.
>> Can the below code be fixed such that it can read the contents of
>> the test.txt file after writing to it with out closing the file
>> first?
>>
>> ===================
>>
>> Set fs=CreateObject("Scripting.FileSystemObject")
>> Set a = fs.CreateTextFile("test.txt",True)
>>
>> a.write "this is a test"
>>
>> Wscript.Sleep 1000
>>
>> 'get test.txt file contents here
>>
>> 'wscript.echo test.txt file contents here
>>
>> a.Close()
>>
>
>


Re: Writing to a file and then reading the file contents by Steven

Steven
Sat Feb 18 15:59:47 CST 2006

You can substitute and use "COM1:" by issuing a Replace command to remove
the :, prior to creating the file....

'// Replace : with a .txt extension
sFile = Replace("COM1:", ":", ".txt")
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(sFile,True)

> What I need is to open or create a file
> and write to it and then read from it with out using a second
> "open" evolution. It needs to either be opened or created, then
> write and read while open, then close it.

You can't do that .... the content of the buffer isn't in the buffer until
it's opened (and it can't be placed into the buffer without opening it). If
you need simply to get it's content, write the output to a var - then save
the var, and use the var to read...

i.e.

Dim sOutput
sOutput = [whatever]

'// <save to file>

'// read var
WScript.Echo sOutput

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Si Ballenger" <shb*NO*SPAM*@comporium.net> wrote in message
news:43f79249.16138085@news.comporium.net...
> What you put won't work substituting "com1:" in place of the
> "test.txt". You appear to make the file, then "open" it a second
> time to get the contents. What I need is to open or create a file
> and write to it and then read from it with out using a second
> "open" evolution. It needs to either be opened or created, then
> write and read while open, then close it.
>
> On Sat, 18 Feb 2006 21:03:10 -0000, "Steven Burn"
> <somewhere@in-time.invalid> wrote:
>
> >You really need to improve your naming conventions .... and yes, it can.
> >
> >*********************************
> >Option Explicit
> >Dim objFSO, objFile, sFile
> >sFile = "test.txt"
> >Set objFSO=CreateObject("Scripting.FileSystemObject")
> >Set objFile = objFSO.CreateTextFile(sFile,True)
> >objFile.write "this is a test"
> >Wscript.Sleep 1000
> >'// get test.txt file contents here
> >Set objFile = objFSO.OpenTextFile(sFile)
> >'// wscript.echo test.txt file contents here
> >WScript.Echo objFile.ReadAll
> >objFile.Close: Set objFSO = Nothing: Set objFile = Nothing
> >*********************************
> >
> >--
> >Regards
> >
> >Steven Burn
> >Ur I.T. Mate Group
> >www.it-mate.co.uk
> >
> >Keeping it FREE!
> >
> >"Si Ballenger" <shb*NO*SPAM*@comporium.net> wrote in message
> >news:43f7798b.9812028@news.comporium.net...
> >> How does one write to a file and then read the file contents with
> >> out closing the file inbetween (if it is possible)? I'm tinkering
> >> with the serial com port to see if the input buffer can be read
> >> after writing to the output buffer. I can write bytes and such to
> >> the comport by treating it like a file (substitute "COM1:" for
> >> the "test.txt"), so the next question is can I get the contents
> >> of the input buffer by reading the open file before closing it.
> >> Can the below code be fixed such that it can read the contents of
> >> the test.txt file after writing to it with out closing the file
> >> first?
> >>
> >> ===================
> >>
> >> Set fs=CreateObject("Scripting.FileSystemObject")
> >> Set a = fs.CreateTextFile("test.txt",True)
> >>
> >> a.write "this is a test"
> >>
> >> Wscript.Sleep 1000
> >>
> >> 'get test.txt file contents here
> >>
> >> 'wscript.echo test.txt file contents here
> >>
> >> a.Close()
> >>
> >
> >
>



Re: Writing to a file and then reading the file contents by shb*NO*SPAM*

shb*NO*SPAM*
Sat Feb 18 17:32:20 CST 2006

On Sat, 18 Feb 2006 21:59:47 -0000, "Steven Burn"
<somewhere@in-time.invalid> wrote:


>> What I need is to open or create a file
>> and write to it and then read from it with out using a second
>> "open" evolution. It needs to either be opened or created, then
>> write and read while open, then close it.
>
>You can't do that .... the content of the buffer isn't in the buffer until
>it's opened (and it can't be placed into the buffer without opening it). If
>you need simply to get it's content, write the output to a var - then save
>the var, and use the var to read...

The serial port has two buffers, and input buffer, and an output
buffer. Both become open and available when the com port is
opened. In the usual basic programming, the port is opened as a
file for random access to allow output and input access, which
can't apparently be done in vbscript. Vbscript appears to open
files with out having to specify at the time of opening what type
of activity is to be done (read or write) on the file at that
time. I'm testing to see if vbscript allows both input and output
under a single open statement. The below serial-out.vbs sends the
string of "a"s to the serial port which goes out the Tx pin. The
bottom serial.bas is the typical setup for writing and then
reading the serial port buffers. I'm looking for a way to read
the input buffer. For testing a jumper is placed between the Tx
and Rx pins on the serial port so what is being output is sent
into the input buffer for reading.

========serial-out.vbs======

Set fs=CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("com1:",True)
a.write "aaaaa"
a.Close

========serial.bas============

open "COM1:57600,N,8,1,cs0,ds0,rs" for random as #1
print #1, "aaaaa"

EndTime = time$("ms") + 50
while time$("ms") < EndTime
wend

dataRead$ = input$(#1, lof(#1))
print dataRead$

close #2