Thursday, April 4, 2013

How can the SilkTest error message " "[TextField]Textfield" is not enabled" be resolved?

This will usually occur when using GetText() or a related method against a textfield which has the "enabled" property set to False.

By default, SilkTest will check this property before proceeding.
To change this:

1. You need to go to "Options/Agent/Verification/Verify That Windows Are Enabled" and uncheck this.

OR

2. Agent.SetOption (OPT_VERIFY_ENABLED, FALSE)
above statement should be written before doing any action on disabled text box
Note: Remember to set it true later like Agent.SetOption (OPT_VERIFY_ACTIVE, TRUE)

Wednesday, April 3, 2013

Function to get the date of last friday of the current month

 [+] public STRING LastFridayOfTheCurrentMonth()
  [ ]  // ==========================================================
  [+]  // FUNCTION: LastFridayOfTheCurrentMonth()
   [ ] //
   [ ] // DESCRIPTION:
   [ ] // This function will return the last friday's date of the current month
  [ ] // ==========================================================
  [ ]
  [-] // Variable Declarations
   [ ] INTEGER iDifference,iLastFridayOfTheMonth,iDayIncreament,iFridayOfTheWeek,i
   [ ] STRING sDay,sDate,sToday
   [ ] DATETIME dtDateTime,newDateTime
   [ ]
  [+] do
   [ ] dtDateTime= GetDateTime ()
   [ ]
   [ ] sDay = FormatDateTime(GetDateTime(), "w")  // Sun, Mon, Tue, Wed, Thu, Fri, or Sat
   [ ]                     //  1       2      3      4      5       6      7
   [ ] iDifference = 6 - Val(sDay)
   [ ]
   [ ] sToday = FormatDateTime(GetDateTime(),"d")
   [ ] // print("sToday = {sToday}")
   [ ]
   [ ]
   [ ] iFridayOfTheWeek = Val(sToday) + iDifference
   [ ] // print("iFridayOfTheWeek = {iFridayOfTheWeek}")
   [+] if(iFridayOfTheWeek > 31)
    [ ] iFridayOfTheWeek = Val(sToday) - Val(sDay)-1
    [ ]
   [ ]
   [ ] iLastFridayOfTheMonth=iFridayOfTheWeek
   [ ] // print("iLastFridayOfTheMonth = {iLastFridayOfTheMonth}")
   [ ]
   [-] for(i=iLastFridayOfTheMonth;i<31;i++)
    [ ] iLastFridayOfTheMonth=iLastFridayOfTheMonth+7
    [+] if(iLastFridayOfTheMonth>31)
     [ ] iLastFridayOfTheMonth=iLastFridayOfTheMonth-7
     [ ] // print("Last friday {iLastFridayOfTheMonth}")
     [ ] break
    [+] else
     [ ] // print(iLastFridayOfTheMonth)
   [ ]
   [ ] iDayIncreament=iLastFridayOfTheMonth-Val(sToday)
   [ ] newDateTime = AddDateTime (dtDateTime, iDayIncreament)
   [ ] sDate = FormatDateTime (newDateTime, "m/d/yyyy")
   [ ]
  [+] except
   [ ] ExceptLog()
   [ ]
  [ ]
  [ ] return sDate
  [ ]

Function to get last date of the current month

 [+] public STRING LastDateOfTheMonth()
  [ ]  // ==========================================================
  [+]  // FUNCTION: LastDateOfTheMonth()
   [ ] //
   [ ] // DESCRIPTION:
   [ ] // This function will return the last date of the current month
  [ ]  // ==========================================================
  [+] // Variable declarations
   [ ] INTEGER iDay,iMonth,iYear
   [ ] DATETIME dtDateTime
   [ ] STRING sDate,sMonth,sYear
  [ ]
  [+] do
   [ ] sMonth = FormatDateTime(GetDateTime(), "m")
   [ ] iMonth = Val(sMonth)
   [ ] sYear= FormatDateTime(GetDateTime(), "yyyy")
   [ ] iYear = Val(sYear)
   [ ]
   [+] switch (iMonth)
    [-] case 2
     [ ] // if year is divisible by 4 and not divisible by 100
     [-] if ((iYear % 4 == 0) && (iYear % 100) > 0)
      [ ] iDay = 29
     [ ] //or if year is divisible by 400
     [-] else if (iYear % 400 == 0)
      [ ] iDay= 29
     [-] else
      [ ] iDay= 28
    [-] case 4
     [ ] iDay= 30
    [-] case 6
     [ ] iDay= 30
    [-] case 9
     [ ] iDay= 30
    [-] case 11
     [ ] iDay= 30
    [-] default
     [ ] iDay= 31
   
   [ ]
   [ ] dtDateTime=MakeDateTime(iYear, iMonth, iDay)
   [ ] sDate=FormatDateTime(dtDateTime,"m/d/yyyy")
  [+] except
   [ ] ExceptLog()
  [ ]
  [ ] return sDate