Jump to content

Tutorial - Date Calculator!

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
travy92

travy92

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
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:

Posted Image

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

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:

Quote

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

Then add this code:

Quote

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

Code Explanation:

Quote

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

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

Quote

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

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

Quote

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

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

You can also change this:

Quote

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!:

Attached Files


[SIGPIC]C:\Users\Travis\Desktop\Image Converter\Knight1.bmp[/SIGPIC]

#2
Hybrid

Hybrid

    Newbie

  • Members
  • Pip
  • 1 posts
thhhxx for this tutorial

#3
$RaMRoM$

$RaMRoM$

    Newbie

  • Members
  • Pip
  • 6 posts
Thanks a lot travy92, your tuts are wonderful, BTW i just wanna say that maybe you can add Text Boxes and change:
Private Sub cmdCalc_Click()
Mint = DateDiff("d", "5/09/2007", "11/09/2007")
lstAnswer.AddItem "The day difference = " & Mint
End Sub
To:
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
Kamilo23

Kamilo23

    Newbie

  • Members
  • Pip
  • 1 posts
thx for tutorial!

#5
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts

$RaMRoM$ said:

Thanks a lot travy92, your tuts are wonderful, BTW i just wanna say that maybe you can add Text Boxes and change:
Private Sub cmdCalc_Click()

Mint = DateDiff("d", "5/09/2007", "11/09/2007")

lstAnswer.AddItem "The day difference = " & Mint

End Sub
To:
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.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#6
an2ny21

an2ny21

    Newbie

  • Members
  • Pip
  • 1 posts

$RaMRoM$ said:

Thanks a lot travy92, your tuts are wonderful, BTW i just wanna say that maybe you can add Text Boxes and change:
Private Sub cmdCalc_Click()

Mint = DateDiff("d", "5/09/2007", "11/09/2007")

lstAnswer.AddItem "The day difference = " & Mint

End Sub
To:
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
acanuto

acanuto

    Newbie

  • Members
  • Pip
  • 1 posts
thx

#8
Ghanas

Ghanas

    Newbie

  • Members
  • Pip
  • 1 posts

acanuto said:

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.