Link to home
Start Free TrialLog in
Avatar of David Regev
David Regev

asked on

Convert Case To if Statement on vbscript

Hi

how can i convert this script from case to If


Option Explicit
On Error Resume Next

Select Case DefaultGateway
       
        Case "10.2.254.1"
                'Do something
        Case "10.3.254.1"
                'Do something
        Case "10.4.254.1"
                'Do something
        Case "10.5.254.1"
                'Do something
        Case "10.6.254.1"
                'Do something
End Select

Function DefaultGateway
        DefaultGateway = Empty
        Dim oDG, oDGs, WMI
        Set WMI = GetObject("winmgmts:\\.\root\cimv2")          
        Set oDGs = WMI.ExecQuery _          
        ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
        For Each oDG In oDGs
                If Not IsNull(oDG.DefaultIPGateway) Then
                If Not oDG.defaultIPGateway(0) = "0.0.0.0" Then
                DefaultGateway = oDG.DefaultIPGateway(0)
                        Exit For
                        End If
                        End If
        Next
End Function
ASKER CERTIFIED SOLUTION
Avatar of Joe Howard
Joe Howard
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial