Age Generator in VB6.0
Submitted by donbermoy on Thursday, March 13, 2014 - 08:49.
Hello! Aside from making tutorial on vb.net, i will also create a tutorial for vb 6.0 for now. We will create an age generator using vb6.0.
Now, let's start this tutorial!
1.Let's start this tutorial by following the following steps in Microsoft Visual Basic 6.0: Open Microsoft Visual Basic 6.0, click Choose Standard EXE, and click Open.
2.Next, add only one Button named Command1 and labeled it as "Compute". Add also DTPicker named DTPicker1 and format it as dtpShortDate .You must design your layout like this:
3.Now put this code for your code module. This code is for Button1_Click:
- Private Sub Command1_Click()
- Dim iyears As Integer
- Dim tmonth As Integer
- Dim Bmonth As Integer
- '
- iyears = DateDiff("yyyy", "01/01/" & DatePart("yyyy", DTPicker1.Value), _
- "01/01/" & DatePart("yyyy", Now)) - 1
- tmonth = DatePart("m", Now)
- Bmonth = DatePart("m", DTPicker1.Value)
- '
- Select Case tmonth
- Case Is > Bmonth
- iyears = iyears + 1
- Case Is = Bmonth
- If DatePart("d", DTPicker1.Value) <= _
- DatePart("d", Now) Then iyears = iyears + 1
- End Select
- MsgBox "Your age is:" & iyears
- End Sub
Explanation:
We have initialized variable iyears As Integer, variable tmonth As Integer, and variable Bmonth As Integer. Then we make our variable iyears to be equal to the date difference of year from the end date to the start date minus 1. DateDiff Function returns the count (signed integer) of the specified datepart boundaries crossed between the specified startdate and enddate. We have also let the tmonth variable will be equal to the current month and the Bmonth variable will be equal to the month of birth inputted in the DTPicker. Next, we have created a select case statement. The Is keyword which is used for object reference comparison. If variable tmonth will be greater than Bmonth variable will increment the value of iyears variable by one. Otherwise , if it will be equal to BMonth variable we extracted the day of our DTPicker and if this is less than or equal to the day of current date, then the iyears variable will increment by 1. Thus, this will display your current age now.Output:
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards, Engr. Lyndon Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISwareAdd new comment
- 64 views