473,699 Members | 2,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you check a value exists in an array?

Using ASP with VBScript is there a clever way to easily check if a value
exists in an array without looping through it?

Steve
Jan 17 '08 #1
10 41165
Dooza wrote:
Using ASP with VBScript is there a clever way to easily check if a
value exists in an array without looping through it?
No

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jan 17 '08 #2
Bob Barrows [MVP] wrote:
Dooza wrote:
>Using ASP with VBScript is there a clever way to easily check if a
value exists in an array without looping through it?
No
I thought as much, just wanted to double check. Thanks Bob.

Steve
Jan 17 '08 #3
"Dooza" <st*****@SPAM.d ooza.tvwrote in message
news:OI******** ******@TK2MSFTN GP06.phx.gbl...
Using ASP with VBScript is there a clever way to easily check if a value
exists in an array without looping through it?
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,st rVAL) 0 Then
WScript.Echo "'" & cVAL & "' found."
Else
WScript.Echo "'" & cVAL & "' not found."
End If


Jan 17 '08 #4
"McKirahan" <Ne**@McKirahan .comwrote in message
news:Wo******** *************** *******@comcast .com...
"Dooza" <st*****@SPAM.d ooza.tvwrote in message
news:OI******** ******@TK2MSFTN GP06.phx.gbl...
Using ASP with VBScript is there a clever way to easily check if a value
exists in an array without looping through it?

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,st rVAL) 0 Then
WScript.Echo "'" & cVAL & "' found."
Else
WScript.Echo "'" & cVAL & "' not found."
End If
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.
--
Anthony Jones - MVP ASP/ASP.NET
Jan 17 '08 #5
Anthony Jones wrote:
"McKirahan" <Ne**@McKirahan .comwrote in message
news:Wo******** *************** *******@comcast .com...
>"Dooza" <st*****@SPAM.d ooza.tvwrote in message
news:OI******* *******@TK2MSFT NGP06.phx.gbl.. .
>>Using ASP with VBScript is there a clever way to easily check if a
value exists in an array without looping through it?

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,st rVAL) 0 Then
WScript.Echo "'" & cVAL & "' found."
Else
WScript.Echo "'" & cVAL & "' not found."
End If

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.
I would have thought the impact of string conversion and concatentation
would be intolerable. To the OP: looping through an array is fast
(especially if the contents are sorted so unsuccessful searches can be
aborted early), so why look for an alternative?

--
Anthony Jones - MVP ASP/ASP.NET
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jan 17 '08 #6
Bob Barrows [MVP] wrote:
>>Another would be to not use an array but a Dictionary.
I think I am restricted to whatever ADSI gives me, but I could be
wrong. See my code somewhere above.
? There is nothing restricting you to using an array vs. a Dictionary.
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?

Steve
Jan 17 '08 #7
Dooza wrote:
Bob Barrows [MVP] wrote:
>>>Another would be to not use an array but a Dictionary.

I think I am restricted to whatever ADSI gives me, but I could be
wrong. See my code somewhere above.
? There is nothing restricting you to using an array vs. a
Dictionary.

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?
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.

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jan 17 '08 #8
"Bob Barrows [MVP]" <re******@NOyah oo.SPAMcomwrote in message
news:uK******** ******@TK2MSFTN GP02.phx.gbl...
Anthony Jones wrote:
"McKirahan" <Ne**@McKirahan .comwrote in message
news:Wo******** *************** *******@comcast .com...
"Dooza" <st*****@SPAM.d ooza.tvwrote in message
news:OI******** ******@TK2MSFTN GP06.phx.gbl...
Using ASP with VBScript is there a clever way to easily check if a
value exists in an array without looping through it?

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,st rVAL) 0 Then
WScript.Echo "'" & cVAL & "' found."
Else
WScript.Echo "'" & cVAL & "' not found."
End If
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.
I would have thought the impact of string conversion and concatentation
would be intolerable.
Join is somewhat more effecient at contentation but its a good point it
probably would be a killer.

--
Anthony Jones - MVP ASP/ASP.NET
Jan 17 '08 #9
"Dooza" <st*****@SPAM.d ooza.tvwrote in message
news:e6******** ******@TK2MSFTN GP06.phx.gbl...
McKirahan wrote:
"Dooza" <st*****@SPAM.d ooza.tvwrote in message
news:OI******** ******@TK2MSFTN GP06.phx.gbl...
Using ASP with VBScript is there a clever way to easily check if a
value
exists in an array without looping through it?
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,st rVAL) 0 Then
WScript.Echo "'" & cVAL & "' found."
Else
WScript.Echo "'" & cVAL & "' not found."
End If

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
<snip>

Its doubtful that the set of groups for user would be large. You're also
testing for multple values in a single loop which makes good use of the
loop. I would say your done here move on.

--
Anthony Jones - MVP ASP/ASP.NET
Jan 17 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
10052
by: dixie | last post by:
I am trying to write some VBA that can check if a certain value exists in a field in a table. The field is a text field. The table is not a part of the query that forms the recordsource of the form on which I am trying to do this. I wish to act on the presence (or absence) of this value. What I am doing is trying to have a generic password form such that when you click a button to open the next form, the code checks if there is a letter...
1
2820
by: James | last post by:
vb.net 2003 i wrote a windows service that does threading. My codes are a) the service thread will read a list of machine from a text file (machines.txt). b) it then logon using the below Dim returnValue As Boolean = LogonUser(m_ntid, m_domain, m_pwd, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, tokenHandle)
2
2001
by: Ros | last post by:
Peeps, I need help with trying to find a value in array of arrays. Public Module myModule Private Site_Access() As Array Property Set_SA() Get Return Site_Access End Get
10
1405
by: codefire | last post by:
Hi, I have some simple code - which works...kind of..here's the code: import os def print_tree(start_dir): for f in os.listdir(start_dir): fp = os.path.join(start_dir, f)
5
27444
by: =?Utf-8?B?QnJlbmRlbiBCaXhsZXI=?= | last post by:
Hello. I am reading a value from a table and trying to determine if that value exists in a list of values associated with a dropdownlist. If so, I select the value, otherwise, I don't. I haven't been able to figure this operation out so far. Code: if (reader != System.DBNull.Value)
2
2103
by: causesdrowsiness | last post by:
Hi everyone. Sorry if this is the wrong group for this question, but since it is .NET and VB, I thought someone may be able to help me here or point me to the right group for this. I am working on an application which needs to check if a certain VALUE exists in a registry subkey. Is there an easy way to do this? So far, my googles have come up empty on this, though they DO have a plethora of information on checking if a KEY exists.
2
1837
by: priyanka1915 | last post by:
helloo, I have to retrive the data from database and then check that value my column in database is CATEGORY ------------------------------- COMMODITY COMMODITY COMMODITY
2
9831
Manikgisl
by: Manikgisl | last post by:
HI. How to check File exists in Web Share C# try { WebRequest request = HttpWebRequest.Create("http://www.microsoft.com/NonExistantFile.aspx"); request.Method = "HEAD"; // Just get the document headers, not the data. request.Credentials = System.Net.CredentialCache.DefaultCredentials; // This may throw a WebException:
2
14655
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how can I pass null value as parameter to the database stored procedure programattically using C#? Although I can check for empty column (the following code passes string.Empty as parameter but how to pass null value?), I cannot check for null value...
0
8687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8617
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8884
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7751
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6534
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4376
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.