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 - Re: Select case question

Reply
 
Old 04-16-2009   #1 (permalink)
Pegasus [MVP]


 
 

Re: Select case question


"Jack" <j.baltus@xxxxxx> wrote in message
news:41b96$49e772f2$5ed32516$8586@xxxxxx
Quote:

> Can anybody help me with a script
> I want if a one file exist then go to a select statement, and do somthing
> But i don`t no how
>
>
>
> Option Explicit
> On Error Resume Next
> Dim arrScript, Array1, BtnCode, WshShell, FileName, FVersion, Script
> Dim Lcomputer, Msg, McShieldPath, NewDATVer, Nwrk, path, f,
> StartDir,sfncLib
> Dim OldDatVer, strDC, strVersion, sVirDefVer, verify, RegistryValue,
> VsInst80, VsInst85
> Dim strNextLine, Lineread, sTmpDir, Arraystr, infile, objTextFile,
> scommand
> Dim fso:
> CONST CONST_QUIT_MAIN = -99
> Const ForReading = 1
> Set fso = WScript.CreateObject("Scripting.FileSystemObject")
> Set Nwrk = WScript.CreateObject("WScript.Network")
> Set WshShell = WScript.CreateObject("WScript.Shell")
> Lcomputer = Nwrk.ComputerName
> Verify = 0
>
> VsInst80 = fso.FileExists("C:\Programs\Networ~1\VirusScan\Mcshield.exe")
> If verify = "1" then WScript.Echo "vsinst80 = " & vsinst80 Else
> WScript.Echo "vsinst80 = " & vsinst80 End If
>
>
> VsInst85 = fso.FileExists("C:\Programs\Mcafee\VirusScan\Mcshield.exe")
> If verify = "1" then WScript.Echo "vsinst85 = " & vsinst85 Else
> WScript.Echo "vsinst85 = " & vsinst85 End If
>
>
> If vsinst80 = False Then
> GetMessage(1)
> End If
> If vsinst85 = False Then
> GetMessage(1)
> End If
Download and consult the file script56.chm for full details on the Select
statement. By the way - while you're developing and debugging your code you
should remove the "on error resume next" statement. Its presence makes the
debugging effort much, much harder because it will hide errors.



My System SpecsSystem Spec
Old 04-16-2009   #2 (permalink)
Al Dunbar


 
 

Re: Select case question


"Jack" <j.baltus@xxxxxx> wrote in message
news:41b96$49e772f2$5ed32516$8586@xxxxxx
Quote:

> Can anybody help me with a script
> I want if a one file exist then go to a select statement, and do somthing
> But i don`t no how
It is difficult to write code when the solution does not follow more or less
automatically from the description of the problem. It also seems to me that
you are confusing what you want as a result with how you think it might be
coded.
Quote:

> Option Explicit
> On Error Resume Next
> Dim arrScript, Array1, BtnCode, WshShell, FileName, FVersion, Script
> Dim Lcomputer, Msg, McShieldPath, NewDATVer, Nwrk, path, f,
> StartDir,sfncLib
> Dim OldDatVer, strDC, strVersion, sVirDefVer, verify, RegistryValue,
> VsInst80, VsInst85
> Dim strNextLine, Lineread, sTmpDir, Arraystr, infile, objTextFile,
> scommand
> Dim fso:
> CONST CONST_QUIT_MAIN = -99
> Const ForReading = 1
> Set fso = WScript.CreateObject("Scripting.FileSystemObject")
> Set Nwrk = WScript.CreateObject("WScript.Network")
> Set WshShell = WScript.CreateObject("WScript.Shell")
> Lcomputer = Nwrk.ComputerName
> Verify = 0
>
> VsInst80 = fso.FileExists("C:\Programs\Networ~1\VirusScan\Mcshield.exe")
in this if-else-endif block:
Quote:

