Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HELP with FUNCTIONS
#1
Solved: 10 Years, 9 Months, 1 Week ago
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!
Reply
#2
Solved: 10 Years, 9 Months, 1 Week ago
more explanation for the scenario will help. if possible paste your lines of code of you functions that you have created.

Reply
#3
Solved: 10 Years, 9 Months, 1 Week ago
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?
Reply
#4
Solved: 10 Years, 9 Months, 1 Week ago
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.
Reply
#5
Solved: 10 Years, 9 Months, 1 Week ago
Thank you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Perform some functions whenever QTP Stop button is pressed smartkarthi 2 2,943 08-22-2013, 11:43 AM
Last Post: smartkarthi
  exit parent functions as well Shridevi.Salagare 3 3,604 07-31-2013, 12:15 AM
Last Post: Ankur
  Datatable in functions shwetasharma 2 3,290 03-26-2013, 08:00 AM
Last Post: sams001
  Problem with using two functions in the same action mhanaan 2 2,850 09-14-2012, 10:09 PM
Last Post: mhanaan
  Can you do functions by calling filename or any other better ways? chong67 2 2,966 05-29-2012, 11:41 PM
Last Post: chong67

Forum Jump:


Users browsing this thread: 1 Guest(s)