1
我主要是通過自己學習qtp和vbs我需要qtp/vbs server 2008中的函數,改變dd和mm的位置並將其轉換爲一個數字字符串以便qtp將其插入到測試中的應用程序中,這是我想出的,但該函數在末尾沒有返回任何內容將變量與多個值進行比較並使用「和」&「或」如果「條件vbscript
'5)DATEFORMATFUNC 「功能是獲取當前系統日期,增加了一天,並把它轉換成字符串 」可用作在UAT‘預訂機票’的日期參數 功能DATEFORMATFUNC
'Defining variables
Dim currentday, currentmonth, currentyear, oday, omonth, oyear, NextDayDate, LeapYear
'* Checking if current year is leap year and transforming answer to numeric variant wher 1=True and 0=False
If DatePart("yyyy", Now) mod 4=0 then
LeapYear = 1
Else LeapYear = 0
End If
'* getting current day of month
currentday = DatePart("d", Now)
'* getting current month of year
currentmonth = DatePart("m", Now)
'* reporting to get it into "test results"
Reporter.ReportEvent micDone, "Current month of year is " & currentmonth, currentmonth
'* getting last two numbers of current year
currentyear = Right((DatePart("yyyy", Now)),2)
'* reporting to get it into "test results"
Reporter.ReportEvent micDone, "Current year is " & currentyear, currentyear
'* If currentday is 31(when 31 days in month) then date becomes the first day of next month
If currentmonth = 1 or 3 or 5 or 7 or 8 or 10 and currentday = 31 Then
omonth = currentmonth +1 and oday = 1
'* If currentday is less then 31(when 31 days in month) then adding 1 day to currentday
ElseIf currentmonth = 1 or 3 or 5 or 7 or 8 or 10 or 12 and currentday < 31 Then
oday = currentday + 1
'* if current day is 31 of december then date becomes first of january next year
ElseIf currentmonth = 12 and currentday = 31 Then
omonth = 1 and oday = 1 and oyear = currentyear+1
'* if current day is 30 (when 30 days in month) then date becomes first day of next month
ElseIf omonth = 4 or 6 or 9 or 11 and oday = 30 Then
omonth =currentmonth + 1 and oday = 1
'* if current day is less then 30 (when 30 days in month) then adding 1 day to current day
ElseIf currentmonth = 4 or 6 or 9 or 11 and currentday < 30 Then
oday = currentday +1
'* if it is leap year and current day is 28 of February then adding 1 day to current day
ElseIf currentmonth = 2 and currentday< 29 and LeapYear = 1 Then
oday = currentday +1
'* if it is leap year and date is 29 of February then date jumps to first of March
ElseIf currentmonth = 2 and currentday = 29 and LeapYear = 1 Then
oday = 1 and omonth = 3
'* if it is not leap year and current day is 28 of February then date becomes first of March
ElseIf currentmonth = 2 and currentday = 28 and LeapYear = 0 Then
oday = 1 and omonth = currentmonth + 1
'* if it is not leap year and current day is less then 28 then adding 1 day to current day
ElseIf currentmonth = 2 and currentday < 28 and LeapYear = 0 Then
oday = currentday + 1
'* End
End If
'if the day of the month is a one digit number then concatinating "0" before it
If oday < 10 then
oday = 0 & oday
end If
'if the month of the year is a one digit number then concatenating "0" before it
If omonth < 10 then
omonth = 0 & omonth
End If
'concatinating the parts of the date in a manner that it can be used as a date parameter (mmddyy) for "Flight Reservation"
NextDayDate = omonth & oday & oyear
Reporter.ReportEvent micDone, "Current date vs changed date", "Current date is: " & Date & " Changed date is: " & NextDayDate
'reporting to get it into "test results"
Reporter.ReportEvent micDone, "The parameter inserted to Data Table " , DataTable.Value ("Next_Day_Date", dtGlobalSheet)
'inserting parameter to data table
DataTable.Value ("Next_Day_Date", dtGlobalSheet) = NextDayDate
End Function
個
@ Ekkehard.Homer感謝您抽出時間回答我的問題!我正在使用hp qtp,但無法識別WScript.Echo。 –
@GeorgeShtalmann - 如果你願意學**我的答案,你會意識到WScript.Echo只是用於演示/展示。 DateAdd()和VBScript布爾操作的工作與您的問題相關。 –