Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Code Samples & Tips
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Code Samples & Tips Share your recent discoveries and ideas with other users.


leap year detection


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-01-2007, 11:45 PM
Junior Member
 
Join Date: Apr 2007
Location: Germany
Posts: 34
Thumbs up leap year detection

Leap year detection is quite simple ... every year divisible by 4 unless divisible by 100 except years divisible by 400. But Basic4PPC has a "built in" leap year detection:

Code:
Sub Globals
End Sub

Sub App_Start
  Form1.Show
  msgbox("2005: " & leapyear(2005))
  msgbox("2004: " & leapyear(2004))	
End Sub

sub leapyear(year)
  ' please keep correct Dateformat() in mind ...
  if DateParse("02/29/" & year) = 0 then return False else return True
end sub
DateParse() returns 0 for non-existent leap days Thanks, Erel!
__________________
iPAQ 6515, MDA compact
Reply With Quote
  #2 (permalink)  
Old 07-02-2007, 02:05 PM
RandomCoder's Avatar
Basic4ppc Veteran
 
Join Date: May 2007
Location: UK
Posts: 485
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Cool tip

Regards,
RandomCoder
__________________
Desktop: Pentium D 920 (2.8GHz, 4MB L2 Cache, 800MHz FSB), 1024MB, 256MB Radeon X600, 250GB HD.
Device : Axim X51v XScale 624MHz, 3.7" VGA, 64MB SDRAM, 256MB Flash ROM + 1Gb SD.

"Defeat never comes to any man until he admits it."Josephus Daniels
Reply With Quote
  #3 (permalink)  
Old 07-02-2007, 03:04 PM
Junior Member
 
Join Date: Apr 2007
Location: Germany
Posts: 34
Default

Thanks RandomCoder,
indeed I wrote this tip with a big smile in my face ...

And here is a more "classic" leap year detection. Works with year represented by number or by datetick:

Code:
sub DateIsLeapYear(year)
	' transform DateTick to year if necessary
	if year > 10000 then year = DateYear(year)
	' calculate leap year
	if (year mod 4 = 0) and (year mod 100 <> 0) or (year mod 400) = 0 then return true else return false
end sub
__________________
iPAQ 6515, MDA compact
Reply With Quote
  #4 (permalink)  
Old 07-02-2007, 05:21 PM
specci48's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Germany
Posts: 638
Default

Just as an addition ...

With this code you don't have to worry about the actual DateFormat :
Code:
Sub leapyear(year)
    If DateDayOfYear(DateAdd(0, year - 1, 11, 30) = 366 Then
        Return True
    Else
        Return False
    End If
End Sub

specci48
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Drive Detection RandomCoder Questions & Help Needed 9 07-04-2008 12:59 PM
Calendar Control: I can't see the year. sloopa Questions & Help Needed 4 06-25-2008 07:30 PM
New Year, New Competition... Cableguy Forum Discussion 2 01-08-2008 11:21 PM
New Year! Tanner Chit Chat 16 01-03-2008 07:16 PM


All times are GMT. The time now is 10:53 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0