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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reducing script 1

Status
Not open for further replies.

terry712

Technical User
Oct 1, 2002
2,175
GB
since we have an issue enumerating recursively without case statements we currently have a large script that consists of a lot of type

If Instr(1, strGroups, "cn=edinburgh-finance-gls", 1) Then

WsHNetwork.MapNetworkDrive "y:", "\\server\shared"
End If

If Instr(1, strGroups, "cn=edinburgh-payroll-gls", 1) Then

WsHNetwork.MapNetworkDrive "y:", "\\server\shared"
End If

If InStr(1, strGroups, "cn=edinburgh-claims-gls", 1) Then

WsHNetwork.MapNetworkDrive "y:", "\\server\shared"

and then say similar for glasgow etc

can i reduce this by use of some kind of wildcard or that
ie edinburgh* so that i can just have one line

sorry afraid my vbs skills suck

 
[1] If you use instr(), in contrast with strcomp(), the the 2nd string part is automatically acquired a flavour of wildcard of its own in the form of *cn=edinburgh*. Hence, on the face of what posted, you can simply use it like what illustrated below. And it is viable because cn=edinburgh and cn=glasgow have nothing overlapping over the whole strgroup structure - this is a piece of private info independently assessed positive due to your specific spec of the ad design, not on the face of what shown.
[tt]
If Instr(1, strGroups, "cn=edinburgh", 1)Then
WsHNetwork.MapNetworkDrive "y:", "\\server\shared"
End If
If Instr(1, strGroups, "cn=glasgow", 1)Then
WsHNetwork.MapNetworkDrive "y:", "\\server2\shared"
End If
'etc
[/tt]
[2] If that part of signature pattern is more complex, such as not only cn=edinburgh matters, but that the suffix gls matters as well, then the above scheme would be insufficient. You then have to resort to regexp for better versatility. Such as this.
[tt]
set rx=new regexp
rx.ignorecase=true

rx.pattern="\bcn=edinburgh-\w+?gls\b"
if rx.test(sgroup) then
WsHNetwork.MapNetworkDrive "y:", "\\server\shared"
end if
rx.pattern="\bcn=edinburgh-\w+?gls2\b"
if rx.test(sgroup) then
WsHNetwork.MapNetworkDrive "y:", "\\server\shared2"
end if
rx.pattern="\bcn=glasgow-\w+?gls\b"
if rx.test(sgroup) then
WsHNetwork.MapNetworkDrive "y:", "\\server2\shared"
end if
rx.pattern="\bcn=glasgow-\w+?gls2\b"
if rx.test(sgroup) then
WsHNetwork.MapNetworkDrive "y:", "\\server2\shared2"
end if
'etc etc
[/tt]
That is the idea.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top