D
Dooza
Using ASP with VBScript is there a clever way to easily check if a value
exists in an array without looping through it?
Steve
exists in an array without looping through it?
Steve
NoDooza said:Using ASP with VBScript is there a clever way to easily check if a
value exists in an array without looping through it?
McKirahan said:If it's a one dimensional array you could try:
Const cVAL = "your_value"
Dim strVAL
strVAL = vbTab & cVAL & vbTab
Dim strARR
strARR = vbTab & Join(your_array,vbTab) & vbTab
If InStr(strARR,strVAL) > 0 Then
WScript.Echo "'" & cVAL & "' found."
Else
WScript.Echo "'" & cVAL & "' not found."
End If
McKirahan said:If it's a one dimensional array you could try:
Const cVAL = "your_value"
Dim strVAL
strVAL = vbTab & cVAL & vbTab
Dim strARR
strARR = vbTab & Join(your_array,vbTab) & vbTab
If InStr(strARR,strVAL) > 0 Then
WScript.Echo "'" & cVAL & "' found."
Else
WScript.Echo "'" & cVAL & "' not found."
End If
Dooza said:Using ASP with VBScript is there a clever way to easily check if a value
exists in an array without looping through it?
Anthony said:Another alternative would be available if the contents of the array is
ordered. If so then a binary search would be much quicker on anything but a
very small array.
Another would be to not use an array but a Dictionary.
I would have thought the impact of string conversion and concatentationAnthony said:An interesting solution. Arguably that is two loops one peformed by
the join and the second by the instr but since both 'loops' in
compiled code that would well be faster than an basic For loop in
VBScript but I doubt it, I'll have to test that.
? There is nothing restricting you to using an array vs. a Dictionary.Dooza said:I think I am restricted to whatever ADSI gives me, but I could be
wrong. See my code somewhere above.
Bob said:? There is nothing restricting you to using an array vs. a Dictionary.
You could store an array of the group members, i.eDooza said:A dictionary allows me to use name/value pairs, is that right? I am
only needing the name of the group that the user is a member of, what
would I use as the pair?
Bob Barrows said:I would have thought the impact of string conversion and concatentation
would be intolerable.
Dooza said:I am using ADSI on our intranet, and only want to show certain users
certain menu items.
What I have done is this:
<%
Dim groupIT
Dim groupSALES
Dim groupACCOUNTS
Dim groupADMIN
For Each objGroup In ObjUser.Groups
If objGroup.Name = "IT" Then groupIT = 1
If objGroup.Name = "UK Sales" Then groupSALES = 1
If objGroup.Name = "Accounts" Then groupACCOUNTS = 1
If objGroup.Name = "Domain Admins" Then groupADMIN = 1
Next
Bob said:You could store an array of the group members, i.e
key: groupname
value: array of group members
I'm not saying this the correct way to do this: simply offering an
alternative.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.