Micro Focus QTP (UFT) Forums
How to create a global variable in QTP - 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: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: How to create a global variable in QTP (/Thread-How-to-create-a-global-variable-in-QTP)



How to create a global variable in QTP - galstar - 08-04-2010

Hi ,
I am facing a problem while creating script in QTP.
Please find below the code...

Code:
Function   RandomString( ByVal strLen )
    Dim str
    Const  LETTERS = "abcdefghijklmnopqrstuvwxyz0123456789"
   For i = 1 to strLen
     str = str & Mid( LETTERS, RandomNumber( 1, Len( LETTERS ) ), 1 )
    Next
  RandomString=str

End Function

'-----------*END FUNCTION*-----------------------
Code:
public a
a=RandomString(4)  'Put  random string generated into a variable 'a'
msgbox(a)
'------------*GET VALUE OF MFG PART# FROM G.SHEET  & SET  PRICE OUTPUT VALUE  in G.SHEET*-------------
row_cnt=datatable.getrowcount
for i=1 to row_cnt ' For each row , do following
datatable.getsheet(i) ' Read Sheet 1 i.e. Global sheet

datatable.Value("Asset_Id",1)=a
msgbox(a)

datatable.setnextrow ' Increment loop counter



Asset_Id is a column in my datasheet..
But still value of as is not getting saved in that column..donn know why..
I am doing record and play..

So please help me to solve this issue.


RE: How to create a global variable in QTP - supputuri - 08-04-2010

Hi Glastar,

I think you are doing wrong when writting value to datatable.

Can you please try to use Datatable.SetCurrentRow(i), rather than using setnextrow.
Code:
Datatable.SetCurrentRow(i)
No need to use the Datatable.GetSheet(i), as it is not at all useful in this contest.