Solved

a wrong example?

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

751 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