> If verify = "1" then WScript.Echo "vsinst80 = " & vsinst80 Else
> WScript.Echo "vsinst80 = " & vsinst80 End If
The FileExists method returns a boolean value, i.e. one which is either true
or false. The fact that the false and true values are represented by
quantites that can be compared to some numeric equivalents (or their string
equivalents) is a red herring of no value. In fact you have it wrong here as
verify will never have the value 1. Although a value of 1 is treated as true
when cast to a boolean, when a truly boolean result is returned, a true
value will be represented as -1.

Instead of [if verify = "1"] I'd recommend you use [if verify].

But that is not the only problem here. The same statement is executed
regardles of the value being tested. You could as easily replace these
statements with:

WScript.Echo "vsinst80 = " & vsinst80

By a strange twist of fate, your incorrect method for testing for the
existence of a file is nullified by the fact that, in this case, it makes no
difference.
Quote:

> VsInst85 = fso.FileExists("C:\Programs\Mcafee\VirusScan\Mcshield.exe")
> If verify = "1" then WScript.Echo "vsinst85 = " & vsinst85 Else
> WScript.Echo "vsinst85 = " & vsinst85 End If
>
>
> If vsinst80 = False Then
better than comparing to zero, but better to use: [if not vsinst80 then]
Quote:

> GetMessage(1)
> End If
> If vsinst85 = False Then
> GetMessage(1)
> End If
As you have written it, GetMessage(1) will be called once, twice, or zero
times, depending on how many of the two files being tested are found to
exist. If you want to call it once if either exists, here is one way:

if ( (not vsinst80) or (not vsinst85) ) then
GetMessage(1)
End If

I see no need here for a select statement, why is it that you want to use
one?

/Al


My System SpecsSystem Spec
Old 04-19-2009   #3 (permalink)
Al Dunbar


 
 

Re: Select case question


"Jack" <j.baltus@xxxxxx> wrote in message
news:5b2d3$49e8c6b2$5ed32516$20914@xxxxxx
Quote:

> if you are interested in the hole script let me no
Not just yet. Your flowchart got mangled enough with linewrapping that, to
be honest, I cannot follow it any better than I can follow your first
attempt at explaining what your goal is.

Try it this way: just indicate what it is that you want to do depending on
which of the four possible combinations is in effect:

a) vsinst80 is false and vsinst85 is false:
b) vsinst80 is true and vsinst85 is false:
c) vsinst80 is false and vsinst85 is true:
d) vsinst80 is true and vsinst85 is true:

Also, it is not clear what is meant by msgbox getmessage(1).

If there are four completely different things to be done in the four cases,
the most straightyforward way to model this is:

if vsinst80 then
if vsinst85 then
' option "d"
else
' option "b"
end if
else
if vsinst85 then
' option "c"
else
' option "a"
end if
end if

If some of the combinations can never occur (i.e. if the installation of 85
uninstalls 80 such that both will never be simultaneously present) this can
be reduced to:

if vsinst80 then
if not vsinst85 then
' option "b"
end if
else
if vsinst85 then
' option "c"
else
' option "a"
end if
end if

A switch statement can sometimes result in more compact code, however,
should be avoided if the abstraction of it obscures the logic behind it,
i.e.:

ix = 0
if vsinst80 then ix = 1
if vsinst85 then ix = ix + 2
select case ix
case 0 : ' option "a"
case 1 : ' option "b"
case 2 : ' option "c"
case 3 : ' option "d"
end select

/Al
Quote:

> "Jack" <j.baltus@xxxxxx> schreef in bericht
> news:17c31$49e8c632$5ed32516$19009@xxxxxx
Quote:

>>I understand that, i have a schema what i want.
>>
>>
>>
>> If vsinst80 = true ------------ false
>> | |
>> | |
>> update if vsinst85=
>> true --------------------------false
>> Mcafeeversion80 | |
>> | |
>> update Mcafeeversion8.5 msgbox
>> GetMessage(1)
>>
>> you have no virusscanner installed
>>
>> "Al Dunbar" <alandrub@xxxxxx> schreef in bericht
>> news:O9GRv0vvJHA.5584@xxxxxx
Quote:

