Home > Archive > Visual Basic Syntax > March 2006 > Help with Select Case
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Help with Select Case
|
|
| Phillop 2006-03-07, 7:57 am |
| Hi there im looking for some help with a problem using select case.
I am trying to establish whether an IP address I have captured from the
Win32_NetworkAdapterConfiguration lies between a certain IP range and am
trying to use select case as there are a number of ranges that I wish to test
for, the only problem I seem to be having is that i'm unable to say >=
"10.168.10.10" AND <= "10.168.10.50"
The script below is what i'm trying to work out.
Any assistance would be appreciated.
Option Explicit
Dim sDomain
Dim sUser
Dim oNet
Dim oShell
Dim oWMIService
Dim oIPConfigSet
Dim sIPConfig
Dim sIPAddress
Dim iCount
Dim sComputer
On Error Resume Next
sDomain = "DomainA"
sComputer = "."
Set oNet = CreateObject("WScript.Network")
Set oShell = WScript.CreateObject("WScript.Shell")
Set oWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
Set oIPConfigSet = oWMIService.ExecQuery("Select * from
Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each sIPConfig in oIPConfigSet
If Not IsNull(sIPConfig.IPAddress) Then
For iCount=LBound(sIPConfig.IPAddress) to UBound(sIPConfig.IPAddress)
sIPAddress = sIPConfig.IPAddress(iCount)
wscript.echo sIPAddress
Select Case (sIPAddress)
Case >= "10.168.10.10" And <= "10.168.10.50"
msgbox "Found it on ScopeA" , 0, "Find?"
Case sipaddress = "10.168.10.51" And <= "10.168.10.100"
msgbox "Found it on ScopeB" , 0, "Find?"
End Select
Next
End If
Next
| |
| Larry Serflaten 2006-03-07, 7:57 am |
|
"Phillop" <Phillop@discussions.microsoft.com> wrote
> Hi there im looking for some help with a problem using select case.
You need to post your question to a group where they discuss the
language you want to use. VBScript is not the same language as
Visual Basic which is what all the microsoft.public.vb.* groups
serve.
You may have better luck posting to a group like:
microsoft.public.wmi.programming
But, if you get no other replies, try converting your Select/Case
to all If/Then commands....
HTH
LFS
| |
| Phillop 2006-03-07, 7:57 am |
| Thanks Larry,
I'll give the microsoft.public.wmi.programming group a go.
Cheers
Phill
"Larry Serflaten" wrote:
>
> "Phillop" <Phillop@discussions.microsoft.com> wrote
>
> You need to post your question to a group where they discuss the
> language you want to use. VBScript is not the same language as
> Visual Basic which is what all the microsoft.public.vb.* groups
> serve.
>
> You may have better luck posting to a group like:
>
> microsoft.public.wmi.programming
>
> But, if you get no other replies, try converting your Select/Case
> to all If/Then commands....
>
>
> HTH
> LFS
>
>
>
| |
|
| Phillop wrote:
> Hi there im looking for some help with a problem using select case.
>
> I am trying to establish whether an IP address I have captured from the
> Win32_NetworkAdapterConfiguration lies between a certain IP range and am
> trying to use select case as there are a number of ranges that I wish to test
> for, the only problem I seem to be having is that i'm unable to say >=
> "10.168.10.10" AND <= "10.168.10.50"
>
> The script below is what i'm trying to work out.
>
> Any assistance would be appreciated.
>
> Option Explicit
>
> Dim sDomain
> Dim sUser
> Dim oNet
> Dim oShell
> Dim oWMIService
> Dim oIPConfigSet
> Dim sIPConfig
> Dim sIPAddress
> Dim iCount
> Dim sComputer
>
>
> On Error Resume Next
>
> sDomain = "DomainA"
> sComputer = "."
>
> Set oNet = CreateObject("WScript.Network")
> Set oShell = WScript.CreateObject("WScript.Shell")
> Set oWMIService = GetObject("winmgmts:" &
> "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
> Set oIPConfigSet = oWMIService.ExecQuery("Select * from
> Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
>
> For Each sIPConfig in oIPConfigSet
> If Not IsNull(sIPConfig.IPAddress) Then
> For iCount=LBound(sIPConfig.IPAddress) to UBound(sIPConfig.IPAddress)
> sIPAddress = sIPConfig.IPAddress(iCount)
> wscript.echo sIPAddress
> Select Case (sIPAddress)
> Case >= "10.168.10.10" And <= "10.168.10.50"
> msgbox "Found it on ScopeA" , 0, "Find?"
> Case sipaddress = "10.168.10.51" And <= "10.168.10.100"
> msgbox "Found it on ScopeB" , 0, "Find?"
> End Select
> Next
> End If
> Next
Note I'm not a VBScript programmer, but I think that if you want to do
some arithmetic, you'll have to use numbers, not strings.
If you know that dotted IP-addresses in fact are 32-bit numbers, you can
convert the IP-address to a 32-bit number.
I don't know if the Split()-function is available in VBScript, if so you
can convert the dotted IP-address into a 32-bit number like this:
Dim sIP() As String
Dim cIP As Currency
sIP = Split(sIPAddress, ".")
cIP = (((sIP(0) * 256 + sIP(1)) * 256) + sIP(2)) * 256 + sIP(3)
Note that I use a Currency variable to avoid 32-bit Signed/Unsigned issues.
The Lower and Upper Bound IP can be hard coded 32-bit.
Another approach: convert the dotted IP so every part consists of 3
digits (10.168.10.10 -> 010.168.010.010) and remove the dots (->
1016801010). The resulting string can be interpreted as a number you can
use to do the comparisons with.
Sinna
|
|
|
|
|