Micro Focus QTP (UFT) Forums
Pass reference to datatable into function - 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Pass reference to datatable into function (/Thread-Pass-reference-to-datatable-into-function)



Pass reference to datatable into function - smallsteve - 09-28-2017

I wish to pass the name of a datatable into a function, such that the function can then retrieve values from said datatable. I tried passing the name as text, but it didn't work. I've also spent a fair amount of time looking around the web for different ideas, to no avail.

I suspect I need to pass the name as an object reference or perhaps a control, but i've never used OO before (although i've read a fair bit about it) and so i'm struggling. Is anyone able to point me in the right direction?

TIA


RE: Pass reference to datatable into function - Ankur - 09-28-2017

Please show what you have tried.


RE: Pass reference to datatable into function - smallsteve - 09-28-2017

Thanks for your assistance. As it happens, I managed to determine that my reference to the name of the datatable was missing a character, hence the reason it wasn't working. Doh!

For the benefit of others, I was calling a function and passing it the name of a particular datatable that I wanted it to collect information from:


Code:
myRtnVar = myFunction ("my_dt_name", myTestVariable)


Then, inside the function I wanted to use the forwarded dt reference (locally known as 'dtbl') to collect specific information from that dt. For example:


Code:
numOfRows = DataTable.GetSheet(dtbl).GetRowCount


I wasn't sure if it was even possible to do this in such a simplistic manner and so when it failed, I failed to spot the obvious error. Anyway, it works fine now that I have used the correct name.

Thanks again.