>>>
>>> "Jack" <j.baltus@xxxxxx> wrote in message
>>> news:41b96$49e772f2$5ed32516$8586@xxxxxx
>>>> Can anybody help me with a script
>>>> I want if a one file exist then go to a select statement, and do
>>>> somthing
>>>> But i don`t no how
>>>
>>> It is difficult to write code when the solution does not follow more or
>>> less automatically from the description of the problem. It also seems to
>>> me that you are confusing what you want as a result with how you think
>>> it might be coded.
>>>
>>>> Option Explicit
>>>> On Error Resume Next
>>>> Dim arrScript, Array1, BtnCode, WshShell, FileName, FVersion, Script
>>>> Dim Lcomputer, Msg, McShieldPath, NewDATVer, Nwrk, path, f,
>>>> StartDir,sfncLib
>>>> Dim OldDatVer, strDC, strVersion, sVirDefVer, verify, RegistryValue,
>>>> VsInst80, VsInst85
>>>> Dim strNextLine, Lineread, sTmpDir, Arraystr, infile, objTextFile,
>>>> scommand
>>>> Dim fso:
>>>> CONST CONST_QUIT_MAIN = -99
>>>> Const ForReading = 1
>>>> Set fso = WScript.CreateObject("Scripting.FileSystemObject")
>>>> Set Nwrk = WScript.CreateObject("WScript.Network")
>>>> Set WshShell = WScript.CreateObject("WScript.Shell")
>>>> Lcomputer = Nwrk.ComputerName
>>>> Verify = 0
>>>>
>>>> VsInst80 =
>>>> fso.FileExists("C:\Programs\Networ~1\VirusScan\Mcshield.exe")
>>>
>>> in this if-else-endif block:
>>>
>>>> If verify = "1" then WScript.Echo "vsinst80 = " & vsinst80 Else
>>>> WScript.Echo "vsinst80 = " & vsinst80 End If
>>>
>>> The FileExists method returns a boolean value, i.e. one which is either
>>> true or false. The fact that the false and true values are represented
>>> by quantites that can be compared to some numeric equivalents (or their
>>> string equivalents) is a red herring of no value. In fact you have it
>>> wrong here as verify will never have the value 1. Although a value of 1
>>> is treated as true when cast to a boolean, when a truly boolean result
>>> is returned, a true value will be represented as -1.
>>>
>>> Instead of [if verify = "1"] I'd recommend you use [if verify].
>>>
>>> But that is not the only problem here. The same statement is executed
>>> regardles of the value being tested. You could as easily replace these
>>> statements with:
>>>
>>> WScript.Echo "vsinst80 = " & vsinst80
>>>
>>> By a strange twist of fate, your incorrect method for testing for the
>>> existence of a file is nullified by the fact that, in this case, it
>>> makes no difference.
>>>
>>>> VsInst85 = fso.FileExists("C:\Programs\Mcafee\VirusScan\Mcshield.exe")
>>>> If verify = "1" then WScript.Echo "vsinst85 = " & vsinst85 Else
>>>> WScript.Echo "vsinst85 = " & vsinst85 End If
>>>>
>>>>
>>>> If vsinst80 = False Then
>>>
>>> better than comparing to zero, but better to use: [if not vsinst80 then]
>>>
>>>> GetMessage(1)
>>>> End If
>>>> If vsinst85 = False Then
>>>> GetMessage(1)
>>>> End If
>>>
>>> As you have written it, GetMessage(1) will be called once, twice, or
>>> zero times, depending on how many of the two files being tested are
>>> found to exist. If you want to call it once if either exists, here is
>>> one way:
>>>
>>> if ( (not vsinst80) or (not vsinst85) ) then
>>> GetMessage(1)
>>> End If
>>>
>>> I see no need here for a select statement, why is it that you want to
>>> use one?
>>>
>>> /Al
>>>
>>>
>>
>>
>
>


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Script that uses the DatePart & Case select VB Script
select case does not work ... why? VB Script
Logon script - function array and select case not working VB Script
Case/Select functionality PowerShell
select-string question 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