Forum Discussion

shivashish's avatar
shivashish
Occasional Contributor
13 years ago

Help in creating a function to form an obejct

Hi,




I want to perform the below statement


Aliases.ie.HomePage.SearchPanel.FindAHotel.SetText("London")


 To execute this statement from a framework I will create
a function EnterText which takes the following inputs


 a.       Window
Name(for the example above the value will be "Aliases.ie.HomePage.SearchPanel")


 b.      Control
name(for the example above the value will be"FindAHotel")


 c.      
Parameter(for the example above the value will be "London")


 The code snippet of the EnterText function is below


*********************************************************************************


Sub EnterText (strWindowName, strControlName, strValue)


       Set objWin = Aliases.ie.HomePage.SearchPanel


      Eval(objWin
& "." & strControlName).SetText(strValue)


 


If Err.Number <> 0 Then


 
BuiltIn.ShowMessage("Data entered correctly")


Else


 
BuiltIn.ShowMessage("Error in forming the Control. Please try
again")


End If


End sub


*************************************************************************************


I am setting the object ObjWin in the function itself to
the alias, But I am getting the error "Object doesn’t support this
property or method" when the cursor goes to Eval function


Also, can I pass the Parameter "
Aliases.ie.HomePage.SearchPanel" as strWindowName, rather than referencing
it within the function. For e.g., Can i call the EnterText function like this?


Call EnterText("Aliases.ie.HomePage.SearchPanel","FindAHotel","Test")




Can you please help me achieve my objective here(being
able to pass the required parameters to EnterText function to make it as a
modular function.  An example will help
to understand it better


Let me know if you need more details on what exactly I am
trying to achieve here


Thanks,

Shiv

6 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    I would do the following:



    Sub EnterText (strWindowName, strControlName, strValue)

           Set objWin = Eval(strWindowName)


          Set ControlObj = Eval(objWin & "." & strControlName)

          Call ControlObj.SetText(strValue)


     


    If Err.Number <> 0 Then


      BuiltIn.ShowMessage("Data entered correctly")


    Else


      BuiltIn.ShowMessage("Error in forming the Control. Please try again")


    End If


    End sub

  • shivashish's avatar
    shivashish
    Occasional Contributor
    Hi Robert,



    I had tried the same and without luck



    Infact , just to be on the safer side, i copied your reply and tried it on and there was the same error thrown "Object doesn't support this property or method" when the cursor came to Eval function



    Can there be some reference which is missing from the project?



    Thansk,

    Shiv
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    is it possible that the object referenced by strControlName does not exist in your NameMapping/Aliasing tree?  That could be the problem there.
  • shivashish's avatar
    shivashish
    Occasional Contributor
    I dont think that is a problem Robert as I ran the line below with all the objects in a single statement and it ran fine



    Aliases.ie.HomePage.SearchPanel.FindAHotel.SetText("London")



    Any other way to achieve this, that you can suggest?
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Try this:




    VBScript


    Sub EnterText (strWindowName, strControlName, strValue)

           Set ControlObj= Eval(strWindowName & "." & strControlName)


          Call ControlObj.SetText(strValue)


     


    If Err.Number <> 0 Then


      BuiltIn.ShowMessage("Data entered correctly")


    Else


      BuiltIn.ShowMessage("Error in forming the Control. Please try again")


    End If


    End sub

  • shivashish's avatar
    shivashish
    Occasional Contributor
    That did the trick Robert. Thanks a lot for your help



    Appreciate it a lot.