UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Null, Nothing, "", which one do I use?    
 
   
Izzy
post Dec 1 2004, 01:00 AM
Post #1

UtterAccess Enthusiast
Posts: 51
From: Brisbane, Australia



I'm trying to use an IF statement to check the contents of a text box to see whether they are empty or not. What do I need to use to check this???

I have tried all three of these variations:

If searchTextBox.Value = "" Then
MsgBox "Please enter a keyword.", vbExclamation
Else
do stuff
End If


If searchTextBox.Value Is Null Then
MsgBox "Please enter a keyword.", vbExclamation
Else
do stuff
End If


If searchTextBox.Value Is Nothing Then
MsgBox "Please enter a keyword.", vbExclamation
Else
do stuff
End If


None of them work.

First version ignores the use of the = "" condition and exectutes the Else part instead. "= Null" gives the same result.

Second version gives me a message box with "object required". This is close to what I'm trying to do, seems to catch the blank textbox but how do I change this message to my own which a user would understand?

Third version gives same as second.

"= Nothing" throws an exception. Same with Is ""

Any ideas anyone???

Thanks.
Go to the top of the page
 
+
JayNoelOlimpo
post Dec 1 2004, 01:15 AM
Post #2

UtterAccess VIP
Posts: 7,990
From: Philippines



If searchTextBox = " " or is null(searchTextBox) or is nothing Then
MsgBox "Please enter a keyword.", vbExclamation
Else
do stuff
End If
Go to the top of the page
 
+
JayNoelOlimpo
post Dec 1 2004, 01:15 AM
Post #3

UtterAccess VIP
Posts: 7,990
From: Philippines



If searchTextBox = " " or is null(searchTextBox) or is nothing(searchTextBox) Then
MsgBox "Please enter a keyword.", vbExclamation
Else
do stuff
End If
Go to the top of the page
 
+
strive4peace
post Dec 1 2004, 01:22 AM
Post #4

UtterAccess VIP
Posts: 20,187
From: Colorado



I do it this way:
CODE
    If isnull(me.searchTextBox) Then
       me.searchTextBox.setfocus
        MsgBox "Please enter a keyword.", vbExclamation, "Need more information"
       exit sub
    End If
     'do stuff
Go to the top of the page
 
+
Izzy
post Dec 1 2004, 01:40 AM
Post #5

UtterAccess Enthusiast
Posts: 51
From: Brisbane, Australia



