Forum Discussion

elyush's avatar
elyush
Occasional Contributor
15 years ago

can i declare array with one element?

Hi !

I have declared array, and now i want to add one item in array, and when i execute, i get en error!

 can't i declare array with  1 length,? i mean can't i have array with one element?



For example



MyStruct = DLL.DefineType("TemplateCodesStruct", VT_VARIANT, "Value")

Set TemplateCode = DLL.New("TemplateCodesStruct",1)

TemplateCode.Item(0).Value = "AEdit"





And the error was "Objecy doesn't support this property or method TemplateCode.Item:"






5 Replies

  • elyush's avatar
    elyush
    Occasional Contributor
    Heeyy.. :( can u help me?



    Thanks in advance..
  • Count The number of the elements to be created. By default, it is 1, which means that you are creating one instance of the specified type. If Count is greater than 1, it means that you are creating an array of elements of the specified type.  -- copied from TestComplete help


        Try this, 



        ...

       MyStruct = DLL.DefineType("TemplateCodesStruct", VT_VARIANT, "Value")

       Set TemplateCode = DLL.New("TemplateCodesStruct",2)

       TemplateCode.Item(0).Value = "AEdit"

        

        I think the count should be 2, which means array ... hope this hels.



    Nancy
  • elyush's avatar
    elyush
    Occasional Contributor
    sooo, can't i have an array with one element?? i always must have min 2 elements in array....?



    MyStruct = DLL.DefineType("TemplateCodesStruct", VT_VARIANT, "Value")

       Set TemplateCode = DLL.New("TemplateCodesStruct",1)

  • It sounds Yes. Well if your array only has one item, why do you need an array? Or you can create an 2 items array, but only put one item in, leave item(1) as null, TestComplete will still pass the test...



    Nancy

  • Hi Elya,





    As far as we understand, an array consisting of one object of a specific type and an object of this type do not differ, and your code should work fine with a single object even if it is expecting an array. If this is not your case, could you please post here the signature or declaration of the function you are working with so we can recreate this situation here?