Solved

a wrong example?

Posted on 1999-01-15
5
113 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
Comment Utility
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
Comment Utility
Yes, your cOrrection is Correct.
0
 

Author Comment

by:learn
Comment Utility
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
Comment Utility
so you'll accept my answer then?
0
 

Author Comment

by:learn
Comment Utility
To caraf_g

Yes and increase the points a little bit.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now