Student Mode Code Display

Welcome to the Fraternity!

Commenting has been enabled. You can comment on all the Code Items now.

Ways to Return values from Functions in vbScript and QTP


Add This Code to My Favourite List
Enter Email

Contributed By admin
Date 2015-01-27 04:34:19

'####################################
'Ways to Return values from Function
'####################################

'a. Single return value

Function Temp()
	Dim x
	X=5
	
	Temp= x
End Function
   
'b.Multiple values return:
Concatenate variables
Function Temp()
	Dim x,y
	X=5
	Y=6
	
	Temp= x & "~"y
End Function

'c. Save Variables in array
Function Temp()
	Dim x,y, aResult(1)
	x=5
	y=6
	aResult (0) = x
	aResult(1) = y
	Temp=aResult
End Function

'd. Return Object
Set ret = Temp()
X = ret.Item(1)
Y= ret.item(2)

Function Temp()
	Dim oDict,x,y
	X=5
	Y=8
	Set oDict = CreateObject("Scripting.Dictionary")
	oDict.Add 1,x
	oDict.Add 2,y
Set Temp= oDict
End Function

'e. Return Multiple values of different Types:

ret = Temp()
ret_1 = ret(0)
ret_2= ret(1)
ret_3 = ret(2)
Set ret_4 = ret(3)
msgbox ret_1 
msgbox ret_2
msgbox ret_3
msgbox  ret_4.FileExists("C:\QueryRandD.txt") 

'Output: 
'5, 8, "AutomationFraternity", 
'True or False dependening on the file availability.
Function Temp()
	Dim fso,x,y,str
	Dim aResult(3)
	X=5
	Y=8
	Str = "AutomationFraternity"
	
	'Object can be of any type of Object:
	' Fso, Dictionary, XML, or QTP 'hierarchy object
	'Set oBrowser = Browser("title:=.*").Page("name:=.*)
	Set fso = CreateObject("Scripting.FileSystemObject")
	aResult(0) = x
	aResult(1) = y
	aResult(2) = str
	Set aResult(3) = fso
	
	Temp= aResult 
End Function

Download Above Code

Comments:


Updated by RECPeap at 2018-06-21 06:08:53
First of all - Do not panic! In most cases, deleted files can reanimate - even if you have cleared the trash or did not used the trash when deleting files.
For successful resuscitation lost data very important execute specific activities. Do not be discouraged - for this, it is not necessary to be an expert in the field of information technology, you also do not need to pay hundreds of dollars to a specialist professional for restoration of your remote information.
<a href=http://bestdatarecovery.info/let-us-find-out-how-to-recover-data-from-hard-disk>how to recover data from hard disk</a>

Add your comments...
Name : *      
Email : *      
The content of this field will be kept private and will not be shown publicly

Your Comment/Answer *

Enter the text present in this box : *