473,394 Members | 1,700 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,394 software developers and data experts.

error 94 invalid use of null

215 128KB
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:

Expand|Select|Wrap|Line Numbers
  1. Public Function IsInArray(stringtocompare As Variant, valueToFind As Variant) As Boolean
  2. On Error GoTo Err_F
  3. ' checks if valueToFind is found in arr, no loop!
  4. If IsNull(stringtocompare) = False Then
  5.     IsInArray = False
  6. Else
  7.     If stringtocompare = valueToFind Then
  8.         IsInArray = True
  9.     Else
  10.         If InStr(1, stringtocompare, ",", vbTextCompare) = 0 Then
  11.             IsInArray = False
  12.         Else
  13.             arrtocompare = Split(stringtocompare, ",")
  14.             IsInArray = (UBound(Filter(arrtocompare, valueToFind)) > -1)
  15.         End If
  16.     End If
  17. End If
  18. Exit_F:
  19. Exit Function
  20. Err_F:
  21. MsgBox Err.Number & " " & Err.Description
  22. Resume Exit_F
  23. End Function
  24.  
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.
Aug 20 '15 #1
5 1907
NeoPa
32,556 Expert Mod 16PB
I suspect line #4 should read :
Expand|Select|Wrap|Line Numbers
  1. If IsNull(stringtocompare) Then
Aug 20 '15 #2
hvsummer
215 128KB
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.
Aug 21 '15 #3
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 :
Expand|Select|Wrap|Line Numbers
  1. If IsNull(stringtocompare) Then
but should be :
Expand|Select|Wrap|Line Numbers
  1. 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.
Aug 21 '15 #4
hvsummer
215 128KB
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
[
Expand|Select|Wrap|Line Numbers
  1. IsInArray(ID, ID promotion)
  2. or
  3. iif(IsInArray(ID, ID promotion)=True, 1, 0) to count
  4.  
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:
Expand|Select|Wrap|Line Numbers
  1. Public Function IsInArray(stringtocompare As Variant, valueToFind As Variant) As Boolean
  2. On Error GoTo Err_F
  3. ' checks if valueToFind is found in arr, no loop!
  4. If IsNull(stringtocompare) = True Then
  5.     IsInArray = False
  6. Else
  7.     If stringtocompare = valueToFind Then
  8.         IsInArray = True
  9.     Else
  10.         If InStr(1, stringtocompare, ",", vbTextCompare) = 0 Then
  11.             IsInArray = False
  12.         Else
  13.             arrtocompare = Split(stringtocompare, ",")
  14.             IsInArray = (UBound(Filter(arrtocompare, valueToFind)) > -1)
  15.         End If
  16.     End If
  17. End If
  18. Exit_F:
  19. Exit Function
  20. Err_F:
  21. MsgBox Err.Number & " " & Err.Description
  22. Resume Exit_F
  23. End Function
Aug 21 '15 #5
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.
Aug 23 '15 #6

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

Similar topics

1
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:...
7
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:
0
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...
9
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...
5
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...
7
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...
5
by: CyberSoftHari | last post by:
Assembly assembly = Assembly.GetExecutingAssembly(); ResourceManager rm = new ResourceManager("NameSpace.Demo", assembly, null); try { logo.Image =...
8
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 );...
5
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...
0
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? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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...
0
BarryA
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...
1
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...
0
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,...
0
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...
0
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,...
0
jinu1996
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...

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.