Implementation of Stack in QTP (VBscript)
Implementation of Stack in QTP (VBscript)
Class Stack
Public sizeofStack ' Property/Public variable to hold the index value of Stack Array Public StackLifo() ' Array to hold the values in Stack 'Initialise the size of STack i.e. StackArry by the value passed as Parameter Public Property Let StackSize(ByVal stack_size) sizeOfStack=stack_size ReDim Preserve StackLifo(sizeOfStack) End Property 'Function to Add value to Stack Array Public Function Push(ByVal itemtoPush) For start=0 to Ubound(StackLifo) stackVal=StackLifo(start) If IsEmpty(stackVal) Then StackLifo(start)=itemtoPush Reporter.ReportEvent micDone,"STACK ITEM PUSHED","ITEM:::"&chr(34)&StackLifo(start)&chr(34)&", pushed at STACK POSITION::;"&start&", successfully" Exit function ElseIf Not(IsEmpty(StackLifo(Ubound(StackLifo)))) Then Reporter.ReportEvent micDone,"STACK LIMIT REACHED","STACK LIMIT IS = "&sizeOfStack&" ITEM :::"&chr(34)&StackLifo(Ubound(StackLifo))&chr(34)&", ALREADY PRESENT"&_ "AT STACK POSITION::;"&Ubound(StackLifo)&", SO UNABLE TO PUSH FURTHER."
Next
End Function
For last=Ubound(StackLifo) to Lbound(StackLifo) step-1 If IsEmpty(StackLifo(last)) Then 'do nothing Else Pop=StackLifo(last) Reporter.ReportEvent micDone,"STACK ITEM POPPED","LAST ITEM IN STACK:::"&chr(34)&StackLifo(last)&chr(34)&",STACK POSITION::;"&last&". ITEM POPPED SUCCESSFULLY" StackLifo(last)=Empty Exit Function End If Next
End Function
Employee-Personal
'do nothing Else Peek=StackLifo(last) Reporter.ReportEvent micDone,"STACK ITEM PEEKED","LAST ITEM IN STACK:::"&chr(34)&StackLifo(last)&chr(34)&",STACK POSITION::;"&last&". ITEM PEEKED" 'StackLifo(last)=Empty Exit Function End If Next
Dim stackObj Set stackObj=new Stack stackObj.StackSize=6 'stackObj.Push "Gajendra","samiksha", "sanjay",3,4,5,"Vijay" stackObj.Push("Sharma") stackObj.Push("Vivek") stackObj.Push("Bhavna") stackObj.Push(55)
peekItem=stackObj.Peek
removedORPopItem=stackObj.Pop
Employee-Personal
newPeek=stackObj.Peek
stackObj.Push("SAMIKSHA")
Employee-Personal