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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with DateAdd in VBScripting

Status
Not open for further replies.

mych

Programmer
May 20, 2004
248
GB
Hi...

Converting my Access FE app to Web browsing front end. I have the following code snippet of a function I run...

Code:
sub RecalcNextRun()

' Declare variables.
dim IntervalType
dim TimeShift
dim NextTimeToRun
dim WhatDay
dim WhatHour

' Set the IntervalType by getting the first character from IntMultiplyer
    IntervalType = Left(document.Ack2.txtTaskMulti.value, 1)

'Set the TimeShift to ReTaskInterval
    TimeShift = document.Ack2.txtTaskInterval.value

' If the IntervalType is w then we need to change this to d
' as w = weekday and d = day
    if IntervalType = "w" then
        IntervalType = "d"
        Timeshift = Timeshift * 7
    end if

' If the IntervalType is m then we need to change this to d
' and set the TimeShift to 28 time the TimeInterval
' This means that tasks will be completed every 4 weeks instead
' of calendar months and saves me lots of code trying to work
' out the first saturday of each month etc.
    if IntervalType = "m" then
        IntervalType = "d"
        TimeShift = TimeShift * 28
    end if

'Code to add the right amount of time so that the NextTimeToRun is updated correctly

[red]NextTimeToRun = FormatDateTime(document.Ack2.txtTaskNtR.value,vbGeneralDate)[/red]

		NextTimeToRun = DateAdd(IntervalType, TimeShify, NextTimeToRun)

    AdvanceDayByOne 'Call Function to advance day by one if required

The line in red comes back with a type mismatch error and I cant think how to fix this in scripting... any help appreciated.

Also I cant seem to find out if DateAdd is a function that works in scripting.
 
NextTimeToRun = DateAdd(IntervalType, [red]TimeShify[/red], NextTimeToRun)

-DNG
 
check for typos...

is this correct...[red]document.Ack2.txtTaskNtR.value[/red]

or is it document.Ack2.txtTaskInterval

-DNG

 
well my fat fingers!!!!!

Cheers DGN!
 
I now have a problem with the next part of my function which uses DateAdd to add a day...

Code:
'### Advance By 1 Day ###
'Code to see if the new date does not fall on a day that it is not required
'First set the DayOKFlag to 0

    DayOKFlag = 0

'Loop adding a day to NextTimeToRun until DayOKFlag = 1

Dim TaskDay(8)

	TaskDay(1) = document.Ack2.txtTaskMon.value
	TaskDay(2) = document.Ack2.txtTaskTue.value
	TaskDay(3) = document.Ack2.txtTaskWed.value
	TaskDay(4) = document.Ack2.txtTaskThu.value
	TaskDay(5) = document.Ack2.txtTaskFri.value
	TaskDay(6) = document.Ack2.txtTaskSat.value
	TaskDay(7) = document.Ack2.txtTaskSun.value

While DayOKFlag = 0

'Work out what number day this is and this we can use to get the value for
'Mon, Tue, Wen, Thu, Fri, Sat or Sun

    WhatDay = Weekday(NextTimeToRun, vbMonday)


'Now check the approptiate TaskDay array, compare and advance day if TaskDay() is False

    If TaskDay(WhatDay) = True Then
        'This Day is OK
        DayOKFlag = 1
    Else
        'Advance NextTimeToRun by one day
        [red]NextTimeToRun = DateAdd("d", 1, NextTimeToRun)[/red]
    End If
    
'Loop through until DayOKFlag = 1
Wend
'### End Advance by one Day

Again the line in red is giving me grief. The erroe givven is "Invalid procedure call or argument: 'DateAdd'"

Not sure where I've mucked up.
 
try hardcoding it for test...just to make sure that NextTimeToRun is getting passed correctly...

NextTimeToRun = DateAdd("d", 1, "some date here")

-DNG
 
Where is NextTimeToRun initially set?

This is client-side VBScript, so use either debugger or alert() to see what's going on.

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
You can use the IsDate() function to test that a variable contains a valid date.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top