Micro Focus QTP (UFT) Forums
HELP with FUNCTIONS - 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: HELP with FUNCTIONS (/Thread-HELP-with-FUNCTIONS)



HELP with FUNCTIONS - rdwaram - 11-10-2009

Hello,

I need some help with function. Have not really got any help from the QTP guides. I am confident someone can explain it to me in better terms.


We have multiple scenarios in out application the same steps are being performed. I would like to write function to limit the amount of code and maintenance.

For example - We have an option to create fields and choices, layouts, etc.

How can i call a function every time, if i need to create a field, instead or reusing a redundant script.

Any help will be appreciated. Thanks!


RE: HELP with FUNCTIONS - Saket - 11-10-2009

more explanation for the scenario will help. if possible paste your lines of code of you functions that you have created.


RE: HELP with FUNCTIONS - rdwaram - 11-11-2009

I think i made some progress on the answer to my intial question. but i do have a follow up. How can i set optional variables in a function.

for example.

public function create addressbook (byref name, byref address, byref city, by ref zip)

Code:
browser("main").page("flight").weblist("objecttype:dropdown").Select name
browser("main").page("flight").weblist("objecttype:dropdown").Select address
browser("main").page("flight").weblist("objecttype:dropdown").Select city
'etc

how can i implement optional variables as well? for instance if i wanted suitenumber to to applicable to some and not all.
is specifying all possible variables the only way?


RE: HELP with FUNCTIONS - jsknight1969 - 11-11-2009

Optional parameters are not allowed in VBscript, neither is overloading. Unfortunantly, you must specify each one. you could always test the varible for a null or empty and just not use it.


RE: HELP with FUNCTIONS - rdwaram - 11-11-2009

Thank you!