Jump to content

My favorite oddball behaviour: Incorrect vars being set


 Share

Recommended Posts

Every now and then I run into this situation where I am looking at a var and then setting another var, and then for whatever reason it sets the wrong var. I'm fairly sure I've posted at least one topic like this before and it is also likely that I'm making a dumb mistake. I've tried this three different ways, the wrong way, the right way and another right way but the behaviour is the same each time.

The original wrong way:

$dGateway1 = FileReadLine ( $oDgdat , 2 ) ; read dg from file
$dGateway2 = StringRegExpReplace($dGateway1 , "[{"& Chr(34) &"}]" , "")

If $dGateway2 = "10.x.1.1" OR "10.x.2.1" THEN
    $ImageServer = "Server1"
ElseIf $dGateway2 = "10.x.3.1" OR "10.x.4.1" THEN
    $ImageServer = "Server2"
ElseIf $dGateway2 = "10.x.5.1" OR "10.x.6.1" THEN
    $ImageServer = "Server3"
EndIf

Recreation should be simple enough. I have verified that the data in $dGateway2 is valid via MsgBox and this is working as expected. Could easily just hardcode $dGateway2 to something. I don't think the fact I am reading it from a text file makes a difference.

Now in this "wrong" method, what happens is that when on the 1.1 or 2.1 network, $ImageServer var = Server1, as expected. This led me to skip past this and do the rest of the script. After thinking it was working properly, I didn't notice that it wasn't until I tried on the 4.1 network. In that case, $ImageServer also was Server1 when it shouldn't. Remembering that this is the inappropriate use of OR in the If statement, I made it (seemingly) foolproof:

If $dGateway2 = "10.x.1.1" THEN
    $ImageServer = "Server1"
ElseIf $dGateway2 = "10.x.2.1" THEN
    $ImageServer = "Server1"
ElseIf $dGateway2 = "10.x.3.1" THEN
    $ImageServer = "Server2"    
ElseIf $dGateway2 = "10.x.4.1" THEN
    $ImageServer = "Server2"
ElseIf $dGateway2 = "10.x.5.1" THEN
    $ImageServer = "Server3"
ElseIf $dGateway2 = "10.x.6.1" THEN
    $ImageServer = "Server3"
EndIf

And still the same. The 4.1 network was putting Server1 as the var for $ImageServer. So then I tried something else:

Select
    Case StringStripWS($dGateway2 = "10.x.1.1",8)
        $ImageServer = "Server1"
    Case StringStripWS($dGateway2 = "10.x.2.1",8)
        $ImageServer = "Server1"
    Case StringStripWS($dGateway2 = "10.x.3.1",8)
        $ImageServer = "Server2"
    Case StringStripWS($dGateway2 = "10.x.4.1",8)
        $ImageServer = "Server2"
    Case StringStripWS($dGateway2 = "10.x.5.1",8)
        $ImageServer = "Server3"
    Case StringStripWS($dGateway2 = "10.x.6.1",8)
        $ImageServer = "Server3"
    Case Else
        MsgBox (0,"Error","Gateway is: " & StringStripWS($dGateway2,8) & ". ImageServer is: " & $ImageServer & ".")
EndSelect

It does match to a case and doesn't fail over to the MsgBox. It seems no matter which value is in $dGateway2 it is setting $ImageServer var to Server1.

All of the vars are declared as global prior to their use. Code is being run in 64bit compiled .exe.

Hopefully someone can point out my error.

Link to comment
Share on other sites

#1 should be :

If $dGateway2 = "10.x.1.1" OR $dGateway2 = "10.x.2.1" THEN
    $ImageServer = "Server1"
ElseIf....

#2 should work

#3 should be :

Select
    Case StringStripWS($dGateway2, 8) = "10.x.1.1"
        $ImageServer = "Server1"
    Case....

 

Link to comment
Share on other sites

  • Developers

Nah ...  that is only true for public ranges but doesn't count for the private  none routable ranges :

  • Class A : 10.0. 0.0 — 10.255. 255.255.
  • Class B : 172.16. 0.0 — 172.31. 255.255.
  • Class C :  192.168. 0.0 — 192.168. 255.255.

Jos :) 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...