Solved

a wrong example?

Posted on 1999-01-15
5
114 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
  • 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

775 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