Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Code Samples & Tips
Documentation Wiki Register Members List B4P 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, 10:45 PM
Junior Member
 
Join Date: Apr 2007
Location: Germany
Posts: 36
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, 01:05 PM
RandomCoder's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire, UK
Posts: 623
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Cool tip

Regards,
RandomCoder
__________________
"Defeat never comes to any man until he admits it."Josephus Daniels
Reply With Quote
  #3 (permalink)  
Old 07-02-2007, 02:04 PM
Junior Member
 
Join Date: Apr 2007
Location: Germany
Posts: 36
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 = 0and (year mod 100 <> 0or (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, 04:21 PM
specci48's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Germany
Posts: 1,057
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
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 - 11130) = 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 Off
Pingbacks are Off
Refbacks are On

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


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


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0