[Year 12 SofDev] Date calculations

Mike Brookes mikebr at tpg.com.au
Thu May 21 18:09:32 EST 2009


Hi Leanne

Use the CDate() function to convert the text to a date instead of Val()

You can also use the IsDate function tio validate that the text is a 
valid date:

If Not IsDate(TxtDate.Text) Then
    'Invalid date provided  display suitable error message
Else
    If CDate(txtDate.Text) < #1/7/09# Then  
            etc. etc
    End If
End If

Mike Brookes
chief cook and bottlewasher Copperfield College


Leanne Wright wrote:
> 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




More information about the sofdev mailing list