Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ElseIf with Multiple conditionals

Status
Not open for further replies.

dkel22

Programmer
Mar 31, 2004
49
US
In our Company they have added another division which has thrown off our user provisioning. I have just been thrown the project being that are previous Script Admin is gone, so I am not the best with vbscript. Below is the code segment which will grab the division ID and if it equals X and the user is active it will continue. Now I want to update the code to check for X or Y and if user is active then continue. I have tried several fixes but they either pull only X or only Y. Thanks in advance for the help!


ElseIf Left(DivisionValue,2) = "X" AND StatusValue = "Active" Then
Set rootDSE = GetObject("LDAP://RootDSE")
DomainContainer = rootDSE.Get("defaultNamingContext")
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ADSDSOObject"
conn.Open "ADs Provider"
ldapStr = "<LDAP://" & DomainContainer & ">;(&(objectClass=user)(objectCategory=person)(info=EmpId:" & keyValue & "));adspath;subtree"
Set rs = conn.Execute(ldapStr)



While Not rs.EOF
'Do nothing but iterate since they are already in AD.
Set FoundObject = GetObject (rs.Fields(0).Value)
rs.MoveNext
 


hi,

1. this equality will ALWAYS be false
Code:
Left(DivisionValue,2) = "X"
2. where is your OR test?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
You wanted this ?
ElseIf (Left(DivisionValue,2) = "X" OR Left(DivisionValue,2) = "Y" ) AND StatusValue = "Active" Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 


I should have quallified my allegation that IF Len(DivisionValue)>1 Then the equality will ALWAYS be false.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Ok it seems to be working fine with

ElseIf (Left(DivisionValue,2) = "X" OR Left(DivisionValue,2) = "Y" ) AND StatusValue = "Active" Then

But when I try to run a script to pull everyone else with (per below) it is still grabbing users with division 40 and 41 with everyone else. How do I now run a script that will exclude only division X and Y, now that my script to only include X and Y seems to be working.

ElseIf (Left(DivisionValue,2) <> "X" OR Left(DivisionValue,2) <>"Y" ) AND StatusValue = "Active" Then

 
ElseIf Left(DivisionValue,2) <> "X" AND Left(DivisionValue,2) <>"Y" AND StatusValue = "Active" Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Consider that the code checks if the left two characters of DivisionValue = "X" or "Y" - both of which are one character long. As SkipVought pointed out, the condition is ALWAYS be false.

ElseIf (Left(DivisionValue,[red]1[/red]) = "X" OR Left(DivisionValue,[red]1[/red]) <> "Y") AND StatusValue = "Active" Then

-Geates


"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Wouldn't a Select Case be more appropriate and/or easier to manage/read?

Something like...
Code:
Select Case lcase((Left(DivisionValue,1))
    Case "x","y"
        If StatusValue = "Active" then
            'Do what you got to do
        End If
    Case "z"
        If StatusValue = "Active" then
            'Do what you got to do
        End If
End Select

JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, or photo, or breakfast...and so on)[/small]
 
SkipVought / Geates:

Technically, no, the condition Left(DivisionValue,2) = "X" will not always be false. Try it:

Code:
DivisionValue = "X"
If Left(DivisionValue,2) = "X" Then
   wscript.echo "True"
else
   wscript.echo "False"
end if

Admittedly, that line of code is awkward but I could see it being useful, perhaps in a subroutine where the second string is a variable and not a hard-coded to "X".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top