Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2006

Tip: Looking for answers? Try searching our database.

textbox value evaluation?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sean - 10 Nov 2006 19:53 GMT
Hi,
I have a question about my code posted below.  For some reason, if
txtCurrentWeek.Value = 5 and txtTotalWeek.Value = 21, the msgbox will be
displayed, even though it shouldn't.  I belive it has to do with the value
not being read as an integer or the length of the value (I assumed this
because if I set 'current' = 1 or = 2 and 'total' = 21, I get no error
message.  Do I have to declare these .values as integers or to have a
specific length?  If so how do I do that?

If txtCurrentWeek.Value > txtTotalWeek.Value Then
MsgBox "Current project week cannot exceed the total number of project
weeks.", vbOKOnly, "Error"
Exit Sub
End If

Thanks.
Jay Freedman - 10 Nov 2006 21:34 GMT
The .Value is a string, so the greater-than operator is doing
character-by-character string comparison. Change the expression to

If Val(txtCurrentWeek.Value) > Val(txtTotalWeek.Value) Then

to compare the numeric values.

Instead of the Val() function, you can use the CInt() function. The only
practical difference is that if myString contains something other than
digits, CInt(myString) will throw a type-mismatch error but Val(myString)
will return 0. Sometimes one or the other is preferable.

Signature

Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

> Hi,
> I have a question about my code posted below.  For some reason, if
[quoted text clipped - 12 lines]
>
> Thanks.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.