|
-
Apr 11th, 2001, 10:16 PM
#1
Thread Starter
Member
why is this work
Code:
If !a <> "" Then
tempname = !a
Else
tempname = !b
End If
but not this???
Code:
If !a = "" Then
tempname = !b
Else
tempname = !a
End If
--this return NULL error
Just a bit programming concept... thanks for explaining...
-
Apr 12th, 2001, 02:13 AM
#2
Well ...
I can't make any of the two codes to work. I get an Unqualified Reference ...' error at the exclamation mark.
What are you trying to test, anyway? And is it in VB?
.
-
Apr 12th, 2001, 02:51 AM
#3
Retired VBF Adm1nistrator
The exclamation mark is usually used as the logical NOT operator, and would be used for boolean values ; not strings.
The logical not operator in VB is 'Not'.
Eg.
Code:
Dim a As String
If (Not (a = "")) Then
MsgBox "A is not empty"
End If
You would appear to also be using the not operator with strings, which you obviously cant do.
- jamie
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Apr 12th, 2001, 02:59 AM
#4
Thread Starter
Member
sorry...
I should be more specific...
--this code is part of my vb code
--the ! used here is the variable in form, in my case, it's a Textbox's variable
I was trying to check if "a" is an empty string,
if yes, I'll use text in "b" as my data
if no, I'll use text in "a"
Thanks
-
Apr 12th, 2001, 04:46 AM
#5
Code:
Dim TempData as string
If IsNull(text1.text) then
TempData = b
Else
TempData = a
End If
Take a look at the ISNULL() function
-
Apr 12th, 2001, 07:05 AM
#6
Well ...
Also, I think VB treats "" and Null differently.
(I also think that I posted this very reply just a short while back and it just disappeared.)
.
-
Apr 15th, 2001, 08:31 PM
#7
Thread Starter
Member
halo...
Thanks everyone..
I just came back from good friday.. today shold be easter holiday but Singapore only declare good friday as holiday... sad sad have to work.. 
I'll try every suggestion..
again.. Thanks......!!!!!
-
Apr 16th, 2001, 12:03 AM
#8
Junior Member
Simple....
you can't assign a Null value to a variable....
in the first one you can't never assign a null value, 'cause !a got a value.
in the second one Null is not equal to "". so it goes to the else part. Being a variable trying to assign a NULL value, BOOM! error.
-
Apr 16th, 2001, 12:40 AM
#9
Thread Starter
Member
finally I underestand.. 
but...
Do you mean that this code
Code:
If !a <> "" Then
tempname = !a
Else
tempname = !b
End If
will always go to the ELSE part??
Thanks
-
Apr 16th, 2001, 02:40 AM
#10
you can't assign a Null value to a variable....
- Rix
yes u can!
var1 = vbNullChar
-
Apr 16th, 2001, 02:44 AM
#11
try this...
to avoid maximum confusion, test if !a = vbnullchar, and if it is, then assign it ""
then use it in the test case u posted!
-
Apr 16th, 2001, 08:12 PM
#12
Junior Member
remember that you can have !a with values of any string e.g. "Elvira", zero-lenght string, e.g. "" or a NULL value. You have to consider the fact that any of the 3 can change your operation.
If you test if !a="", then you know !a = "", but if !a="" it's false, it can be 'cause !a = NULL or !a = "Elvira"
TheSarlacc....
with function you can make wonders....
-
Apr 16th, 2001, 08:49 PM
#13
Thread Starter
Member
I actually use
Code:
if IsNull(!a) then
...
is this the only way to check if !a is null?
Other suggestions like
!a = "" and !a = vbNullChar
is to assign null to !a, correct?
Thanks!
-
Apr 16th, 2001, 09:47 PM
#14
Junior Member
Don't assign a Null value.
If you want something like it, assign a "" (zero-lenght string ), in the future, you'll see why.
and yes ISNULL() is your only bet. (assuming that is not a zero-lenght string or a normal string, either case you can test that !a is neither, so, by elimination, it got to be NULL.)
-
Apr 17th, 2001, 01:13 AM
#15
Thread Starter
Member
Thanks..
I'll keep everything in mind...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|