Returning value from VBScript function

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
mnaeem
Junior Coder
Posts: 30
Joined: Wed Mar 10, 2021 5:05 pm

Returning value from VBScript function

Post by mnaeem » Thu Oct 14, 2021 11:16 pm

Hello,
As per the documented instructions this below VBScript function is at the top of my script.

Code: Select all

VBSTART
  Function CheckIsValidPage(sourceString)
    Dim x
    CheckIsValidPage = "1"
  End Function
VBEND
Now in my script when I am executing these below mentioned 2 lines, I am not able to read the value which is 1 returned by the above vbscript function. I am supposed to receive the value in answer variable.

The MessageModel window popup shows the word answer rather its value 1

By the way I am able to see the value of answer is 1 in the watch List

Code: Select all

VBEval>CheckIsValidPage(theSource), answer
MessageModal>answer
Please advise what I am doing wrong

Thanks

User avatar
Grovkillen
Automation Wizard
Posts: 1128
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Returning value from VBScript function

Post by Grovkillen » Fri Oct 15, 2021 4:40 am

The space should be removed:

Code: Select all

VBEval>CheckIsValidPage(theSource), answer
Should be

Code: Select all

VBEval>CheckIsValidPage(theSource),answer
Let>ME=%Script%

Running: 15.0.27
version history

mnaeem
Junior Coder
Posts: 30
Joined: Wed Mar 10, 2021 5:05 pm

Re: Returning value from VBScript function

Post by mnaeem » Fri Oct 15, 2021 1:02 pm

Appreciate your support, your suggested solution worked, but I am facing strange problem and I am sure I am messing up things.
This is the vbscript function I am wrestling with.

Code: Select all

VBSTART
  Function CheckIsValidPage(sourceString)
    Dim x
    Msgbox "Inside function " + sourceString
    If Len(sourceString)=0 Then
      MsgBox "Empty Input"
    End If
    CheckIsValidPage = "0"
  End Function
VBEND
Now these below are the script lines and what I am trying to pass is simply the parameter value. When the above mentioned VBScript get evaluated it seems sourceString value is empty or null. Any suggestions.

Code: Select all

ChromeGetInfo>session_id,source,theSource
VBEval>CheckIsValidPage(theSource),answer
MessageModal>answer

User avatar
Grovkillen
Automation Wizard
Posts: 1128
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Returning value from VBScript function

Post by Grovkillen » Fri Oct 15, 2021 1:04 pm

What are you trying to accomplish?
Let>ME=%Script%

Running: 15.0.27
version history

mnaeem
Junior Coder
Posts: 30
Joined: Wed Mar 10, 2021 5:05 pm

Re: Returning value from VBScript function

Post by mnaeem » Fri Oct 15, 2021 1:54 pm

I am trying to pass parameter value to the VB script function and get the output from function using VBEval command but seems the parameter value is not being passed.

Edit

Ok finally managed to make it work.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts