SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 3 of 3
  1. #1
    Member
    Join Date
    Jan 2007
    Location
    twin cities
    Posts
    81
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Frustration with the ArrayObject object

    So here I am, trying to simply work with arrays in TestComplete, in VB. I am getting nowhere fast.

    I dream of using arrays without hassle, and with ample support methods like AddItem and such. Plain 'ol arrays in VB aren't working well for me, and of course, errors out when I try to use it.

    Searching high and low for some very basic sample code in vb to incorporate has resulted in failure. What I'm looking for is an array of strings. Those strings are a list of files in a directory. I have a simple loop to enumerate files in a list. I figure drop an AddItem statement in the loop & call it a day.

    Can someone throw me a bone here? I am tired of "type mismatch" and "object required" errors here. I don't even know what the syntax is to declare an arraytype object. That's my current stumbling block.

  2. #2
    Moderator tristaanogre's Avatar
    Join Date
    Mar 2006
    Location
    Pennsylvania, USA
    Posts
    1,792
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Frustration with the ArrayObject object

    Here's a quick sample of how to use ODT Data Groups and Variables to create quick, loopable arrays. I don't have a loop built into this code but, hopefully, this should give you some of the basic syntax. Without knowing more about what you have tried I'm afraid I can't do much more.

    <font class="small">Code:</font><hr /><pre>
    {DelphiScript code}
    procedure FunWithArrays;

    var
    DataGroup,
    ArrayVar;

    begin
    try
    if ODT.Data.Groups['TestArrays'] &lt;&gt; nil then
    ODT.Data.DeleteGroup['TestArrays'];
    DataGroup := ODT.Data.AddGroup('TestArrays');
    ArrayVar := DataGroup.AddVarofArrayType('FileNameArray');
    ArrayVar.AddItem('File1');
    ArrayVar.AddItem('File2');
    ArrayVar.AddItem('File3');


    except
    Log.Error('Exception', ExceptionMessage)
    end;
    end;
    </pre><hr />

    The above code works great in DelphiScript. I'm not a VB script dude so the best I can do is
    <font class="small">Code:</font><hr /><pre>
    'VBScript
    Sub Main

    if IsSupported(ODT.Data, "TestArrays") then
    ODT.Data.DeleteGroup("TestArrays")
    end if
    set DataGroup = ODT.Data.AddGroup("TestArrays")
    set ArrayVar = DataGroup.AddVarOfArrayType("FileNames")
    ArrayVar.AddItem("File1")
    ArrayVar.AddItem("File2")
    ArrayVar.AddItem("File3")
    Log.Message(ArrayVar.Items(0))
    Log.Message(ArrayVar.Items(1))
    Log.Message(ArrayVar.Items(2))
    End Sub
    </pre><hr />
    -Robert Martin
    Automated Testing Evangelists
    TestComplete "expert"
    Definition expert - noun - Unknown drip under pressure

  3. #3
    SQA Knight
    Join Date
    May 2006
    Location
    Playa Del Rey, California, United States
    Posts
    2,594
    Post Thanks / Like
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Total Downloaded
    0

    Re: Frustration with the ArrayObject object

    Vbscript has very annoying arrays. Anytime you need to resize them, you need to use the "Redim Preserve" keyword. It's also confusing because an Array in VBScript isn't an object, it's a basic type.

    Declearing an array:
    dim myarray = Array("item1", "item2") 'etc...

    Resizing an array
    Redim Reserve myarray(20) 'resizes the array to length 20

    Looping through arrays..
    for i=LBound(myarray) to UBound(myarray)
    MsgBox myarray(i)
    next i


    Let's say you want to create an array and add an item in the back, the code will look like..

    dim myarray = array()
    for each myobject in myenum
    Redim Preserve myarray(UBound(myarray) + 1)
    set myarray(UBound(myarray)) = myobject
    next
    David Lai
    SDET / Consultant
    LinkedIn profile

 

 

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

Copyright BetaSoft Inc.