473,320 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

checking if value exists in array

hello

i am looking for a boolean function to be used like this:

Expand|Select|Wrap|Line Numbers
  1. if InArray(val,arr()) then
  2.     ' some code to run if the value "val" exists in one of the posts of the array "arr"
  3. else
  4.     ' some code to run if it doesn't
  5. end if
i guess i could write my own function where i loop through the array and look for the value, and if found i return true - but then i'd have to write a new version for each type i want to use (i.e. one for file arrays, one for string arrays etc.) is there a more efficient way?
Nov 9 '07 #1
2 13548
debasisdas
8,127 Expert 4TB
Have you tried using ISNULL() .
Nov 9 '07 #2
Have you tried using ISNULL() .
isnull() would not give me an answer to my question. i clarify with an example:

i have a string array, arrStrings(), containing five different strings. i have a variable, strValue, containing a value i want to test for. what i want is a function that, regardless of the data types (in this case string), can return to me whether or not strValue is exactly the same as any one or more of the elements in arrStrings().

A function to do what i want for strings would be this:

Expand|Select|Wrap|Line Numbers
  1. Function InStrArray(val as string, arr() as string)
  2.    InStrArray = False
  3.  
  4.    dim i as integer
  5.    for i = lbound(arr) to ubound(arr)
  6.        if arr(i) = value then InStrArray = True
  7.    next
  8. End Function
I want to do the same, but regardless of datatypes. That is, I want to be able to use my function on string arrays as well as file, control and other arrays.
Nov 9 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Wendy S | last post by:
I have this working, but I don't think it's done efficiently or the best way: <a href="javascript:setAllAccounts(true)">check all</a> <a href="javascript:setAllAccounts(false)">clear all</a> ...
5
by: CJM | last post by:
In an application I'm working the user has the opportunity to record the despatching of one or more items with serial numbers. For each item they despatch, they have to chose the serial no that...
14
by: Kayle | last post by:
How should we check if the '\0' characters exists in the string as I am confused that some books mentioned that we have to check whether we need to make sure that we pass the...
99
by: Mikhail Teterin | last post by:
Hello! Consider the following simple accessor function: typedef struct { int i; char name; } MY_TYPE; const char *
4
by: Darrel | last post by:
I'm trying to add an extra layer of error checking on a Drop Down List. The list is populated from one table, and then I select the selectedValue from another DB. While it SHOULDN'T ever happen,...
9
by: Amit Bhatnagar | last post by:
An array has a majority element if there exists an element whose frequency is more than (N/2 +1 ) where N is the number of elemnts in array.. We need to write a program to find the majority elemnt...
8
by: Fuzzydave | last post by:
Okay, I have been handed a python project and working through it I have had to add a report. I am returning 10 variables the results of an SQL Query and as usual the number of results vary from...
4
by: chinu | last post by:
HI all, i am declaring an array in javascript var a = new array(); now before assigning a value to the ith element of this array, i have to check if some value has already been assigned there....
125
by: jacob navia | last post by:
We hear very often in this discussion group that bounds checking, or safety tests are too expensive to be used in C. Several researchers of UCSD have published an interesting paper about this...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.