Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Defining variable as Static in QTP script
#1
Solved: 10 Years, 9 Months ago
how can we define a variable as Static in QTP scripts

i tried doing following but it failed.

Public Static Var_Name
Reply
#2
Solved: 10 Years, 9 Months ago
You mean to say that the variable is holding static value in all the actions , Could you please explore more about this?
If your answer is static variable in all the actions use enviromnent variable .

Regards,
Venkat.Batchu
Reply
#3
Solved: 10 Years, 9 Months ago
hi @ venkat,

i have a function called Fun1()
inside it i want to define a variable which should be static.
something like following:

--------------cut--------------------

Code:
Function Fun1()
   public Static totalSales  = 0
    totalSales +=1
End Function

--------------cut end --------------
so that each time i call this function ,totalSales should remain static.
Qtp pops an error messageBox while defining totalSales as Static.
when i tried this function without QTP , it works well.
Reply
#4
Solved: 10 Years, 9 Months ago
Hi ,

Try with the below way.

Code:
Function Fun1()
  public [b]Const [/b]totalSales = 0
  totalSales +=1
  --------------
  --------------
End Function

Hi ,

Try with below way.

Code:
Function Fun1()
  public Const totalSales = 0
  totalSales +=1
  --------------
  --------------
End Function
Reply
#5
Solved: 10 Years, 9 Months ago
Static not supported
Reply
#6
Solved: 10 Years, 9 Months ago
You should diclare as

Public Const constName = "Value"

And this should be out of any procedure(function).
Reply
#7
Solved: 10 Years, 9 Months ago
hi @ V_selvam

i tried this :
----------------------------------------------------
Code:
public Const totalSales = 0
Function Fun1()
  totalSales +=1
  --------------
  --------------
End Function
----------------------------------------------------
and i got error message " illegal assignment totalSales +=1"
Reply
#8
Solved: 10 Years, 9 Months ago
Hi Caze

A constant is a meaningful name that takes the place of a number or string and never changes.

In you case totalsales is constant and cannot be changed.


Thanks
Reply
#9
Solved: 10 Years, 9 Months ago
Yes, I agree with Nilesh, if you need to use a variable as similar as static declare it as Const but if you need to change the value later then you should not think of defining it as Const.

simply declare as Dim

Reply
#10
Solved: 10 Years, 9 Months ago
so there is no scope of defining a variable as static in QTP?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using static descriptive programming how to count no. of objects on any webpage alpha1 4 6,726 08-11-2015, 08:48 PM
Last Post: kotaramamohana
  How to Verify Static Object Text which is changing Dynamically with Expected Result johnny77 0 3,185 06-25-2015, 11:32 AM
Last Post: johnny77
  Can you please help me in QTP DP to pass the variable name anshika.agarwal 1 2,593 09-04-2014, 06:43 PM
Last Post: anshika.agarwal
  Vierd problem with static descriptive programming Shwethareddy 7 4,110 10-19-2012, 10:35 AM
Last Post: Shwethareddy
  How to copy the content of a variable to clipboard - QTP 10 rohit330 2 17,250 02-22-2012, 08:29 PM
Last Post: rohit330

Forum Jump:


Users browsing this thread: 1 Guest(s)