Windows Vista Forums

Re: Select case question
  1. #1


    Pegasus [MVP] Guest

    Re: Select case question


    "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
    >
    >
    >
    > 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

  2. #2


    Al Dunbar Guest

    Re: Select case question


    "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

  3. #3


    Al Dunbar Guest

    Re: Select case question


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

    > 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

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

    >>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

    >>>
    >>> "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

Re: Select case question problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie Question: Basic select-object Question. No Spam PowerShell 3 06 Oct 2009
Script that uses the DatePart & Case select David Rodriguez VB Script 0 16 Jul 2009
select case does not work ... why? Albert Andersson VB Script 1 17 Jun 2009
Logon script - function array and select case not working Nex6 VB Script 6 09 Jun 2009
Case/Select functionality LoneWolf PowerShell 7 25 Feb 2007