Forum Discussion

Techtravel's avatar
Techtravel
Occasional Contributor
13 years ago

Trying to get a current date to enter into a field

Here is the originally generated vb script:



Call SSCalendarMaskedEdit.Keys("03152011[Tab]")



And we are attempting to place a current date into the field minus a set number of days and all of our current attempts to seems to cause errors and I'm unsure what were putting in wrong. To clarify Current Date Minus say 15 days (Ex. 10/30/2011 - 15 days = 10/15/2011)



Here is one of our recent attempts: Giving the error - Object required: 'DateValue(...)'



Dim dtmTest

Dim formatedDate

Dim currentDate

Set currentDate = DateValue(Now)

Set dtmTest = DateAdd("D", -15, currentDate)

Set formatedDate = Format(dtmTest, "mmddyyyy")

Call SSCalendarMaskedEdit.Keys(formatedDate & "[Tab]")



The way we have achieved this in the past using a slightly different method was such:

(Format(DateAdd("D", -15, Now), "mmddyyyy") )

This would not work either.



Can anyone assist me with the proper terms that will work within TestComplete?

Also, the return for 3/1/2011 would need to be formatted like: 03012011



Thanks for the help

4 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    You'll want to use a combination of aqDateTime and aqConvert objects.  So, the following function will write to the log today's date minus 5 days...





    function tada()

    {

        var TodaysDate = aqDateTime.Now()

        var FiveDaysAgo = aqDateTime.AddDays(TodaysDate, -5)

        var FormattedDate = aqConvert.DateTimeToFormatStr(FiveDaysAgo, "%m%d%Y")

        Log.Message(FormattedDate)

    }




    You'll need to adapt it for VBScript but this should demonstrate how to use those two object.



    Relevant documentation:



    http://smartbear.com/support/viewarticle/13474/ - aqDateTime.Now

    http://smartbear.com/support/viewarticle/13488/ - aqDateTime.AddDays

    http://smartbear.com/support/viewarticle/13451/ - aqConvert.DateTimeToFormatStr
  • Techtravel's avatar
    Techtravel
    Occasional Contributor
    Thanks for the help, I had stumbled upon the articles you mentioned just prior to you posting this.



    This is the result that we got working:



    Call SSCalendarMaskedEdit.Keys(aqConvert.DateTimeToFormatStr(aqDateTime.AddDays(aqDateTime.Now , -15), "%m%d%Y") & "[Tab]")



    Thanks again.
  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    Hi Jason,



    While you've already got a working answer, I'd still like to explain the "Object required: 'DateValue(...)" error you got with your original code. It's caused by improper use of the Set keyword. In VBScript, you use Set only for object assignments. When a variable is assigned a simple value -- a string, number, date, etc. -- Set isn't needed:

    currentDate = DateValue(Now)

    dtmTest = DateAdd("D", -15, currentDate)
  • Techtravel's avatar
    Techtravel
    Occasional Contributor
    Thanks for the assist, writing code isn't my primary background so sometimes I feel like I'm using a chainsaw for surgery but I'm learning and I read these forums quiet a bit for tips and tricks to pick up.