Micro Focus QTP (UFT) Forums
Defining variable as Static in QTP script - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Defining variable as Static in QTP script (/Thread-Defining-variable-as-Static-in-QTP-script)

Pages: 1 2


Defining variable as Static in QTP script - caze - 12-05-2009

how can we define a variable as Static in QTP scripts

i tried doing following but it failed.

Public Static Var_Name


RE: Defining variable as Static in QTP script - venkatbatchu - 12-06-2009

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


RE: Defining variable as Static in QTP script - caze - 12-06-2009

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.


RE: Defining variable as Static in QTP script - sreekanth chilam - 12-06-2009

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



RE: Defining variable as Static in QTP script - nil - 12-07-2009

Static not supported


RE: Defining variable as Static in QTP script - v_selvam - 12-07-2009

You should diclare as

Public Const constName = "Value"

And this should be out of any procedure(function).


RE: Defining variable as Static in QTP script - caze - 12-10-2009

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"


RE: Defining variable as Static in QTP script - nil - 12-10-2009

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


RE: Defining variable as Static in QTP script - Saket - 12-10-2009

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


RE: Defining variable as Static in QTP script - caze - 12-11-2009

so there is no scope of defining a variable as static in QTP?