Forum Discussion

martin_home's avatar
martin_home
Occasional Contributor
6 years ago

TestComplete VBA scripting - I want to variablise checking table checkpoints

 I have 8 Table Checkpoints( as the code below shows)

 

I would like to replace this clumsy Select Case  End Select with one  elegant statement.

 

 I would like to replace the number in the name of the checkpoint with a variable.

e.g. BT_AT_01_Chk_3 becomes BT_AT_01_Chk_varRequestCount

 

I have been unable to bend the VBA code to my will.

 

Any ideas/help much appreciated.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

For varRequestCount = 1 to 8

 

select case varRequestCount
case 1
Call Tables.BT_AT_01_Chk_1.Check
case 2
Call Tables.BT_AT_01_Chk_2.Check
case 3
Call Tables.BT_AT_01_Chk_3.Check
case 4
Call Tables.BT_AT_01_Chk_4.Check
case 5
Call Tables.BT_AT_01_Chk_5.Check
case 6
Call Tables.BT_AT_01_Chk_6.Check
case 7
Call Tables.BT_AT_01_Chk_7.Check
case 8
Call Tables.BT_AT_01_Chk_8.Check
case else
msgbox " Invalid Request Count: " & varRequestCount
end select

 

next

4 Replies

  • NisHera's avatar
    NisHera
    Valued Contributor

    not sure how in VB..

    in javascript can do like

    eval("BT_AT_01_Chk"+varRequestCount);

    here in brackets you make the string , then evaluete it ...will taken as  object

    • jab4743's avatar
      jab4743
      Contributor

      Another option:

      You could dynamically

      set the checkpoint by dynamically determining/creating the Aliases name and sending it to a common function.   Something like (in VB):

      Function Add_Region_To_Store(imagename, AliasesObject, xloc, yloc, widthloc, heightloc)

      Dim holdscreenregion

      Dim regionpanelname

       

      dim tempregion

      set holdscreenregion = Regions.CreateRegionInfo(AliasesObject, xloc, yloc, widthloc, heightloc, False

       

      regionpanelname = imagename

      Regions.AddPicture holdscreenregion, regionpanelname 

      End Function

      • martin_home's avatar
        martin_home
        Occasional Contributor

        Thanks for the idea but I wanted something simple so I will stick with the case statement. Cheers 

    • martin_home's avatar
      martin_home
      Occasional Contributor

      There is Eval statement in vbscript but this soution did not work for me. Thanks fro trying