Micro Focus QTP (UFT) Forums
Can you do functions by calling filename or any other better ways? - 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: Can you do functions by calling filename or any other better ways? (/Thread-Can-you-do-functions-by-calling-filename-or-any-other-better-ways)



Can you do functions by calling filename or any other better ways? - chong67 - 05-25-2012

I have functions that I use all the time in my automation.

1. Can I save the function to another filename?
2. If I save to another filename how do I evoke it?
3. Is there any other better way?

==============

Below is example of my function:

Code:
Dim OutDate,ReturnDate,RndValue

' Initialize random-number generator
Randomize
' Generate random value between 200 and 300
RndValue = Int(  (300-200 +1)* Rnd + 200)
'msgBox(RndValue)

OutDate = DateAdd("d", RndValue, Date)
'msgBox(OutDate)

ReturnDate = DateAdd("d", RndValue+10, Date)
'msgBox(ReturnDate)
================

My code that calls it:

Code:
Browser("Delta Air Lines - Airline").Page("Delta Air Lines - Airline").WebEdit("departureDate_0").Set OutDate



RE: Can you do functions by calling filename or any other better ways? - falvi - 05-28-2012

you should look into function library, it is an external file, can contain functions and objects/variables.


RE: Can you do functions by calling filename or any other better ways? - chong67 - 05-29-2012

I got it working the first time. It was not that hard. I just google it. I just didnt know its called 'function library'

You need to go to Resources Tab and do "Associated Function Librarys".

I dont know if this is good programming or not.

I am still learning.

=============
' I save this to a file

Code:
Dim  RndValue
Randomize
RndValue = Int(  (300-200 +1)* Rnd + 200)

Public Function OutDate()
     OD = DateAdd("d", RndValue, Date)
     OutDate = OD
End Function

Public Function ReturnDate()
    RD= DateAdd("d", RndValue+10, Date)
    ReturnDate = RD
End Function

======================
'Put this in expert view:

Code:
Browser("Delta Air Lines - Airline_2").Page("Delta - Book a flight").WebEdit("departureDate[0]").Set OutDate
Browser("Delta Air Lines - Airline_2").Page("Delta - Book a flight_14").WebEdit("departureDate[1]").Set ReturnDate