![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||