SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 4 of 4
  1. #1
    Member
    Join Date
    Mar 2010
    Posts
    40
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Passing Dynamic Array to Function calls

    Hi ,

    I am passing dynamic array to function as ByRef function parameter. New elements appended to array but when array is returned ,called function losses all the new appended elements . Here is what I am doing


    Function CheckLinks(Browser , Page, ByRef links() )
    CheckLinks= True
    Dim listofLinks(),linkscount
    linkscount = UBound(links)
    ReDim Preserve listofLinks(linkscount)
    'listofLinks=links - this assginment didn't work

    For i = 0 to linkscount
    listofLinks(i)=links(i)
    Next

    ' added few more links to the list
    For j=0 to 4
    ReDim Preserve listofLinks(linkscount+j)
    listofLinks(linkscount+j) = "New Link"
    Next
    ' now listofLinks has 5 more links.
    CheckLinks = listofLinks
    End Function

    'Call from the Function1
    Function Function1( Browser, Page , ByRef links() )
    'links() has say 10 links before calling checklinks function.
    call checkLinks(Browser , Page, links)
    End Function

    instead of 15 elements link() array has original 10 elements only.

    Could someone explain me how dynamic array passing is done in QTP/VB

    Thanks in advance..

  2. #2
    Member
    Join Date
    Aug 2008
    Posts
    150
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Passing Dynamic Array to Function calls

    Try including the dimension of the array you are resizing. This is necessary for multiple dimension arrays, it may also be fore single dimension.

    ReDim Preserve listofLinks(1, linkscount+j)

  3. #3
    Advanced Member KishoreApplabs's Avatar
    Join Date
    Oct 2006
    Posts
    965
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Passing Dynamic Array to Function calls


    check with this logic may be this will be help for you logic

    If strText <> "" Then

    'Has the array been dimensioned?
    If blDimensioned = True Then

    'Yes, so extend the array one element large than its current upper bound.
    'Without the "Preserve" keyword below, the previous elements in our array would be erased with the resizing
    ReDim Preserve strSongNames(0 To UBound(strSongNames) + 1) As String

    Else

    'No, so dimension it and flag it as dimensioned.
    ReDim strSongNames(0 To 0) As String
    blDimensioned = True

    End If

    Regards,
    Kishore

  4. #4
    Member
    Join Date
    Mar 2010
    Posts
    40
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Passing Dynamic Array to Function calls


    I am resizing the array with preserve everytime new element is added.

    'Below is code in CheckLink Function

    For j=0 to 4
    ReDim Preserve listofLinks(linkscount+j)
    listofLinks(linkscount+j) = "New Link"
    Next

    But when CheckLink() function is called Function , data is not preserving.

    'Call from the Function1
    Function Function1( Browser, Page , ByRef links() )
    'links() has 10 links before calling CheckLinks function.
    call checkLinks(Browser , Page, links)
    End Function

    instead of 15 elements link() array has original 10 elements only.


    Kishore - I am not very clear with your logic. Could you please explain more....

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 10.71%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 01:49 PM.

Copyright BetaSoft Inc.