0

I am new to vbscript and trying to use the below code with a Function and then a Sub Procedure. I am confused as to why I have to "call" the function as it should itself return the value without calling the function. Please see the below pieces of code - one with Function and the other one with Sub Procedure.

Function -

Systemutil.Run"C:\Program Files\Internet Explorer\iexplore.exe","www.gmail.com"

Function tester()
    Set tester=Description.Create
    tester=Browser("title:=Gmail").Page("title:=Gmail").WebButton("html id:=next").GetROProperty("Name")
    print tester
End Function

Call tester

If I don't call the function, it doesn't return anything.

I have used function name as a variable to output the value.

Sub Procedure-

Systemutil.Run"C:\Program Files\Internet Explorer\iexplore.exe","www.gmail.com"

Sub tester()
    Set X=Description.Create
    X=Browser("title:=Gmail").Page("title:=Gmail").WebButton("html id:=next").GetROProperty("Name")
    print X
End Sub

Call tester

My question is why doesn't the first script work without calling the Function.

Community
  • 1
  • 1

1 Answers1

1

The first part of your code only defines your function. It doesn't execute the code in it yet.

Whether it returns a value or not is irrelevant. If you want the code in your function or sub to execute, you must call it.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794