Micro Focus QTP (UFT) Forums

Full Version: How to create a global variable in QTP
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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.