The GW-Scripting list is a discussion list for information regarding the development and use of Window-Eyes scripts. Any subscriber of the GW-Scripting list has the ability to post on-topic messages.
From:
"David" <elephant@tele2.no>Subject:
yet another Object definition questionDate:
Mon, Jun 25, 2012 10:02:13 pmThis is a multi-part message in MIME format.
------=_NextPart_000_01A8_01CD5350.779A4360
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Throughout my app, I am going to use a given object several times, but in different subs and functions, and with different properties and methods.
My techie question here is, what is the most adviceable way, or the official practice here? Should I make a Global definition, and then do my local variants thereof, like:
Dim FS: Set FS = CreateObject( "WScript.FileSystemObject")
Dim F: Set F = Nothing
sub ReadFile( Filename)
Set F = FS.OpenTextFile( Filename, 1, False)
End Sub 'ReadFile.
Sub WriteFile( Filename)
Set F = FS.OpenTextFile( Filename, 2, True)
End Sub 'WriteFile.
Sub EndApp()
If Not F Is Nothing Then Set F = Nothing
Set FS = Nothing
End Sub 'EndAp.
Or, should I strictly go for local definitions, like:
Dim FS: Set FS = CreateObject( "WScript.FileSystemObject")
Sub ReadFile( Filename)
Dim F: Set F = FS.OpenTextFile( Filename, 1, False)
Set F = Nothing
End Sub 'ReadFile.
Sub WriteFile( Filename)
Dim F: Set F = FS.OpenTextFile( Filename, 2, True)
Set F = Nothing
End Sub 'WriteFile.
Sub EndApp()
Set FS = Nothing
End Sub 'EndApp.
In my first sample, it does make the lesser amount of writing and number of instructions. But is the second sample more "inline with the books"? Does the one sample take less memory than the other? And, is the one more safe to run - less vulnerable - than the other? I somehow have the feeling, that the second sample - with all local definition of the F object, and nullifying it for every time - is a bit more safe run. At the same time, I wonder if the repeated definition of the object does take more time or memory - in any way.
OK, I know time might not be the biggest issue, since we are talking only fractions of a second anyway. But what if the above was holding objects that are called hundreds of times, like in a speech handler of some kind? The, even fractions of seconds that you save every time you call an object could maybe have an effect? And, what is the encouraged practice in a matter like this. I want to have the app running as safe and fast as possible, smile.
Thanks for any feedback here.
------=_NextPart_000_01A8_01CD5350.779A4360
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.19258">
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=2 face=Arial>Throughout my app, I am going to use a given object
several times, but in different subs and functions, and with different
properties and methods.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>My techie question here is, what is the most
adviceable way, or the official practice here? Should I make a Global
definition, and then do my local variants thereof, like:</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial> Dim FS: Set FS = CreateObject(
"WScript.FileSystemObject")</FONT></DIV>
<DIV><FONT size=2 face=Arial> Dim F: Set F =
Nothing</FONT></DIV>
<DIV><FONT size=2 face=Arial>sub ReadFile( Filename)</FONT></DIV>
<DIV><FONT size=2 face=Arial> Set F = FS.OpenTextFile(
Filename, 1, False)</FONT></DIV>
<DIV><FONT size=2 face=Arial>End Sub 'ReadFile.</FONT></DIV>
<DIV><FONT size=2 face=Arial>Sub WriteFile( Filename)</FONT></DIV>
<DIV><FONT size=2 face=Arial> Set F = FS.OpenTextFile(
Filename, 2, True)</FONT></DIV>
<DIV><FONT size=2 face=Arial>End Sub 'WriteFile.</FONT></DIV>
<DIV><FONT size=2 face=Arial>Sub EndApp()</FONT></DIV>
<DIV><FONT size=2 face=Arial> If Not F Is Nothing
Then Set F = Nothing</FONT></DIV>
<DIV><FONT size=2 face=Arial> Set FS = Nothing</FONT></DIV>
<DIV><FONT size=2 face=Arial>End Sub 'EndAp.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>Or, should I strictly go for local definitions,
like:</FONT></DIV>
<DIV><FONT size=2 face=Arial> Dim FS: Set FS = CreateObject(
"WScript.FileSystemObject")</FONT></DIV>
<DIV><FONT size=2 face=Arial>Sub ReadFile( Filename)</FONT></DIV>
<DIV><FONT size=2 face=Arial> Dim F: Set F = FS.OpenTextFile(
Filename, 1, False)</FONT></DIV>
<DIV><FONT size=2 face=Arial> Set F =
Nothing</FONT></DIV>
<DIV><FONT size=2 face=Arial>End Sub 'ReadFile.</FONT></DIV>
<DIV><FONT size=2 face=Arial>Sub WriteFile( Filename)</FONT></DIV>
<DIV><FONT size=2 face=Arial> Dim F: Set F = FS.OpenTextFile(
Filename, 2, True)</FONT></DIV>
<DIV><FONT size=2 face=Arial> Set F = Nothing</FONT></DIV>
<DIV><FONT size=2 face=Arial>End Sub 'WriteFile.</FONT></DIV>
<DIV><FONT size=2 face=Arial>Sub EndApp()</FONT></DIV>
<DIV><FONT size=2 face=Arial> Set FS = Nothing</FONT></DIV>
<DIV><FONT size=2 face=Arial>End Sub 'EndApp.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>In my first sample, it does make the lesser amount
of writing and number of instructions. But is the second sample more "inline
with the books"? Does the one sample take less memory than the other? And, is
the one more safe to run - less vulnerable - than the other? I somehow have the
feeling, that the second sample - with all local definition of the F object, and
nullifying it for every time - is a bit more safe run. At the same time, I
wonder if the repeated definition of the object does take more time or memory -
in any way.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>OK, I know time might not be the biggest issue,
since we are talking only fractions of a second anyway. But what if the above
was holding objects that are called hundreds of times, like in a speech handler
of some kind? The, even fractions of seconds that you save every time you call
an object could maybe have an effect? And, what is the encouraged practice in a
matter like this. I want to have the app running as safe and fast as possible,
smile.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>Thanks for any feedback here.</FONT></DIV>
<DIV> </DIV></BODY></HTML>
------=_NextPart_000_01A8_01CD5350.779A4360--
------=_NextPart_000_01A8_01CD5350.779A4360
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Throughout my app, I am going to use a given object several times, but in different subs and functions, and with different properties and methods.
My techie question here is, what is the most adviceable way, or the official practice here? Should I make a Global definition, and then do my local variants thereof, like:
Dim FS: Set FS = CreateObject( "WScript.FileSystemObject")
Dim F: Set F = Nothing
sub ReadFile( Filename)
Set F = FS.OpenTextFile( Filename, 1, False)
End Sub 'ReadFile.
Sub WriteFile( Filename)
Set F = FS.OpenTextFile( Filename, 2, True)
End Sub 'WriteFile.
Sub EndApp()
If Not F Is Nothing Then Set F = Nothing
Set FS = Nothing
End Sub 'EndAp.
Or, should I strictly go for local definitions, like:
Dim FS: Set FS = CreateObject( "WScript.FileSystemObject")
Sub ReadFile( Filename)
Dim F: Set F = FS.OpenTextFile( Filename, 1, False)
Set F = Nothing
End Sub 'ReadFile.
Sub WriteFile( Filename)
Dim F: Set F = FS.OpenTextFile( Filename, 2, True)
Set F = Nothing
End Sub 'WriteFile.
Sub EndApp()
Set FS = Nothing
End Sub 'EndApp.
In my first sample, it does make the lesser amount of writing and number of instructions. But is the second sample more "inline with the books"? Does the one sample take less memory than the other? And, is the one more safe to run - less vulnerable - than the other? I somehow have the feeling, that the second sample - with all local definition of the F object, and nullifying it for every time - is a bit more safe run. At the same time, I wonder if the repeated definition of the object does take more time or memory - in any way.
OK, I know time might not be the biggest issue, since we are talking only fractions of a second anyway. But what if the above was holding objects that are called hundreds of times, like in a speech handler of some kind? The, even fractions of seconds that you save every time you call an object could maybe have an effect? And, what is the encouraged practice in a matter like this. I want to have the app running as safe and fast as possible, smile.
Thanks for any feedback here.
------=_NextPart_000_01A8_01CD5350.779A4360
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.19258">
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=2 face=Arial>Throughout my app, I am going to use a given object
several times, but in different subs and functions, and with different
properties and methods.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>My techie question here is, what is the most
adviceable way, or the official practice here? Should I make a Global
definition, and then do my local variants thereof, like:</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial> Dim FS: Set FS = CreateObject(
"WScript.FileSystemObject")</FONT></DIV>
<DIV><FONT size=2 face=Arial> Dim F: Set F =
Nothing</FONT></DIV>
<DIV><FONT size=2 face=Arial>sub ReadFile( Filename)</FONT></DIV>
<DIV><FONT size=2 face=Arial> Set F = FS.OpenTextFile(
Filename, 1, False)</FONT></DIV>
<DIV><FONT size=2 face=Arial>End Sub 'ReadFile.</FONT></DIV>
<DIV><FONT size=2 face=Arial>Sub WriteFile( Filename)</FONT></DIV>
<DIV><FONT size=2 face=Arial> Set F = FS.OpenTextFile(
Filename, 2, True)</FONT></DIV>
<DIV><FONT size=2 face=Arial>End Sub 'WriteFile.</FONT></DIV>
<DIV><FONT size=2 face=Arial>Sub EndApp()</FONT></DIV>
<DIV><FONT size=2 face=Arial> If Not F Is Nothing
Then Set F = Nothing</FONT></DIV>
<DIV><FONT size=2 face=Arial> Set FS = Nothing</FONT></DIV>
<DIV><FONT size=2 face=Arial>End Sub 'EndAp.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>Or, should I strictly go for local definitions,
like:</FONT></DIV>
<DIV><FONT size=2 face=Arial> Dim FS: Set FS = CreateObject(
"WScript.FileSystemObject")</FONT></DIV>
<DIV><FONT size=2 face=Arial>Sub ReadFile( Filename)</FONT></DIV>
<DIV><FONT size=2 face=Arial> Dim F: Set F = FS.OpenTextFile(
Filename, 1, False)</FONT></DIV>
<DIV><FONT size=2 face=Arial> Set F =
Nothing</FONT></DIV>
<DIV><FONT size=2 face=Arial>End Sub 'ReadFile.</FONT></DIV>
<DIV><FONT size=2 face=Arial>Sub WriteFile( Filename)</FONT></DIV>
<DIV><FONT size=2 face=Arial> Dim F: Set F = FS.OpenTextFile(
Filename, 2, True)</FONT></DIV>
<DIV><FONT size=2 face=Arial> Set F = Nothing</FONT></DIV>
<DIV><FONT size=2 face=Arial>End Sub 'WriteFile.</FONT></DIV>
<DIV><FONT size=2 face=Arial>Sub EndApp()</FONT></DIV>
<DIV><FONT size=2 face=Arial> Set FS = Nothing</FONT></DIV>
<DIV><FONT size=2 face=Arial>End Sub 'EndApp.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>In my first sample, it does make the lesser amount
of writing and number of instructions. But is the second sample more "inline
with the books"? Does the one sample take less memory than the other? And, is
the one more safe to run - less vulnerable - than the other? I somehow have the
feeling, that the second sample - with all local definition of the F object, and
nullifying it for every time - is a bit more safe run. At the same time, I
wonder if the repeated definition of the object does take more time or memory -
in any way.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>OK, I know time might not be the biggest issue,
since we are talking only fractions of a second anyway. But what if the above
was holding objects that are called hundreds of times, like in a speech handler
of some kind? The, even fractions of seconds that you save every time you call
an object could maybe have an effect? And, what is the encouraged practice in a
matter like this. I want to have the app running as safe and fast as possible,
smile.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>Thanks for any feedback here.</FONT></DIV>
<DIV> </DIV></BODY></HTML>
------=_NextPart_000_01A8_01CD5350.779A4360--




