Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Writing information to text file

Reply
 
Old 09-03-2008   #1 (permalink)
whiggins


 
 

Writing information to text file

Hello, I am trying to gather some patch information for several machines and
I wrote a little vbscript to gather the information for me. I am having some
problems writing out to a text file. The issue I am having is that when it
goes to write a line that has no information it gives me an error of
Microsoft VBScript runtime error: Object required.

If have tested to see if the variables are an empty string, Nulls, and
Nothing.
The script works fine if I just do a Wscript.Echo instead of writing it out
to a file.

Any Help would be greatly appreciated.
Thanks in advance.

Here is my script
Dim Name, Description, Status, HotFix
Name = ""
Description = ""
Status = ""
HotFix = ""
Set objFS = WScript.CreateObject("Scripting.FileSystemObject")
Set strPatchResults = objFS.createtextfile("C:\Temp\PatchTemp.txt", true)
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM
Win32_QuickFixEngineering",,48)
For Each objItem in colItems
Name = ""
Description = ""
Status = ""
HotFix = ""
Name = objItem.Name
Description = objItem.Description
Status = objItem.Status
HotFix = objItem.HotFixID
If Name = "" Then
Name = "N/A"
End If
If Description = "" Then
Description = "N/A"
End If
If Status = "" Then
Status = "Installed"
End if
If HotFix = "" Then
HotFix = "N/A"
End If
strPatchResults.WriteLine(Name)
strPatchResults.WriteLine(Description)
strPatchResults.WriteLine(Status)
strPatchResults.WriteLine(HotFix)
PatchCount = PatchCount + 1
Next
strPatchResults.Close()


My System SpecsSystem Spec
Old 09-03-2008   #2 (permalink)
Pegasus \(MVP\)


 
 

Re: Writing information to text file


"whiggins" <whiggins@xxxxxx> wrote in message
news:C0FDFDDB-563A-4D9F-BDFE-9F2C6C876147@xxxxxx
Quote:

> Hello, I am trying to gather some patch information for several machines
> and
> I wrote a little vbscript to gather the information for me. I am having
> some
> problems writing out to a text file. The issue I am having is that when
> it
> goes to write a line that has no information it gives me an error of
> Microsoft VBScript runtime error: Object required.
>
> If have tested to see if the variables are an empty string, Nulls, and
> Nothing.
> The script works fine if I just do a Wscript.Echo instead of writing it
> out
> to a file.
>
> Any Help would be greatly appreciated.
> Thanks in advance.
>
> Here is my script
> Dim Name, Description, Status, HotFix
> Name = ""
> Description = ""
> Status = ""
> HotFix = ""
> Set objFS = WScript.CreateObject("Scripting.FileSystemObject")
> Set strPatchResults = objFS.createtextfile("C:\Temp\PatchTemp.txt", true)
> Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
> Set colItems = objWMIService.ExecQuery("SELECT * FROM
> Win32_QuickFixEngineering",,48)
> For Each objItem in colItems
> Name = ""
> Description = ""
> Status = ""
> HotFix = ""
> Name = objItem.Name
> Description = objItem.Description
> Status = objItem.Status
> HotFix = objItem.HotFixID
> If Name = "" Then
> Name = "N/A"
> End If
> If Description = "" Then
> Description = "N/A"
> End If
> If Status = "" Then
> Status = "Installed"
> End if
> If HotFix = "" Then
> HotFix = "N/A"
> End If
> strPatchResults.WriteLine(Name)
> strPatchResults.WriteLine(Description)
> strPatchResults.WriteLine(Status)
> strPatchResults.WriteLine(HotFix)
> PatchCount = PatchCount + 1
> Next
> strPatchResults.Close()
>
This happens because your variables are not empty strings but undefined. You
can get around the problem as shown in the script below. Note the shortened
syntax for the "If/then" statements - much less chatty!

Dim Name, Description, Status, HotFix
Name = ""
Description = ""
Status = ""
HotFix = ""
Set objFS = WScript.CreateObject("Scripting.FileSystemObject")
Set strPatchResults = objFS.createtextfile("c:\Temp\PatchTemp.txt", True)
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM
Win32_QuickFixEngineering", , 48)

For Each objItem In colItems
Name = objItem.Name
Description = objItem.Description
Status = objItem.Status
HotFix = objItem.HotFixID
If vartype(Name) = 1 Then Name = "N/A"
If vartype(Description) = 1 Then Description = "N/A"
If vartype(Status) = 1 Then Status = "Installed"
If vartype(HotFix) = 1 Then HotFix = "N/A"
strPatchResults.WriteLine(Name)
strPatchResults.WriteLine(Description)
strPatchResults.WriteLine(Status)
strPatchResults.WriteLine(HotFix)
PatchCount = PatchCount + 1
Next
strPatchResults.Close()


My System SpecsSystem Spec
Old 09-03-2008   #3 (permalink)
Owen Gilmore


 
 

Re: Writing information to text file

On Sep 3, 1:32*pm, whiggins <whigg...@xxxxxx>
wrote:
Quote:

> Hello, I am trying to gather some patch information for several machines and
> I wrote a little vbscript to gather the information for me. *I am having some
> problems writing out to a text file. *The issue I am having is that when it
> goes to write a line that has no information it gives me an error of
> Microsoft VBScript runtime error: Object required.
>
> If have tested to see if the variables are an empty string, Nulls, and
> Nothing.
> The script works fine if I just do a Wscript.Echo instead of writing it out
> to a file.
>
> Any Help would be greatly appreciated.
> Thanks in advance.
>
> Here is my script
> * * * * Dim Name, Description, Status, HotFix
> * * * * Name = ""
> * * * * Description = ""
> * * * * Status = ""
> * * * * HotFix = ""
> * * * * Set objFS = WScript.CreateObject("Scripting.FileSystemObject")
> * * * * Set strPatchResults = objFS.createtextfile("C:\Temp\PatchTemp.txt", true)
> * * * * Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
> * * * * Set colItems = objWMIService.ExecQuery("SELECT * FROM
> Win32_QuickFixEngineering",,48)
> * * * * For Each objItem in colItems
> * * * * * * * * Name = ""
> * * * * * * * * Description = ""
> * * * * * * * * Status = ""
> * * * * * * * * HotFix = ""
> * * * * * * Name = objItem.Name
> * * * * * * Description = objItem.Description
> * * * * * * Status = objItem.Status
> * * * * * * HotFix = objItem.HotFixID
> * * * * * * If Name = "" Then
> * * * * * * * * Name = "N/A"
> * * * * * * End If
> * * * * * * If Description = "" Then
> * * * * * * * * Description = "N/A"
> * * * * * * End If
> * * * * * * If Status = "" Then
> * * * * * * * * Status = "Installed"
> * * * * * * End if
> * * * * * * If HotFix = "" Then
> * * * * * * * * HotFix = "N/A"
> * * * * * * End If
> * * * * * * * * strPatchResults.WriteLine(Name)
> * * * * * * * * strPatchResults.WriteLine(Description)
> * * * * * * * * strPatchResults.WriteLine(Status)
> * * * * * * * * strPatchResults.WriteLine(HotFix)
> * * * * * * PatchCount = PatchCount + 1
> * * * * Next
> * * * * strPatchResults.Close()
I problem I see off the bat, hard coding the path c:\temp
Is the file ever created?
My System SpecsSystem Spec
Old 09-03-2008   #4 (permalink)
whiggins


 
 

Re: Writing information to text file

Thanks Pegasus. that did the trick for me.

Does the VarType keyword specify that what is in the () is a variable?

"Pegasus (MVP)" wrote:
Quote:

>
> "whiggins" <whiggins@xxxxxx> wrote in message
> news:C0FDFDDB-563A-4D9F-BDFE-9F2C6C876147@xxxxxx
Quote:

> > Hello, I am trying to gather some patch information for several machines
> > and
> > I wrote a little vbscript to gather the information for me. I am having
> > some
> > problems writing out to a text file. The issue I am having is that when
> > it
> > goes to write a line that has no information it gives me an error of
> > Microsoft VBScript runtime error: Object required.
> >
> > If have tested to see if the variables are an empty string, Nulls, and
> > Nothing.
> > The script works fine if I just do a Wscript.Echo instead of writing it
> > out
> > to a file.
> >
> > Any Help would be greatly appreciated.
> > Thanks in advance.
> >
> > Here is my script
> > Dim Name, Description, Status, HotFix
> > Name = ""
> > Description = ""
> > Status = ""
> > HotFix = ""
> > Set objFS = WScript.CreateObject("Scripting.FileSystemObject")
> > Set strPatchResults = objFS.createtextfile("C:\Temp\PatchTemp.txt", true)
> > Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
> > Set colItems = objWMIService.ExecQuery("SELECT * FROM
> > Win32_QuickFixEngineering",,48)
> > For Each objItem in colItems
> > Name = ""
> > Description = ""
> > Status = ""
> > HotFix = ""
> > Name = objItem.Name
> > Description = objItem.Description
> > Status = objItem.Status
> > HotFix = objItem.HotFixID
> > If Name = "" Then
> > Name = "N/A"
> > End If
> > If Description = "" Then
> > Description = "N/A"
> > End If
> > If Status = "" Then
> > Status = "Installed"
> > End if
> > If HotFix = "" Then
> > HotFix = "N/A"
> > End If
> > strPatchResults.WriteLine(Name)
> > strPatchResults.WriteLine(Description)
> > strPatchResults.WriteLine(Status)
> > strPatchResults.WriteLine(HotFix)
> > PatchCount = PatchCount + 1
> > Next
> > strPatchResults.Close()
> >
>
> This happens because your variables are not empty strings but undefined. You
> can get around the problem as shown in the script below. Note the shortened
> syntax for the "If/then" statements - much less chatty!
>
> Dim Name, Description, Status, HotFix
> Name = ""
> Description = ""
> Status = ""
> HotFix = ""
> Set objFS = WScript.CreateObject("Scripting.FileSystemObject")
> Set strPatchResults = objFS.createtextfile("c:\Temp\PatchTemp.txt", True)
> Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
> Set colItems = objWMIService.ExecQuery("SELECT * FROM
> Win32_QuickFixEngineering", , 48)
>
> For Each objItem In colItems
> Name = objItem.Name
> Description = objItem.Description
> Status = objItem.Status
> HotFix = objItem.HotFixID
> If vartype(Name) = 1 Then Name = "N/A"
> If vartype(Description) = 1 Then Description = "N/A"
> If vartype(Status) = 1 Then Status = "Installed"
> If vartype(HotFix) = 1 Then HotFix = "N/A"
> strPatchResults.WriteLine(Name)
> strPatchResults.WriteLine(Description)
> strPatchResults.WriteLine(Status)
> strPatchResults.WriteLine(HotFix)
> PatchCount = PatchCount + 1
> Next
> strPatchResults.Close()
>
>
>
My System SpecsSystem Spec
Old 09-03-2008   #5 (permalink)
Pegasus \(MVP\)


 
 

Re: Writing information to text file

I recommend that you download script56.chm from the Microsoft site, then
look up the VarType method. It shows you every available code.

"whiggins" <whiggins@xxxxxx> wrote in message
news:E4C5347B-244C-497E-800B-366EE57B48F8@xxxxxx
Quote:

> Thanks Pegasus. that did the trick for me.
>
> Does the VarType keyword specify that what is in the () is a variable?
>
> "Pegasus (MVP)" wrote:
>
Quote:

>>
>> "whiggins" <whiggins@xxxxxx> wrote in message
>> news:C0FDFDDB-563A-4D9F-BDFE-9F2C6C876147@xxxxxx
Quote:

>> > Hello, I am trying to gather some patch information for several
>> > machines
>> > and
>> > I wrote a little vbscript to gather the information for me. I am
>> > having
>> > some
>> > problems writing out to a text file. The issue I am having is that
>> > when
>> > it
>> > goes to write a line that has no information it gives me an error of
>> > Microsoft VBScript runtime error: Object required.
>> >
>> > If have tested to see if the variables are an empty string, Nulls, and
>> > Nothing.
>> > The script works fine if I just do a Wscript.Echo instead of writing it
>> > out
>> > to a file.
>> >
>> > Any Help would be greatly appreciated.
>> > Thanks in advance.
>> >
>> > Here is my script
>> > Dim Name, Description, Status, HotFix
>> > Name = ""
>> > Description = ""
>> > Status = ""
>> > HotFix = ""
>> > Set objFS = WScript.CreateObject("Scripting.FileSystemObject")
>> > Set strPatchResults = objFS.createtextfile("C:\Temp\PatchTemp.txt",
>> > true)
>> > Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
>> > Set colItems = objWMIService.ExecQuery("SELECT * FROM
>> > Win32_QuickFixEngineering",,48)
>> > For Each objItem in colItems
>> > Name = ""
>> > Description = ""
>> > Status = ""
>> > HotFix = ""
>> > Name = objItem.Name
>> > Description = objItem.Description
>> > Status = objItem.Status
>> > HotFix = objItem.HotFixID
>> > If Name = "" Then
>> > Name = "N/A"
>> > End If
>> > If Description = "" Then
>> > Description = "N/A"
>> > End If
>> > If Status = "" Then
>> > Status = "Installed"
>> > End if
>> > If HotFix = "" Then
>> > HotFix = "N/A"
>> > End If
>> > strPatchResults.WriteLine(Name)
>> > strPatchResults.WriteLine(Description)
>> > strPatchResults.WriteLine(Status)
>> > strPatchResults.WriteLine(HotFix)
>> > PatchCount = PatchCount + 1
>> > Next
>> > strPatchResults.Close()
>> >
>>
>> This happens because your variables are not empty strings but undefined.
>> You
>> can get around the problem as shown in the script below. Note the
>> shortened
>> syntax for the "If/then" statements - much less chatty!
>>
>> Dim Name, Description, Status, HotFix
>> Name = ""
>> Description = ""
>> Status = ""
>> HotFix = ""
>> Set objFS = WScript.CreateObject("Scripting.FileSystemObject")
>> Set strPatchResults = objFS.createtextfile("c:\Temp\PatchTemp.txt", True)
>> Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
>> Set colItems = objWMIService.ExecQuery("SELECT * FROM
>> Win32_QuickFixEngineering", , 48)
>>
>> For Each objItem In colItems
>> Name = objItem.Name
>> Description = objItem.Description
>> Status = objItem.Status
>> HotFix = objItem.HotFixID
>> If vartype(Name) = 1 Then Name = "N/A"
>> If vartype(Description) = 1 Then Description = "N/A"
>> If vartype(Status) = 1 Then Status = "Installed"
>> If vartype(HotFix) = 1 Then HotFix = "N/A"
>> strPatchResults.WriteLine(Name)
>> strPatchResults.WriteLine(Description)
>> strPatchResults.WriteLine(Status)
>> strPatchResults.WriteLine(HotFix)
>> PatchCount = PatchCount + 1
>> Next
>> strPatchResults.Close()
>>
>>
>>

My System SpecsSystem Spec
Old 09-03-2008   #6 (permalink)
Richard Mueller [MVP]


 
 

Re: Writing information to text file


"Pegasus (MVP)" <I.can@xxxxxx> wrote in message
news:%23dWAUDhDJHA.4816@xxxxxx
Quote:

>I recommend that you download script56.chm from the Microsoft site, then
>look up the VarType method. It shows you every available code.
>
> "whiggins" <whiggins@xxxxxx> wrote in message
> news:E4C5347B-244C-497E-800B-366EE57B48F8@xxxxxx
Quote:

>> Thanks Pegasus. that did the trick for me.
>>
>> Does the VarType keyword specify that what is in the () is a variable?
>>
>> "Pegasus (MVP)" wrote:
>>
Quote:

>>>
>>> "whiggins" <whiggins@xxxxxx> wrote in message
>>> news:C0FDFDDB-563A-4D9F-BDFE-9F2C6C876147@xxxxxx
>>> > Hello, I am trying to gather some patch information for several
>>> > machines
>>> > and
>>> > I wrote a little vbscript to gather the information for me. I am
>>> > having
>>> > some
>>> > problems writing out to a text file. The issue I am having is that
>>> > when
>>> > it
>>> > goes to write a line that has no information it gives me an error of
>>> > Microsoft VBScript runtime error: Object required.
>>> >
>>> > If have tested to see if the variables are an empty string, Nulls, and
>>> > Nothing.
>>> > The script works fine if I just do a Wscript.Echo instead of writing
>>> > it
>>> > out
>>> > to a file.
>>> >
>>> > Any Help would be greatly appreciated.
>>> > Thanks in advance.
>>> >
>>> > Here is my script
>>> > Dim Name, Description, Status, HotFix
>>> > Name = ""
>>> > Description = ""
>>> > Status = ""
>>> > HotFix = ""
>>> > Set objFS = WScript.CreateObject("Scripting.FileSystemObject")
>>> > Set strPatchResults = objFS.createtextfile("C:\Temp\PatchTemp.txt",
>>> > true)
>>> > Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
>>> > Set colItems = objWMIService.ExecQuery("SELECT * FROM
>>> > Win32_QuickFixEngineering",,48)
>>> > For Each objItem in colItems
>>> > Name = ""
>>> > Description = ""
>>> > Status = ""
>>> > HotFix = ""
>>> > Name = objItem.Name
>>> > Description = objItem.Description
>>> > Status = objItem.Status
>>> > HotFix = objItem.HotFixID
>>> > If Name = "" Then
>>> > Name = "N/A"
>>> > End If
>>> > If Description = "" Then
>>> > Description = "N/A"
>>> > End If
>>> > If Status = "" Then
>>> > Status = "Installed"
>>> > End if
>>> > If HotFix = "" Then
>>> > HotFix = "N/A"
>>> > End If
>>> > strPatchResults.WriteLine(Name)
>>> > strPatchResults.WriteLine(Description)
>>> > strPatchResults.WriteLine(Status)
>>> > strPatchResults.WriteLine(HotFix)
>>> > PatchCount = PatchCount + 1
>>> > Next
>>> > strPatchResults.Close()
>>> >
>>>
>>> This happens because your variables are not empty strings but undefined.
>>> You
>>> can get around the problem as shown in the script below. Note the
>>> shortened
>>> syntax for the "If/then" statements - much less chatty!
>>>
>>> Dim Name, Description, Status, HotFix
>>> Name = ""
>>> Description = ""
>>> Status = ""
>>> HotFix = ""
>>> Set objFS = WScript.CreateObject("Scripting.FileSystemObject")
>>> Set strPatchResults = objFS.createtextfile("c:\Temp\PatchTemp.txt",
>>> True)
>>> Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
>>> Set colItems = objWMIService.ExecQuery("SELECT * FROM
>>> Win32_QuickFixEngineering", , 48)
>>>
>>> For Each objItem In colItems
>>> Name = objItem.Name
>>> Description = objItem.Description
>>> Status = objItem.Status
>>> HotFix = objItem.HotFixID
>>> If vartype(Name) = 1 Then Name = "N/A"
>>> If vartype(Description) = 1 Then Description = "N/A"
>>> If vartype(Status) = 1 Then Status = "Installed"
>>> If vartype(HotFix) = 1 Then HotFix = "N/A"
>>> strPatchResults.WriteLine(Name)
>>> strPatchResults.WriteLine(Description)
>>> strPatchResults.WriteLine(Status)
>>> strPatchResults.WriteLine(HotFix)
>>> PatchCount = PatchCount + 1
>>> Next
>>> strPatchResults.Close()
>>>
>>>
>>>
>
As noted, the error is raised because the value assigned to the variable is
Null. In similar situations where the value can be Null I append a blank
string to the value, to that the result is always a string. For example:

Name = objItem.Name & ""
Description = objItem.Description & ""
Status = objItem.Status & ""
HotFix = objItem.HotFixID & ""

In this case, assigning the value "N/A" might be better.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 09-07-2008   #7 (permalink)
Al Dunbar


 
 

Re: Writing information to text file


"Pegasus (MVP)" <I.can@xxxxxx> wrote in message
news:%23gpP1ugDJHA.2056@xxxxxx
Quote:

>
> "whiggins" <whiggins@xxxxxx> wrote in message
> news:C0FDFDDB-563A-4D9F-BDFE-9F2C6C876147@xxxxxx
Quote:

>> Hello, I am trying to gather some patch information for several machines
>> and
>> I wrote a little vbscript to gather the information for me. I am having
>> some
>> problems writing out to a text file. The issue I am having is that when
>> it
>> goes to write a line that has no information it gives me an error of
>> Microsoft VBScript runtime error: Object required.
>>
>> If have tested to see if the variables are an empty string, Nulls, and
>> Nothing.
>> The script works fine if I just do a Wscript.Echo instead of writing it
>> out
>> to a file.
>>
>> Any Help would be greatly appreciated.
>> Thanks in advance.
>>
>> Here is my script
>> Dim Name, Description, Status, HotFix
>> Name = ""
>> Description = ""
>> Status = ""
>> HotFix = ""
>> Set objFS = WScript.CreateObject("Scripting.FileSystemObject")
>> Set strPatchResults = objFS.createtextfile("C:\Temp\PatchTemp.txt", true)
>> Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
>> Set colItems = objWMIService.ExecQuery("SELECT * FROM
>> Win32_QuickFixEngineering",,48)
>> For Each objItem in colItems
>> Name = ""
>> Description = ""
>> Status = ""
>> HotFix = ""
>> Name = objItem.Name
>> Description = objItem.Description
>> Status = objItem.Status
>> HotFix = objItem.HotFixID
>> If Name = "" Then
>> Name = "N/A"
>> End If
>> If Description = "" Then
>> Description = "N/A"
>> End If
>> If Status = "" Then
>> Status = "Installed"
>> End if
>> If HotFix = "" Then
>> HotFix = "N/A"
>> End If
>> strPatchResults.WriteLine(Name)
>> strPatchResults.WriteLine(Description)
>> strPatchResults.WriteLine(Status)
>> strPatchResults.WriteLine(HotFix)
>> PatchCount = PatchCount + 1
>> Next
>> strPatchResults.Close()
>>
>
> This happens because your variables are not empty strings but undefined.
> You can get around the problem as shown in the script below. Note the
> shortened syntax for the "If/then" statements - much less chatty!
>
> Dim Name, Description, Status, HotFix
Quote:

> Name = ""
> Description = ""
> Status = ""
> HotFix = ""
A nice cleanup of the script, but the above four statements appear to me to
be unnecessary.

/Al
Quote:

> Set objFS = WScript.CreateObject("Scripting.FileSystemObject")
> Set strPatchResults = objFS.createtextfile("c:\Temp\PatchTemp.txt", True)
> Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
> Set colItems = objWMIService.ExecQuery("SELECT * FROM
> Win32_QuickFixEngineering", , 48)
>
> For Each objItem In colItems
> Name = objItem.Name
> Description = objItem.Description
> Status = objItem.Status
> HotFix = objItem.HotFixID
> If vartype(Name) = 1 Then Name = "N/A"
> If vartype(Description) = 1 Then Description = "N/A"
> If vartype(Status) = 1 Then Status = "Installed"
> If vartype(HotFix) = 1 Then HotFix = "N/A"
> strPatchResults.WriteLine(Name)
> strPatchResults.WriteLine(Description)
> strPatchResults.WriteLine(Status)
> strPatchResults.WriteLine(HotFix)
> PatchCount = PatchCount + 1
> Next
> strPatchResults.Close()
>

My System SpecsSystem Spec
Old 09-07-2008   #8 (permalink)
Pegasus \(MVP\)


 
 

Re: Writing information to text file


"Al Dunbar" <AlanDrub@xxxxxx> wrote in message
news:eC%23nP6SEJHA.3996@xxxxxx
Quote:

>
Quote:

>> Dim Name, Description, Status, HotFix
>
Quote:

>> Name = ""
>> Description = ""
>> Status = ""
>> HotFix = ""
>
> A nice cleanup of the script, but the above four statements appear to me
> to be unnecessary.
>
> /Al
Indeed, but I think that initialising one's variables is always a good idea,
even though it's not usually necessary in VB Scripts. I have seen many a
batch file fail for this very reason . . .


My System SpecsSystem Spec
Old 09-08-2008   #9 (permalink)
Al Dunbar


 
 

Re: Writing information to text file


"Pegasus (MVP)" <I.can@xxxxxx> wrote in message
news:%23kmRXITEJHA.3476@xxxxxx
Quote:

>
> "Al Dunbar" <AlanDrub@xxxxxx> wrote in message
> news:eC%23nP6SEJHA.3996@xxxxxx
Quote:

>>
Quote:

>>> Dim Name, Description, Status, HotFix
>>
Quote:

>>> Name = ""
>>> Description = ""
>>> Status = ""
>>> HotFix = ""
>>
>> A nice cleanup of the script, but the above four statements appear to me
>> to be unnecessary.
>>
>> /Al
>
> Indeed, but I think that initialising one's variables is always a good
> idea, even though it's not usually necessary in VB Scripts. I have seen
> many a batch file fail for this very reason . . .
That is likely because batch files inherit the environment variable of the
parent process, whereas with vbscript this is not the case. I know that some
vbscripters assume that all undefined variables will come into existence as
zero-length strings when referenced, however, like you I believe that all
variables should be initialized.

Where we disagree is regarding the advisability of the above redundant
initialization. All you really need do is ensure that a valid value is
assigned to each variable before it is referenced.

If the first references are like these:

sum = sum + 1
list = list & nextItem

Then these should be preceded by:

sum = 0
list = ""

But if the first reference is:

Name = objItem.Name

Preceding it with:

Name = ""

Will have no effect, and may, in fact, confuse those maintaining the script.

/Al


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Convert hostname text file to IP text file VB Script
Skipping When Writing Text Vista mail
Writing Number to Text File: Type Problem? VB Script
I am looking for information on parsing log files (text) PowerShell
Newbie - Writing to host and a text file PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46