Forum Discussion

kktsenthil's avatar
kktsenthil
Occasional Contributor
9 years ago

Get a variable value from one Script file to another script file in VBScript

Hi All,

 

How can i get a variable value from one script file to another file in VB Script

 

File1

Dim page

set page = Aliases.browser.pageHomeLogg.frameModules

 

File2

 

I want to use the page variable in teh File2

so how can i achieve that?

6 Replies

  • Ravik's avatar
    Ravik
    Super Contributor
    Hi, you can get variable value from one file unit to another file by using "USEUNIT" write in file2 'USEUNIT file1 Sub file2Test : : : End Sub This may help you. (Define variable as global)
    • kktsenthil's avatar
      kktsenthil
      Occasional Contributor

      hi,

       

      i followed your input but its not getting the value.

      i used as 'USEUNIT File2 in vbscript anyother way is there to achieve this?

  • Lage's avatar
    Lage
    Contributor

    Hi kktsenthil

     

    Rabik is right. this is the approach.

     

    Create scripts: File1 and File2.

     

    File1:

    function function_return_value
        function_return_value = "some_value_in_file1"
    end function

    File2:

    'USEUNIT File1
    
    sub subs_cannot_retur_values
        thisValue = File1.function_return_value()
        Log.Message(thisValue)
    end sub

    Functions can return values.

    Subs cannot return values.

     

    Hope this example helps you

     

    Regards,

    Lage

    • kktsenthil's avatar
      kktsenthil
      Occasional Contributor

      File1

       

      function function_return_value

      Dim page

      set page =Aliases.browser.pageB.frameDetail.formAspnetform.paneltest.Panel("testGridDiv").Table("ASGrid")


      function_return_value = page

      end function

       

      'USEUNIT File1

      sub testing()

      Dim Addprops,Addvalue,idstrtagname, idstrtagname

      Addprops = Array("contentText", "tagName")
      Addvalues = Array("Add value", "SPAN")

      idstrtagname = File1.function_return_value()

      idstrtagname.Find(Addprops, Addvalues, 1000,true).click

      log.Message idstrtagname

      end sub

       

       

      when i run file1 i was getting an error message as 'Object doesn't support this property or method'

      guide me on this.

       

      if i want to pass a object  from one file to another file how can i do please guide me  friends..

      • Ravik's avatar
        Ravik
        Super Contributor
        HI, I thing in your code - idstrtagname.Find(Addprops, Addvalues, 1000,true).click Statement is wrong, I thought that it should like- Set onjName = idstrtagname.Find(Addprops, Addvalues, 1000,true) objName.Click This may work for you.