Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

a wrong example?

Posted on 1999-01-15
5
Medium Priority
?
119 Views
Last Modified: 2010-05-03
I got following example from a book and I think that is wrong and did my currection. Do you agree?

---------------------------------------
If your Visual Basic procedure needs to know whether a form's field named Hours Worked has data, the procedure can check it with an If statement, as follows:

If IsNull(txtHoursWorked) Then
   msg = MsgBox("You didn't enter hours worked!", vbOKOnly)
Else                   ' Thank them for the good hours
   msg = MsgBox("Thanks for entering hours worked!", vbOKOnly)
End If
-----------------------------------------

My currection:
If txtHoursWorked = "" Then
   msg = MsgBox("You didn't enter hours worked!", vbOKOnly)
Else                   ' Thank them for the good hours
   msg = MsgBox("Thanks for entering hours worked!", vbOKOnly)
End If
0
Comment
Question by:learn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
caraf_g earned 160 total points
ID: 1456552
I guess txtHoursWorked is a text box.

In that case yes.

better even would be to explicitly state the property you are looking for so:
If txtHoursWorked.Text = "" Then

Also, do you allow the user to enter spaces. If the user enters 3 spaces in the text box, with the above code, since "   " is different from "" it will say "Thanks".

To stop that:
If Trim(txtHoursWorked.Text) = "" Then

0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1456553
Yes, your cOrrection is Correct.
0
 

Author Comment

by:learn
ID: 1456554
To caraf_g:

Thank you for your excellent answer. Yes, that is a text box which is called "field" in that book.
That example is for describing how to use NULL! I should find another book to lean VB :-(

To Mirkwood:

Yes, I was right...except "currection". Thank you.
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1456555
so you'll accept my answer then?
0
 

Author Comment

by:learn
ID: 1456556
To caraf_g

Yes and increase the points a little bit.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question