SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Member
    Join Date
    Aug 2007
    Posts
    90
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Preserving array across iterations

    Hi,

    I am creating an array in first iteration and in second iteration i want to use the array values. Please tell how can i do this?


    Thanks,
    Preet

  2. #2
    Moderator
    Join Date
    Jul 2005
    Location
    Delhi
    Posts
    15,575
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    7 Thread(s)
    Total Downloaded
    0

    Re: Preserving array across iterations

    Declare the array in a VBS file and associate the VBS file to the test. Then it will be available across actions

  3. #3
    Junior Member
    Join Date
    Nov 2004
    Location
    India
    Posts
    28
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Preserving array across iterations

    Do you need to access the data that gets populated through various iterations?

  4. #4
    Member
    Join Date
    Aug 2007
    Posts
    90
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Preserving array across iterations

    Hi,

    Is there any other way other than declaring the array in vbs file, like using environment variables?

    Also,
    When i declare the array as dynamic (in vbs file) and try using it in script , i get general run error. It works for a fixed length array.

    Dynamic array case:-
    Declaration in vbs - Public myarray()
    Usage in main script- myarray(0)="value1"

    How to fix this. I want the array to be declared as dynamic instead of fixed length.

    Thanks,
    Preet

  5. #5
    Moderator
    Join Date
    Jul 2005
    Location
    Delhi
    Posts
    15,575
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    7 Thread(s)
    Total Downloaded
    0

    Re: Preserving array across iterations

    You need to look at the ReDIm statement

    <font class="small">Code:</font><hr /><pre>
    'Your VBS:
    Dim MyArray

    'Action 1:
    ReDim MyArray(0)
    MyArray(0) = "Test"

    'Action 2:
    ReDim Preserve MyArray(2)
    MyArray(1) = "Testing"
    </pre><hr />
    Msgbox MyArray(0)

  6. #6
    Member
    Join Date
    Aug 2007
    Posts
    90
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Preserving array across iterations

    Tarun, this is correct but when ever i try to add values to a dynamic array i always get the error "subscript out of range".

    eg.
    dim myarray()
    myarray(0)="John"
    why above step always give "subscript out of range" error.

    Is it that we can't use dynamic arrays unless we fix them using redim. If this is true then whats the meaning of dynamic in this.
    In my case i dont know how many values i will be storing in the array so i cant fix its length.

    Thanks,
    Preet

  7. #7
    Moderator
    Join Date
    Jul 2005
    Location
    Delhi
    Posts
    15,575
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    7 Thread(s)
    Total Downloaded
    0

    Re: Preserving array across iterations

    Yes you need to atleast one ReDim before using a dynamic array.

    If you don't know how many value you would be storing you can just increase the array whenever you want.

    increase array size by 1
    Redim preserve myarray(UBound(myarray) + 1)

  8. #8
    Member
    Join Date
    Aug 2007
    Posts
    90
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Preserving array across iterations

    Ok...
    Thanks Tarun

  9. #9
    Junior Member
    Join Date
    Feb 2008
    Posts
    13
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Preserving array across iterations

    I have similar problem with multidimensional arrays.
    The array has two dimensions. The 2nd dimension remain fix and 1st dimension of the array is dynamic. Example:

    Dim MyArray

    dimension1 = 0

    ReDim MyArray( 0, 1 )

    for i = 0 To 12345
    dimension1 = dimension1 + 1
    ReDim Preserve MyArray( dimension1 , 1 )
    next
    .... etc

    First execution of 'ReDim Preserve MyArray( dimension1 , 1 )' was without error. Second execution (dimension = 2)
    terminated with "subscript out of range"-error.

    Has anyone an idea how to solve this issue?

    Thanks
    DadoZu

  10. #10
    Moderator
    Join Date
    Jul 2005
    Location
    Delhi
    Posts
    15,575
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    7 Thread(s)
    Total Downloaded
    0

    Re: Preserving array across iterations

    The ReDim Preserve only allows you to change the last dimension and not anything else.

 

 
Page 1 of 2 12 LastLast

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 11:41 AM.

Copyright BetaSoft Inc.