Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

DTPicker/VB6 bug (?)

Posted on 1999-06-24
8
Medium Priority
?
270 Views
Last Modified: 2010-05-02
I've run into the following problem:

Suppose you've got a DTPicker control called dtpDate on your form set to 01/12/2014 (dd/mm/yyyy format). The following code returns False!

Format(dtpDate,"dd/mm/yyyy") >= Format(Date,"dd/mm/yyyy")

I'm running VB6/SP2 on NTWS/SP5 - my clock is set to 24-jun-1999. Isn't this strange behaviour, certainly when the following line does return True as it should:

CDate(Format(dtpDate,"dd/mm/yyyy")) >= Format(Date,"dd/mm/yyyy")

But - and this is the clue:

IsDate(Format(dtpDate,"dd/mm/yyyy")) returns True
and
TypeName(dtpDate.Value) returns Date

Conclusion: I *HAVE* to use explicite Date types ????

Has anyone seen this before?
0
Comment
Question by:SLE
[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
8 Comments
 
LVL 10

Expert Comment

by:caraf_g
ID: 1519482
I haven't seen this before but here's a bit of advice:

ALWAYS use explicit data types. ALWAYS. VB tries to be nice and does a lot of implicit stuff behind the scenes lulling you into the mistaken belief that it will always work. Until you hit something like this. So don't rely on VB.
0
 

Expert Comment

by:jaypro
ID: 1519483
I completely agree with caraf_g... I have seen situations where datatypes are VERY VERY important...so always make sure not to trust VB's intrinsic type conversions...
0
 
LVL 2

Expert Comment

by:BeedleGuis
ID: 1519484
Another point of interest . . if you don't use FORMAT the result returns true. ie  dtpicker1 > date
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 2

Expert Comment

by:BeedleGuis
ID: 1519485
Also, if you use the custom formats designed for datepicker the result is true  ie format(dtpicker1,"M/d/yyy") > format(date,"mm/dd/yyyy") . .Case Sensitive ..  which probably the way MS designed it to work with the format function as well.
0
 
LVL 3

Accepted Solution

by:
gajendra earned 0 total points
ID: 1519486
Comparing dates through the format function is not correct.

You see, Format converts date to a string.
So when you use ...
Format(#01/12/2014#,"dd/mm/yyyy") >= Format(#24/07/1999#,"dd/mm/yyyy")
... it is obvious that, lexically,
"01" < "24"

Try comparing without the format function... it will work fine.

HTH

Gajendra

0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1519487
gajendra, did you read BeedleGui's comments (Friday, June 25 1999 - 01:21PM PDT)?

You are making a good point, and you explain it well, but since BeedleGui had already brought up the point 9 hours earlier I think the "politically correct" thing to do would have been to add your remark as a comment, not as an answer.
0
 
LVL 2

Author Comment

by:SLE
ID: 1519488
Thanks all for your interest - this was a 0 points question though.
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1519489
:-)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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

722 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