Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Problem with date

Status
Not open for further replies.

Hokis

Technical User
May 21, 2007
51
US
Hi, I'm doing this simple program which I don't know how to to.
I have this form in it a employee txtbox, a masked date txtbox & a vacation hour txtbox, & a result lblbox,
when the user puts the info in it, i need the calculate btn to calculate as follows:
if the employee is hired 1 year ago, then the lbl should say he has 40 hours of vacation to go, if 2 years ago then 80 hours.
if in the vacatio box there was (any vacation that he already had) then diduct that from the total vacation that he has.
I hope someone undrestand what i wrote.
tha's how i verifyed my variables.
I'm having problems with the date???
Dim strName As String
Dim decDate As Decimal
Dim decVacation As Decimal

strName = Me.txtName.Text
decDate = CDec(Me.txtDate.Text)
decVacation = CDec(Me.txtVacation.Text)
Pls help I need that.
Thank you
Hokis
 




Hi,

If this is MS Access, you are in the wrong forum.

Check out the DateDiff function.

Also, since dates can be entered any number of ways, and the conversion from TEXT to DATE depends on the correct format, I suggest collecting YEAR, MONTH and DAY in separate textboxes and then using the DateSerial function to convert to a date varaible. There is no DECIMAL variable type in VBA. Declare you date variable as DATE, and your vacation variable as a INTEGER.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a brand NUANCE![tongue][/sub]
 
Ok this is my code after modification.
Dim strName As String
Dim intMonth As Integer
Dim intYear As Integer
Dim intDay As Integer
Dim intTotal As Integer
Dim intVacation As Integer


strName = Me.txtName.Text
intYear = CInt(Me.txtYear.Text)
intDay = CInt(Me.txtDay.Text)
intMonth = CInt(Me.txtMonth.Text)
intVacation = CInt(Me.txtVacation.Text)


If (2008 - intYear) <= 2 Then
intTotal = Convert.ToInt32(Me.txtVacation.Text) - 40
Me.lblResult.Visible = True

Me.lblResult.Text = ("You have " & intTotal & " Hours Left")
ElseIf (2008 - intYear) > 2 Then
intTotal = Convert.ToInt32(Me.txtVacation.Text) - 80
Me.lblResult.Visible = True

Me.lblResult.Text = ("You have " & intTotal & " Hours Left")

End If
But still I'm missing the month & year i need to comapre it acordin to the three of them. how can i do that??
Hokis
 



You do not want to compare anything to the individual YEAR, MONTH or DAY. Convert to a date using the DateSerial Function. Then use DateDiff to get the YEARS difference.



Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a brand NUANCE![tongue][/sub]
 
can u be more specific pls. can u show me how to do it.
PLEASE.
Thank you
 



Feel free to use your F1 key.
Code:
dSomeDate = DateSerial(YrVal,MoVal,DaVal)



Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a brand NUANCE![tongue][/sub]
 
i did but i couldn't figure it out, I'm sorry as I'm new in Visual basic, so Pls can u help.
Thanks
 




Please post your code and explain where you need help.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a brand NUANCE![tongue][/sub]
 
That's the only code i have.
I need the Date slected & today's date's difference to see if it is more then then one year or not.
How can i do that?
Thanks
 





Code:
iYrDiff = DateDiff("yyyy",dSomeDate,Date)


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a brand NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top