Solved

a wrong example?

Posted on 1999-01-15
5
117 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 40 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month9 days, 21 hours left to enroll

624 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