0% found this document useful (0 votes)
422 views3 pages

CS 211 1st Activity

The document instructs students to create a VB program that calculates their age in years, months, and days based on their birthday, with a deadline of July 28, 2013. It provides sample code to calculate the difference between two dates that students can modify for their program. Students are told to upload their program folder to Mediafire, include a screenshot on Tinypic, and post details on the class forum.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
422 views3 pages

CS 211 1st Activity

The document instructs students to create a VB program that calculates their age in years, months, and days based on their birthday, with a deadline of July 28, 2013. It provides sample code to calculate the difference between two dates that students can modify for their program. Students are told to upload their program folder to Mediafire, include a screenshot on Tinypic, and post details on the class forum.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

GREETINGS MY DEAR STUDENTS!

Let me inform you of your first activity in this particular subject,Data Structure and Algorithm Analysis. Your aim is to create a VB program that could calculate your period of existence in years , months and days. The algorithm should base on your birthday. You can make use all of you resources, internet , books, and any other source. If you are done with your project. Create a RAR of your folder and upload it on mediafire. Create a screenshot also of your finished program and upload it on tinypic.com. You can check the forums under OFF TOPICS to seek assistance in mediafire and tinypic.com Lastly: Post on Forum under Data Structure Section your uploaded program in mediafire and the screenshot of your program that was uploaded in tinypic.com. LAST SUBMISSION IS ON - JULY 28, 2013 MAXIMUM TOLERANCE AFTER DEADLINE IS THREE DAYS ONLY. Best of Luck to all! And Happy Intramurals 2013! Best Regards; Sir Reynan ################################################################################### Program Name : Period of Existence Calculator Deadline : July 28, 2013 + 3 days for maximum tolerance Note : Codes below are my own algorithm, you can make use of your own, or you can modify this code depending on your own needs. By any means you wish to use the codes below as your basis, you can begin by following the succeeding instruction Instruction: 1. Create a new standar exe project with 1 Form. 2. Add controls: 2 TextBoxes, 1 Label, and 1 Timer. 3. Copy this following code to the form editor form. 4. Nevertheless, bear in mind that all you had to do is calculate how long you had exists in years, months, and days. 'Description: Calculate difference between 2 particular dates ' and show the result in format: day(s), hr:min:sec ' For example: ' The first date = 01/03/2002 17:18:00 and ' The second date = 01/09/2002 09:42:30, then ' the result will output --> 183 day(s), 16:24:30 ' (183 days, 16 hours, 24 minutes, and 30 seconds). ' You can use the DateDiff function belongs to VB6 '------------------------------------------------------------------Option Explicit Function CalcDiff2Dates(ByVal d1 As Date, _ ByVal d2 As Date) As String Dim Second As Long, Day As Long, Hour As Long Dim CompleteHour As String

If d1 > d2 Then MsgBox "The first date must be lower than " & _ "the second date!", _ vbCritical, "Warning" Exit Function End If 'Count the difference in seconds Second = DateDiff("s", d1, d2) 'Calculate the hour by dividing with 3600 '(backslash ("\") in order to get the Integer 'without decimal value) Hour = Second \ 3600 'If hour greater than 23 'it means: more than 1 day If Hour > 23 Then 'Calculate day by dividing with 24 '(backslash ("\") in order to get the Integer 'value without decimal value) Day = Hour \ 24 'Calculate the hour duration in hh:mm:ss CompleteHour = Format((d2 - d1), "hh:mm:ss") Else 'If the hour less than or equal with 23 Day = 0 'assign the Day with zero value 'Calculate hour duration in hh:mm:ss CompleteHour = Format((d2 - d1), "hh:mm:ss") End If If Day = 0 Then 'If less than 1 day 'Get the final result CalcDiff2Dates = CompleteHour Else 'If day greater than 0, show the day duration 'Get the final result CalcDiff2Dates = Day & " day(s), " & CompleteHour End If Exit Function End Function Private Sub Form_Load() Timer1.Interval = 500 Timer1.Enabled = True Text1.Text = "01/03/2002 17:18:00" 'Text2.Text = "01/09/2002 09:42:30" Text2.Text = Now End Sub Private Sub Timer1_Timer()

On Error GoTo ErrHandler Text2.Text = Now Label1.Caption = CalcDiff2Dates(CDate(Text1.Text), _ CDate(Text2.Text)) Exit Sub ErrHandler: MsgBox "Invalid date or format!", _ vbCritical, "Error Date" End Sub

You might also like