Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
While calling sub procedure its giving error
#2
Not Solved
Hi ,

Sub procedure will not return any value , so you will not be able to call it and expect a return result out of it. You have to use the 'function' instead to return the value. U can give directly the 'function name' to return any value.

I have modified your code try out:

Code:
Function result(val)
If val=0 Then
result =  "its zero"             '**To return the value
elseif val=1 then
result = "its one"
elseif val=2 then
result =  "its two"
else
result = "out of range"
end if
end Function

sub getval()
val3 = cint(inputbox("enter the val"))           '***see below
msgbox "val is " & result(val3)
End sub

call getval()   '*****


***Here I have converted the input box entry to 'Cint' because VB script only uses a variable called 'Varient' , you have convert it to integer using 'cint'.
**Also i have assigned the 'msgbox' value directly to the function name to make your function returns some value.
**** You have to use 'call' statement while calling a 'sub' , but it is not mandatory in case of 'function' call.


Thanks,
Harish
Reply


Messages In This Thread
RE: While calling sub procedure its giving error - by harishshenoy - 10-22-2012, 01:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  calling QTP script from one to another krishnas.tester 3 6,481 11-12-2014, 10:32 AM
Last Post: vinod123
  GetVisibleText giving Junk Values anushreebehura 1 2,779 04-02-2013, 10:27 AM
Last Post: K Gaurav Varshney
  calling stored procedure from Oracle borisk 3 6,213 03-19-2013, 12:41 PM
Last Post: gaveyom
  Function is not calling from subdriver qtpexpert 0 1,987 01-18-2013, 12:25 PM
Last Post: qtpexpert
  Calling dll C# in VBScript nacchio 0 3,050 10-11-2011, 07:32 PM
Last Post: nacchio

Forum Jump:


Users browsing this thread: 2 Guest(s)