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 - How to do an IF strValue IS NOT "Specified Value" then....

Reply
 
Old 03-19-2009   #1 (permalink)
GBPackerBacker


 
 

How to do an IF strValue IS NOT "Specified Value" then....

Hey all, I've got a script that goes out and collects all the data on
the adapters of a computer. I want all adapters, except for a few
things like the RAS Asysync Adapter and the WAN Miniport and such.
How can I modify my writeline statement in my script to say basically:

if strAdapterDesc [IS NOT] "WAN Miniport, RAS Async Adapter, [or any
null value" then
Textfile.writeline "NULL"
else
TexFile.writeline "strAdapterDesc"


To recap, I have about 20 lines of adapters on my servers. I only care
about the 2-6 physical nics, so I want my script to go out and find
the adapter info, but only do a writeline on the pysical nics. I'm
having trouble with the IS NOT part of the equasion.

I want the exact oppiset of "if strAdapterDesc = "value" then)

Thanks in advance for any help.

BJ

My System SpecsSystem Spec
Old 03-19-2009   #2 (permalink)
ekkehard.horner


 
 

Re: How to do an IF strValue IS NOT "Specified Value" then....

GBPackerBacker schrieb:
Quote:

> Hey all, I've got a script that goes out and collects all the data on
> the adapters of a computer. I want all adapters, except for a few
> things like the RAS Asysync Adapter and the WAN Miniport and such.
> How can I modify my writeline statement in my script to say basically:
>
> if strAdapterDesc [IS NOT] "WAN Miniport, RAS Async Adapter, [or any
> null value" then
> Textfile.writeline "NULL"
> else
> TexFile.writeline "strAdapterDesc"
>
>
> To recap, I have about 20 lines of adapters on my servers. I only care
> about the 2-6 physical nics, so I want my script to go out and find
> the adapter info, but only do a writeline on the pysical nics. I'm
> having trouble with the IS NOT part of the equasion.
>
> I want the exact oppiset of "if strAdapterDesc = "value" then)
>
> Thanks in advance for any help.
>
> BJ
In most programming languages it is not nice to test for multiple
conditions:

If strAdapterDesc = "nice1" Or strAdapterDesc = "nice2" ... Then
do something

or

If strAdapterDesc <> "WAN Miniport" And strAdapterDesc <> "RAS Async Adapter" ... Then
do something

is clumsy and error-prone. In VBScript you have an additional problem:
Because there is no short-cut evaluation in If condition statements

Dim nZero : nZero = 0
If 0 <> nZero And 1 = (1 / nZero) Then WScript.Echo "surprise, surprise"

won't work, because VBScript tries to evaluate 1 = (1 / nZero) even
though 0 <> nZero is false.

A good strategy in such cases is to use a dictionary, which can accept
'everything' as key and therefore won't choke on testing Null or Objects.

Another method to make testing for multiple conditions easier, is using
Select Case True and specifying the conditions in the Case statements.

All this is demonstrated here:

Dim aTests : aTests = Array( _
Null, Empty, "", New RegExp, " ", "eins", "zwei", "drei", "one", "two", "three" _
)
Dim sNice : sNice = "eins zwei drei"
Dim dicNice : Set dicNice = CreateObject( "Scripting.Dictionary" )
Dim sKey
For Each sKey In Split( sNice, " " )
dicNice( sKey ) = 0
Next

Dim nZero : nZero = 0
On Error Resume Next
If 0 <> nZero And 1 = (1 / nZero) Then WScript.Echo "surprise, surprise"
If 0 <> Err.Number Then WScript.Echo "error", Err.Description
On Error GoTo 0

WScript.Echo "---------------"

Dim vItem
For Each vItem In aTests
If dicNice.Exists( vItem ) Then
WScript.Echo "oh nice, found", vItem
Else
WScript.Echo "ignoring an item"
End If
Next

WScript.Echo "---------------"

For Each vItem In aTests
Select Case True
Case IsNull( vItem ), IsObject( vItem )
WScript.Echo "ignoring Null or Object"
Case "" = Trim( vItem )
WScript.Echo "Ignoring empty string"
Case "zwei" = vItem
WScript.Echo "got the nice 2"
Case dicNice.Exists( vItem )
WScript.Echo "got a fairly nice", vItem
Case Else
WScript.Echo "don't care for", vItem
End Select
Next

Output:

=== easyIfs: complex conditions made easy ===
surprise, surprise
error Division durch Null
---------------
ignoring an item
ignoring an item
ignoring an item
ignoring an item
ignoring an item
oh nice, found eins
oh nice, found zwei
oh nice, found drei
ignoring an item
ignoring an item
ignoring an item
---------------
ignoring Null or Object
Ignoring empty string
Ignoring empty string
ignoring Null or Object
Ignoring empty string
got a fairly nice eins
got the nice 2
got a fairly nice drei
don't care for one
don't care for two
don't care for three
=== easyIfs: 0 done (00:00:03) ==============



My System SpecsSystem Spec
Old 03-19-2009   #3 (permalink)
GBPackerBacker


 
 

Re: How to do an IF strValue IS NOT "Specified Value" then....

Thankis for the info. I'm having good luck with the <> in the script,
pretty obvious when you think about it. Thanks for showing me how
dumb I can be! LOL.

Now for another one. Hoping this one isn't as stupid of a question,
but how do I pass parenthesis inside quotes?

So my script is as follows.

if strDriverDesc <> "WAN Miniport (L2TP)" then
wscript.echo "TEXT"

THe script keeps erroring out though because it doesn't know how to
process the L2TP inside the parenthesis, even though it's enveloped in
quotes......all others that don't have a parenthesis work great.





My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
SOLVED! "Cannot load Contacts" "0x8004104E" "MSOE.DLL" Vista mail
Unwanted Multiple contacts in "To","CC","BCC" of email send catago Vista mail
Vista not wotking with "My Computer" or "Control Panel", "Screen Saver" Vista General
How can I add the icons "Delete", "Cut", "Copy" and "Paste" in Vis Vista file management
WM5 Sync with Vista "Windows Calender", "Contacts", and "Mail" Vista General


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