why is this work
Code:If !a <> "" Then
tempname = !a
Else
tempname = !b
End If
but not this???
--this return NULL errorCode:If !a = "" Then
tempname = !b
Else
tempname = !a
End If
Just a bit programming concept... thanks for explaining... ;)
Printable View
why is this work
Code:If !a <> "" Then
tempname = !a
Else
tempname = !b
End If
but not this???
--this return NULL errorCode:If !a = "" Then
tempname = !b
Else
tempname = !a
End If
Just a bit programming concept... thanks for explaining... ;)
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?
.
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.
You would appear to also be using the not operator with strings, which you obviously cant do.Code:Dim a As String
If (Not (a = "")) Then
MsgBox "A is not empty"
End If
- jamie
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
:)
Take a look at the ISNULL() function ;)Code:Dim TempData as string
If IsNull(text1.text) then
TempData = b
Else
TempData = a
End If
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.)
.
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.. :D
I'll try every suggestion..
again.. Thanks......!!!!!
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.
finally I underestand.. :)
but...
Do you mean that this code
will always go to the ELSE part??Code:If !a <> "" Then
tempname = !a
Else
tempname = !b
End If
Thanks
- RixQuote:
you can't assign a Null value to a variable....
yes u can!
var1 = vbNullChar
to avoid maximum confusion, test if !a = vbnullchar, and if it is, then assign it ""
then use it in the test case u posted!
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....
I actually use
is this the only way to check if !a is null?Code:if IsNull(!a) then
...
Other suggestions like
!a = "" and !a = vbNullChar
is to assign null to !a, correct?
:confused:
Thanks!
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.)
Thanks..
I'll keep everything in mind...
;)