Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


if statement within for loop

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,33424
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> if statement within for loop
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 if statement within for loop - 4/12/2006 2:01:26 AM   
  y2k

 

Posts: 2
Score: 0
Joined: 4/12/2006
Status: offline
I'm pretty new to all this.  What I need to do is create an array of subnets, and if the IP address is not in a particular subnet then basically to exit the script.  I've got most of it done, I just need to loop through the array of subnets and then do an if on each element in the array.  Here's a code snipet:
      
It's grabbing the IP address fine and diong the subnet thing.  All I need to do is loop through the allowedSubnets array and compared each iteration to the subnet variable.  I've got it doing the loop, bu not the if statment.  Do I need to do something like for i < allowedSubnets.elements.count blah blah blah ??
 
 
Post #: 1
 
 RE: if statement within for loop - 4/12/2006 2:07:28 AM   
  ebgreen


Posts: 5070
Score: 31
Joined: 7/12/2005
Status: online
If I understand your situation correctly, then try this to see if it does what you want:

function checkSubnet()
   ip = GetIPAddress
   iparray = Split(ip, ".")
   iparray(3)="0"
   subnet = join(iparray,".")
   objWshShell.Popup subnet
   ' Now loop through the subnets and see if the logon script should run
   bIsAllowed = False
   For Each objItem in allowedSubnets
       If subnet = allowedSubnets Then
           bIsAllowed = True
       End If
   Next
    If Not bIsAllowed Then
      objWshShell.Popup "You are not permitted to map drives from this network"
   End If

end function

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to y2k)
 
 
Post #: 2
 
 RE: if statement within for loop - 4/12/2006 2:20:31 AM   
  y2k

 

Posts: 2
Score: 0
Joined: 4/12/2006
Status: offline
Um ... no, not quiet !!  allowedSubnets is an array, which I declared at the start of the script.  So I have
Dim allowedSubnets(2)
allowedSubnets(0) = "10.128.0.0"
allowedSubnets(1) = "10.129.0.0"

So with this line:
For Each objItem in allowedSubnets
...
Next

I was able to loop through the allowedSubnets array.  But then I need to do an if statement on that particular iteration to find out if the subnet variable (which is the user's subnet) is equal to that particular iteration.  If it is, then eventually I will just set a variable to True similar to what you've done (I was just putting in the popups for debugging purposes).  But my if statement just says
If subnet = allowedSubnets Then
...
End If

I think it needs to say something like
If subnet = allowedSubnets(i) Then
...
End If
where i would be the iteration of allowedSubnets (so in this case either 0 or 1 because there's only 2 elements in the array).  Does all this make sense?  So escentailly I need to reference the current iteration, but maybe to do that I need to change my for loop to say For i = allowedSubnets.elements.count - or something like that, yes?? no?? any ideas??

Thanks in advance

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: if statement within for loop - 4/12/2006 2:23:20 AM   
  ebgreen


Posts: 5070
Score: 31
Joined: 7/12/2005
Status: online
Ooops...use this:

If subnet = objItem Then

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to y2k)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> if statement within for loop Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts