Stackie
Stackie

Reputation: 3

Finding IP match through VBScript

I have an array

arrIP={"10","144","26,"0"}
and another array
arrItc={"10","126","0","0"}

I want to check the equality of the first three values and return a boolean if all the three are equal

Upvotes: 0

Views: 73

Answers (2)

Panayot Karabakalov
Panayot Karabakalov

Reputation: 3179

One more idea to test.

a1 = Array("10", "144", "26", "0")
a2 = Array("10", "126", "0", "0")
a3 = Array("10", "144", "26", "1")

a1(UBound(a1)) = ""
a2(UBound(a2)) = ""
a3(UBound(a3)) = ""

WScript.Echo "a1=a2 ? " & (Join(a1) = Join(a2))
WScript.Echo "a2=a3 ? " & (Join(a2) = Join(a3))
WScript.Echo "a1=a3 ? " & (Join(a1) = Join(a3))

'Result:

a1=a2 ? False
a2=a3 ? False
a1=a3 ? True

Upvotes: 0

Ekkehard.Horner
Ekkehard.Horner

Reputation: 38765

Use a boolean expression or a loop:

Option Explicit

Dim aTests : aTests = Array( _
    Split("10 144 26 0") _
      , Split("10 144 26 0") _
      , Split("10 144 26 1") _
      , Split("10 144 27 0") _
      , Split("10 145 26 0") _
      , Split("11 144 26 0") _
)
Dim nTest
For nTest = 1 To UBound(aTests)
    WScript.Echo Join(aTests(0)), "?", Join(aTests(nTest)), CStr(cmp3(aTests(0), aTests(nTest)))
Next

Function cmp3(aL, aR)
  cmp3 = aL(0) = aR(0) And aL(1) = aR(1) And aL(2) = aR(2) 
End Function

Function cmp3(aL, aR)
  cmp3 = False 
  Dim i
  For i = 0 To 2
      If aL(i) <> aR(i) Then Exit Function
  Next
  cmp3 = True 
End Function

output:

10 144 26 0 ? 10 144 26 0 Wahr
10 144 26 0 ? 10 144 26 1 Wahr
10 144 26 0 ? 10 144 27 0 Falsch
10 144 26 0 ? 10 145 26 0 Falsch
10 144 26 0 ? 11 144 26 0 Falsch

Upvotes: 1

Related Questions