Cheers Crystal, that worked. (IMG:http://www.utteraccess.com/forum/style_emoticons/default/thumbup.gif)
Go to the top of the page
 
+
strive4peace
post Dec 1 2004, 01:57 AM
Post #6

UtterAccess VIP
Posts: 20,187
From: Colorado



you're welcome (IMG:http://www.utteraccess.com/forum/style_emoticons/default/wink.gif) happy to help
Go to the top of the page
 
+
ChrisO
post Dec 1 2004, 02:23 AM
Post #7

Utterly Banned
Posts: 3,905
From: Brisbane, Australia



‘Exit Sub’ I strongly disagree with.

If the aim is to bail out of a procedure, with speed, then it requires an exit point.
Go To Exit Point. That Exit Point should be defined…Go To A Single Defined Exit Point.

It has been done that way for many years and I have yet to see a valid reason for not doing so.

The methodology stems from machine code writing. One can attempt to pull the stack but with great risk.

We no longer need to resort to those tricks but must play safe.

Please do not ‘Exit Sub’ but instead Go To an Exit Procedure.

One point in and one point out.

Regards,
Chris.
Go to the top of the page
 
+
strive4peace
post Dec 1 2004, 04:42 PM
Post #8

UtterAccess VIP
Posts: 20,187
From: Colorado



good point, Chris. When I have no object variables to release or any code to execute before exiting, I just get out. Personal preferance -- less code.

Ideally, you would never have a procedure without an error handler either. But I only add them when I think there may be problems -- or add them if there are (IMG:http://www.utteraccess.com/forum/style_emoticons/default/wink.gif) Again, it is a personal decision.
Go to the top of the page
 
+
ChrisO
post Dec 1 2004, 08:15 PM
Post #9

Utterly Banned
Posts: 3,905
From: Brisbane, Australia



G’day Crystal.

Yes a lot of programming is very much personal preference.

In this case however there would be three less letters and preserve the ideal of a single exit point.
(We can replace Exit Sub with Else and shuffle the code around a bit.)

CODE
If IsNull(Me.searchTextBox) Then

    Me.searchTextBox.SetFocus

    MsgBox "Please enter a keyword.", vbExclamation, "Need more information"

    Exit Sub

End If

[color="green"]' do stuff





'  Or...[/color]

If IsNull(Me.searchTextBox) Then

    Me.searchTextBox.SetFocus

    MsgBox "Please enter a keyword.", vbExclamation, "Need more information"

Else

    [color="green"]' do stuff[/color]

End If

I know I’m being fussy but just trying to pass on that which was hammered into me. (IMG:http://www.utteraccess.com/forum/style_emoticons/default/grin.gif)

ETA.
And we need to get it right for these Brizzy boys. (IMG:http://www.utteraccess.com/forum/style_emoticons/default/laugh.gif) -o!

Regards,
Chris.


Edited by: ChrisO on Wed Dec 1 20:19:20 EST 2004.
Go to the top of the page
 
+
strive4peace
post Dec 1 2004, 08:27 PM
Post #10

UtterAccess VIP
Posts: 20,187
From: Colorado



Chris, thanks for your thoughts . You have a point, but I myself believe differently. Personally, I always check data at the top and exit out if there is nothing for the routine to do -- usually before anything is even dimensioed. No need to feel frustrated -- we all have our own ways. Unlike you that had the benefit of a teacher, I am self-taught. I am sure I have what others may call bad habits, but they work, and usually work well.

Cheers o!
Go to the top of the page
 
+
ChrisO
post Dec 1 2004, 08:57 PM
Post #11

Utterly Banned
Posts: 3,905
From: Brisbane, Australia



Teacher…what teacher?
I’m as much self taught as most other people around here, I just happen to have a head start on most.
(Pleas read as…Oh Chris, you poor old thing. (IMG:http://www.utteraccess.com/forum/style_emoticons/default/cryhard.gif) )

My boss (not teacher) was a project manager who had a few good tips one of which was a cattle prod. (IMG:http://www.utteraccess.com/forum/style_emoticons/default/shocked.gif)

That was more that twenty ago; the scars have healed but the memories stay forever.

The high level language that I learnt on was called Foxboro Process Basic. A very good language but also very restrictive about how to go about things. I suppose if I had a teacher it was FPB.

We now live with VBA and can do many things differently but I wonder sometimes as to the validity of that which we do.

I guess the point I’m try to make is by all means do things differently but also try to understand why we are doing it differently.

If we can pass along that understanding we have done our job correctly.

Cheers and regards, o!
Chris.
Go to the top of the page
 
+
strive4peace
post Dec 2 2004, 08:49 AM
Post #12

UtterAccess VIP
Posts: 20,187
From: Colorado



Chris,

I approach programming from my engineering background. Like you, I used FoxPro (and dBASE and a host of other dbs) before starting to program with Access 10+ years ago. When you said it was "hammered" in, I assumed that meant you were taught.

This is a great site -- best one I have ever run across. There is a wealth of knowledge here and I always learn so much from the greats like mishej, Ricky Hicks, and ghubbel.

btw, if I exit out of a routine anywhere but the top -- where it is really obvious, I do jump to an exit label...
Go to the top of the page
 
+
ChrisO
post Dec 2 2004, 10:40 PM
Post #13

Utterly Banned
Posts: 3,905
From: Brisbane, Australia



G’day Crystal, how’s it going.

No problems but just wanted to clarify a point in your last post.

A minor point indeed but it could be read that I used FoxPro but that is incorrect, I was taught by/with Foxboro Process Basic. (FPB)

Since there are, comparatively, very few people that have used FPB its source may need further explanation.

The company is called the Foxboro Company and is based in Foxboro Massachusetts. (In house called FoxMas)
They manufacture top quality instrumentation and computers; those computers (1975-1990???) ran on AMD 4901 four-bit slice and had an in-house semi interpreter. (FPB)

FPB was very powerful but at the same time restrictive, however it was very well documented.

That documentation for FPB, along with the documentation they wrote for their glorious Spec200 line has taught more people than I can know. The linear Fairchild catalogue, circa 1970, has also taught more people than I can know.

Therefore, in my (and many others) working life, my ‘teacher’ has been documentation.

Since we are now the documentation writers we should strive to be correct or at the very least explicit.

Kindest of regards,
Chris.
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 19th May 2013 - 07:49 PM