Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


VBScript Functions

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> VBScript Functions
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 VBScript Functions - 7/12/2004 7:34:28 AM   
  Turkey

 

Posts: 19
Score: 0
Joined: 7/12/2004
From:
Status: offline
In C++ you can have Functions, which allow you to jump to an area of code, and do various things with it. They're very useful. I was wondering if anyone could tell me the closest thing in VBScript to these, and pretty much every Function(or whatever they're called)-related command they could remember.
Basically, I need a command to jump to preset areas of code - that's the main thing.
Thanks.

_____________________________

There are 10 types of people in the world; those who understand Binary and those who don't.
 
 
Post #: 1
 
 Re: VBScript Functions - 7/12/2004 9:14:45 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
While I am not familiar with C++ I do not think that functions in Vbscript work in the way you might be thinking. If I am following you, you are talking about checking for something then moving to a section of the script to perform something else.

i.e.
If X = Y goto HERE
If Y<>X goto THERE

Here
Some code
Goto somewhere else
THERE
Some code
etc.

You would call your function in the script any time that it was needed. One function I use is to retrive what OS the script is running on,

Call GetTheOS or strOS = GetTheOS or msgbox GetTheOS
Would call the function which would then perform a command and return a value or just do something specified.

This can explain it better than I could, taken from http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en

Function Procedures
A Function procedure is a series of VBScript statements enclosed by the Function and End Function statements. A Function procedure is similar to a Sub procedure, but can also return a value. A Function procedure can take arguments (constants, variables, or expressions that are passed to it by a calling procedure). If a Function procedure has no arguments, its Function statement must include an empty set of parentheses. A Function returns a value by assigning a value to its name in one or more statements of the procedure. The return type of a Function is always a Variant.

In the following example, the Celsius function calculates degrees Celsius from degrees Fahrenheit. When the function is called from the ConvertTemp Sub procedure, a variable containing the argument value is passed to the function. The result of the calculation is returned to the calling procedure and displayed in a message box.

Sub ConvertTemp()
temp = InputBox("Please enter the temperature in degrees F.", 1)
MsgBox "The temperature is " & Celsius(temp) & " degrees C."
End Sub

Function Celsius(fDegrees)
Celsius = (fDegrees - 32) * 5 / 9
End Function

(in reply to Turkey)
 
 
Post #: 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 >> VBScript Functions Page: [1]
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