[Year 12 SofDev] Date calculations

Don Morelli Optus da_morelli at optusnet.com.au
Thu May 21 18:29:59 EST 2009


The problem with your condition is that you are not comparing the right data
types. Convert each to a date, using the Cdate() function (covert to a date
datatype), and then compare the results, like below

 

If CDate(txtDate.Text) < CDate("1/7/09") Then ....

It will work fine as I tried it.  

 

Cheers 

Don

  _____  

From: sofdev-bounces at edulists.com.au [mailto:sofdev-bounces at edulists.com.au]
On Behalf Of Leanne Wright
Sent: Thursday, 21 May 2009 3:51 PM
To: Year 12 Software Development Teachers' M List
Subject: [Year 12 SofDev] Date calculations

 

Can anyone help me with VB6 code for the following task. My students are
working on a program which will allow a discount on goods purchased before
30th June 2009. I have tried the following line of code:
 
 if val(txtDate.text) < #1/7/09# then   
etc. etc
 
However this gives a discount to dates before and after the cut off date.  I
have also tried declaring orderdate as a variable of type date and also
changing 'val' to 'dateval' in the above code but this then gives no
discount at all regardless of the date. I thought this would be simple to
code but am tearing my hair out. Thanks in advance to anyone who can help.
Leanne Wright - Epping SC

  _____  

Let ninemsn property help Looking to move somewhere new this winter?
<http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fninemsn%2Edomain%2Ecom%2Eau
%2F%3Fs%5Fcid%3DFDMedia%3ANineMSN%5FHotmail%5FTagline&_t=774152450&_r=Domain
_tagline&_m=EXT> _______________________________________________ 
http://www.edulists.com.au  <http://www.edulists.com.au> IT Software
Development Mailing List kindly supported by 
http://www.vitta.org.au/vce/studies/infotech/softwaredevel3-4.html
<http://www.vitta.org.au/vce/studies/infotech/softwaredevel3-4.html%20%20>
- Victorian Curriculum and Assessment Authority and 
http://www.vitta.org.au  <http://www.vitta.org.au> - VITTA Victorian
Information Technology Teachers Association Inc

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.edulists.com.au/pipermail/sofdev/attachments/20090521/11a1ff38/attachment.html


More information about the sofdev mailing list