Hi everyone,
I want to find a string on another string, then i google code and copy it. After that i modify to suit my situation like this: - Public Function IsInArray(stringtocompare As Variant, valueToFind As Variant) As Boolean
-
On Error GoTo Err_F
-
' checks if valueToFind is found in arr, no loop!
-
If IsNull(stringtocompare) = False Then
-
IsInArray = False
-
Else
-
If stringtocompare = valueToFind Then
-
IsInArray = True
-
Else
-
If InStr(1, stringtocompare, ",", vbTextCompare) = 0 Then
-
IsInArray = False
-
Else
-
arrtocompare = Split(stringtocompare, ",")
-
IsInArray = (UBound(Filter(arrtocompare, valueToFind)) > -1)
-
End If
-
End If
-
End If
-
Exit_F:
-
Exit Function
-
Err_F:
-
MsgBox Err.Number & " " & Err.Description
-
Resume Exit_F
-
End Function
-
and when i run it inside an IIF function in expression of a query, the error " 94invalid use of null" keep appear...
What is my problem ? how can I fix this ?
please help me,
thank you.
5 1907 NeoPa 32,556
Expert Mod 16PB
I suspect line #4 should read : - If IsNull(stringtocompare) Then
well, thank NeoPa, but that's not correct, I figure out that link 4 incorrect, it should be "=True" to filter the null value out of formula behind it... still thank you.
NeoPa 32,556
Expert Mod 16PB
That seems to be a misunderstanding. Unless you're saying something different from what I understand you to be saying of course. It's not very clear as you've only put in a part of the line we're talking about.
If you mean that it should not be : - If IsNull(stringtocompare) Then
but should be : - If IsNull(stringtocompare) = True Then
instead, then I'd challenge you to test out your theory. From my perspective, and I have a certain amount of experience with such things, they would both give exactly the same result. The returned value of an IsNull() call can never be Null of course. The only difference being that the latter is a little more clumsy and says more than is required.
it did work mate, when the code run, first it filter out any null value as False value. then if field is not null, it run the code below it.
I have to code like that because not every stringtocompare field have value, some field is null, and it'll broken the code inside the 2nd "If".
and to introduce my code's target, it work like this
you set a field to compare that content some data (the ID that apply promote for example -ID promotion) like this "1,2,3,4,5,6,9" and some row are null, some row are 2,3,5 ; even a row with only 1 number "5"
now you have the ID on another table, and you want to check whether that ID have promotion or not, use my function
[ -
IsInArray(ID, ID promotion)
-
or
-
iif(IsInArray(ID, ID promotion)=True, 1, 0) to count
-
it'll give you the result very clearly, I think people searching for this code very much on internet, so It'll be helpfull here.
full code: - Public Function IsInArray(stringtocompare As Variant, valueToFind As Variant) As Boolean
-
On Error GoTo Err_F
-
' checks if valueToFind is found in arr, no loop!
-
If IsNull(stringtocompare) = True Then
-
IsInArray = False
-
Else
-
If stringtocompare = valueToFind Then
-
IsInArray = True
-
Else
-
If InStr(1, stringtocompare, ",", vbTextCompare) = 0 Then
-
IsInArray = False
-
Else
-
arrtocompare = Split(stringtocompare, ",")
-
IsInArray = (UBound(Filter(arrtocompare, valueToFind)) > -1)
-
End If
-
End If
-
End If
-
Exit_F:
-
Exit Function
-
Err_F:
-
MsgBox Err.Number & " " & Err.Description
-
Resume Exit_F
-
End Function
NeoPa 32,556
Expert Mod 16PB
There seems to be some confusion here.
I never said that your code wouldn't work. In fact, I stated quite clearly that, though it may be more clumsy than what I'd suggested, both would work in almost identical fashion.
My post was submitted because in your post #3 you stated that my suggestion wouldn't work. That is simply not the case. I would suggest that you be a little more careful how you express yourself publicly and be more precise in your claims.
If I need to repeat myself then I will. Both examples of code should work, however your code is less precise and indicates a lack of clear understanding of what's needed to work with boolean values (As opposed to an understanding one can get away with).
I don't say that to belittle you, as I understand better than most that working with Booleans is an area that almost everyone struggles with. Nevertheless, I think you should be more careful with such bold statements unless you have a much better understanding of what it is you're stating.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Frank Jones |
last post by:
When manually running resgen.exe from the command prompt (Visual Studio .NET
2003 command prompt) I get the following error:
error: Invalid ResX input.
error: Specific exception:...
|
by: bazley |
last post by:
I've been tearing my hair out over this:
#ifndef MATRIX2_H
#define MATRIX2_H
#include <QVector>
template<class T>
class Matrix2
{
public:
|
by: David Veeneman |
last post by:
This post is for the Google archive and does not require a reply.
I received an 'Invalid parameter used' error when trying to do
double-buffering with the .Net SetStyles method. I used this code...
|
by: CQ |
last post by:
Hi everyone,
I get the following error when compiling my code:
error: invalid initialization of non-const reference of type 'Vertex&'
from a temporary of type 'int'
The implementation of...
|
by: Eric |
last post by:
I run a program which read emails from a text file. There is some thing
invalid in one or more text file. When program is busy doing parsing it
shows that error and process stop. I dont know which...
|
by: The|Godfather |
last post by:
Hi everybody,
I read Scotte Meyer's "Effective C++" book twice and I know that
he mentioned something specific about constructors and destructors that
was related to the
following...
|
by: CyberSoftHari |
last post by:
Assembly assembly = Assembly.GetExecutingAssembly();
ResourceManager rm = new ResourceManager("NameSpace.Demo", assembly, null);
try
{
logo.Image =...
|
by: mahmoodn |
last post by:
Hi, I have a problem with a compiler error "invalid use of incomplete type". Here is the description:
in "first.h", I have:
class cache_t {
public:
virtual void printStats( pseq_t *pseq );...
|
by: Abest |
last post by:
I am trying to get my form to autofill the values from the last record to the new record. In the form properites on the BeforeInsert, I used the following module
I have been away from VB for...
|
by: tirupathiraov |
last post by:
I have set the prepared statement ResultSet.HOLD_CURSORS_OVER_COMMIT and the same thing working on one instace of DB2 and not working on other instance of DB2. what could be the problem?
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |