Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


RE: Another function question

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,45440
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: Another function question
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: <<   < prev  1 [2]
Login
Message << Older Topic   Newer Topic >>
 RE: Another function question - 4/26/2007 7:18:46 PM   
  ginolard


Posts: 1020
Score: 21
Joined: 8/10/2005
Status: offline
And so we touch upon Global Variables again.  If you want the variable strComputer to be available outside of the function it has to be global.  This is, generally, frowned upon by people on here (I'm a little more accepting of them).  You can pass the VALUE of strComputer outside of the function by making the Function equal to StrComputer


      

As it stands the strComputer variable in that function is redundant.  It doesn't do anything other than assign itself a value.  You could just as easily do


      

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to sheepz)
 
 
Post #: 21
 
 RE: Another function question - 4/27/2007 1:01:30 AM  1 votes
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Another way to return multiple values from a function is to return an array or a dictionary.


Dim dicRet

Set dicRet = SomeFunc()
WScript.Echo dicRet("Foo")
WScript.Echo dicRet("Other")

Function SomeFunc
Dim dicTemp

Set dicTemp = CreateObject("Scripting.Dictionary")
dicTemp.Add "Foo", "Bar"
dicTemp.Add "Other", "Things"

SomeFunc = dicTemp
End Function

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ginolard)
 
 
Post #: 22
 
 RE: Another function question - 4/27/2007 4:04:55 AM   
  Skie

 

Posts: 58
Score: 0
Joined: 3/2/2006
Status: offline
quote:

ORIGINAL: ebgreen

Another way to return multiple values from a function is to return an array or a dictionary.


I'd never thought to use a dictionary to return multiple items from a function.  I've created a global dictionary for use, but never directly returned a dictionary.  Thanks for the tip, that'll eliminate most of the global variables I have in my code.

(in reply to ebgreen)
 
 
Post #: 23
 
 RE: Another function question - 4/27/2007 9:37:17 PM   
  ehvbs

 

Posts: 2061
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
quote:

ORIGINAL: ebgreen

Another way to return multiple values from a function is to return an array or a dictionary.


Dim dicRet

Set dicRet = SomeFunc()
WScript.Echo dicRet("Foo")
WScript.Echo dicRet("Other")

Function SomeFunc
Dim dicTemp

Set dicTemp = CreateObject("Scripting.Dictionary")
dicTemp.Add "Foo", "Bar"
dicTemp.Add "Other", "Things"

SomeFunc = dicTemp
End Function


Set SomeFunc = dicTemp

(in reply to ebgreen)
 
 
Post #: 24
 
 RE: Another function question - 4/30/2007 1:28:13 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Ooops..good catch ehvbs. That is what I get for just typing out code instead of testing it first.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ehvbs)
 
 
Post #: 25
 
 
Page:  <<   < prev  1 [2]
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: Another function question Page: <<   < prev  1 [2]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts