Micro Focus QTP (UFT) Forums

Full Version: HELP with FUNCTIONS
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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!
more explanation for the scenario will help. if possible paste your lines of code of you functions that you have created.
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?
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.
Thank you!