将变量与多个值进行比较,并使用“and”或“If”条件vbscript
我主要是自己学习qtp和vbs。我需要qtp/vbs server 2008中的一个函数,该函数将ads一天转换为当前日期,然后更改dd和mm的位置,并将其转换为数字字符串,以便qtp将其插入测试中的应用程序。这是我想到的,但该函数最终没有返回任何结果 '5 DATEFORMATFUNC '函数,该函数获取当前系统日期,向其中添加一天并将其转换为字符串 '可用作UAT航班预订中的日期参数 函数DATEFORMATFUNC将变量与多个值进行比较,并使用“and”或“If”条件vbscript,vbscript,Vbscript,我主要是自己学习qtp和vbs。我需要qtp/vbs server 2008中的一个函数,该函数将ads一天转换为当前日期,然后更改dd和mm的位置,并将其转换为数字字符串,以便qtp将其插入测试中的应用程序。这是我想到的,但该函数最终没有返回任何结果 '5 DATEFORMATFUNC '函数,该函数获取当前系统日期,向其中添加一天并将其转换为字符串 '可用作UAT航班预订中的日期参数 函数DATEFORMATFUNC 'Defining variables Dim currentda
'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
像你这样的条件
If currentmonth = 1 or 3 or 5 or 7 or 8 or 10 and currentday = 31 Then
不要“工作”,因为VBScript的逻辑运算符对数字进行按位操作。cf.:
对于i=0,条件的计算结果为False或False,即False
i=0的False作为数字0,按位Or设置为2,即2,因此为真
在将大量CurrnEng= =添加到条件语句之前,请考虑
要将日期格式化为MMDDYYYY,请执行以下操作:>> dtX = Date()
>> sX = Right(100 + Month(dtx), 2) & Right(100 + Day(dtX), 2) & Year(dtX)
>> WScript.Echo TypeName(sX), sX
>>
String 05032015
@Ekkehard.Homer感谢您抽出时间回答我的问题!我正在使用hp qtp,但它不识别WScript.Echo。@GeorgeShtalmann-如果您仔细研究我的答案,您会发现WScript.Echo仅用于演示/显示。DateAdd和VBScript的布尔运算的工作与您的问题相关。
>> For i = 0 To 1
>> If i = 1 Or 2 Then
>> WScript.Echo i, "is 1 Or 2"
>> End If
>> Next
>>
0 is 1 Or 2
1 is 1 Or 2
>> dtToday = Date()
>> WScript.Echo TypeName(dtToday), dtToday
>> dtTomorrow = DateAdd("d", 1, dtToday)
>> WScript.Echo TypeName(dtTomorrow), dtTomorrow
>>
Date 03.05.2015 ' german locale
Date 04.05.2015
>> For Each dtX In Array(#12/31/2014#, #2/28/2012#, #2/28/2013#)
>> WScript.Echo dtX, DateAdd("d", 1, dtX)
>> Next
>>
31.12.2014 01.01.2015 ' german locale
28.02.2012 29.02.2012
28.02.2013 01.03.2013
>> dtX = Date()
>> sX = Right(100 + Month(dtx), 2) & Right(100 + Day(dtX), 2) & Year(dtX)
>> WScript.Echo TypeName(sX), sX
>>
String 05032015