Login | |
|
 |
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
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|