+ Reply to Thread
Results 1 to 8 of 8

Thread: Tutorial - Date Calculator!

  1. #1
    Learning Programmer travy92 will become famous soon enough travy92's Avatar
    Join Date
    Sep 2007
    Location
    Australia
    Age
    17
    Posts
    73

    Post Tutorial - Date Calculator!

    Welcome to this very simply date calculator!

    What we're doing!

    Basically we'll be making a program that calculates the date difference between the two dates specified!

    GUI (LAYOUT):
    This is my GUI:



    ----------------------------------------------------------------

    What you need~
    1 Command Button with:
    Name: cmdCalc
    Caption: Calculate!

    1 ListBox with:
    Name: lstAnswer

    ----------------------------------------------------------------
    CODE (Very short & simple!)

    Add this code into General Declarations before you begin adding the rest of the code:

    Private Mint As Integer
    ----------------------------------------------------------------

    Then add this code:

    Private Sub cmdCalc_Click()
    Mint = DateDiff("d", "5/09/2007", "11/09/2007")
    lstAnswer.AddItem "The day difference = " & Mint
    End Sub
    ----------------------------------------------------------------

    Code Explanation:

    Private Sub cmdCalc_Click()
    Basically means whenever you click on the cmdCalc button ("Calculate!" button), do the code that's specified below the line.

    ----------------------------------------------------------------

    Mint = DateDiff("d", "5/09/2007", "11/09/2007")
    Means calculate the day difference between the dates specified.

    ----------------------------------------------------------------

    lstAnswer.AddItem "The day difference = " & Mint
    Simply means add the answer to the LixtBox.

    ----------------------------------------------------------------

    You can also change this:
    Mint = DateDiff("d", "5/09/2007", "11/09/2007")
    The "d" can be changed into other things like:

    Year(s): "yyyy"
    Month(s): "m"
    Week(s): "ww"
    Day(s): "d"
    Hour(s): "h"
    Minute(s): "n"
    Second(s): "s"

    Just replace the "d" with one of those and you're done!

    ALSO you can obviously change the dates to whatever you want!

    Thanks to Tcm9669 for the Screenshot program.

    Thanks to TheComputerMaster for the upgraded Screenshot program.

    Thanks to you for reading this tutorial!

    Made by me, Travy92.


    Lol, Samples!:
    Bijgevoegde bestanden
    Last edited by Jordan; 09-11-2007 at 05:17 AM.
    C:\Users\Travis\Desktop\Image Converter\Knight1.bmp

  2. #2
    Newbie Hybrid is an unknown quantity at this point
    Join Date
    Nov 2007
    Posts
    1
    thhhxx for this tutorial

  3. #3
    Newbie $RaMRoM$ is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    6
    Thanks a lot travy92, your tuts are wonderful, BTW i just wanna say that maybe you can add Text Boxes and change:
    Code:
    Private Sub cmdCalc_Click()
    Mint = DateDiff("d", "5/09/2007", "11/09/2007")
    lstAnswer.AddItem "The day difference = " & Mint
    End Sub
    To:
    Code:
    Private Sub cmdCalc_Click()
    Mint = DateDiff("d", Val(Text1.Text), Val(Text2.Text))
    lstAnswer.AddItem "The day difference = " & Mint
    End Sub
    Just Saying! lol

  4. #4
    Newbie Kamilo23 is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    1

    Re: Tutorial - Date Calculator!

    thx for tutorial!

  5. #5
    Xav
    Xav is offline
    Code Slinger Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav's Avatar
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,217
    Blog Entries
    13

    Re: Tutorial - Date Calculator!

    Quote Originally Posted by $RaMRoM$ View Post
    Thanks a lot travy92, your tuts are wonderful, BTW i just wanna say that maybe you can add Text Boxes and change:
    Code:
    Private Sub cmdCalc_Click()
    Mint = DateDiff("d", "5/09/2007", "11/09/2007")
    lstAnswer.AddItem "The day difference = " & Mint
    End Sub
    To:
    Code:
    Private Sub cmdCalc_Click()
    Mint = DateDiff("d", Val(Text1.Text), Val(Text2.Text))
    lstAnswer.AddItem "The day difference = " & Mint
    End Sub
    Just Saying! lol
    I'm not sure your code will work. DateDiff() expects 3 string parameters, yet Val() returns a value. Maybe a DateTimePicker would be a better choice of control.

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  6. #6
    Newbie an2ny21 is an unknown quantity at this point
    Join Date
    Feb 2009
    Posts
    1

    Re: Tutorial - Date Calculator!

    Quote Originally Posted by $RaMRoM$ View Post
    Thanks a lot travy92, your tuts are wonderful, BTW i just wanna say that maybe you can add Text Boxes and change:
    Code:
    Private Sub cmdCalc_Click()
    Mint = DateDiff("d", "5/09/2007", "11/09/2007")
    lstAnswer.AddItem "The day difference = " & Mint
    End Sub
    To:
    Code:
    Private Sub cmdCalc_Click()
    Mint = DateDiff("d", Val(Text1.Text), Val(Text2.Text))
    lstAnswer.AddItem "The day difference = " & Mint
    End Sub
    Just Saying! lol
    it definitely wont work. try this:

    Private Sub cmdCalc_Click()
    date1 = txtmonth.text & "/" & txtday.text & "/" & txtyear.text
    Mint = DateDiff("d", date1, now) ' now means getting the current date
    lstAnswer.AddItem "The day difference = " & Mint
    End Sub


    im sure this will work if its just the day you want to calculate. in other cases im not sure like calculating the age.

  7. #7
    Newbie acanuto is an unknown quantity at this point
    Join Date
    Aug 2009
    Posts
    1

    Re: Tutorial - Date Calculator!

    thx

  8. #8
    Newbie Ghanas is an unknown quantity at this point
    Join Date
    Apr 2010
    Posts
    1

    Re: Tutorial - Date Calculator!

    Quote Originally Posted by acanuto View Post
    thx
    I'm using VB 2008, and am having issues...I'm only learning how to program, and tips? I keep getting an error saying that AddItem isn't a member of the form.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. A date showing tutorial
    By ahsan16 in forum VB Tutorials
    Replies: 3
    Last Post: 12-11-2008, 05:33 PM
  2. John's Java Tutorial Index
    By John in forum Java Tutorials
    Replies: 0
    Last Post: 01-11-2007, 01:05 PM
  3. PHP:Tutorial The Date
    By John in forum PHP Tutorials
    Replies: 0
    Last Post: 01-10-2007, 04:10 PM
  4. Flex, bison multifunction calculator
    By annatsos in forum C and C++
    Replies: 1
    Last Post: 01-04-2007, 04:00 AM