Beheld Basal Software Tutorials - Tutorial Addendum - Procedures - Functions and Subroutines
| |
(Continued from antecedent part...)
Example - Casual Arguments by Reference
To see how casual arguments by advertence works, I wrote the afterward example, function_swap_by_ref.html:
<html>
<body>
<!-- function_swap_by_ref.html
Absorb (c) 2006 by Dr. Yang. http://www.yang.com/
-->
<pre>
<script language="vbscript">
document.writeln("")
document.writeln("Test 1: Swapping two literals by reference")
document.writeln(" Afore Sub: " & "Apple" & " | " & "Orange")
Alarm SwapByRef("Apple", "Orange")
document.writeln(" Afterwards Sub: " & "Apple" & " | " & "Orange")
vFirst = "Dog"
vSecond = "Cat"
document.writeln("")
document.writeln("Test 2: Swapping two variables by reference")
document.writeln(" Afore Sub: " & vFirst & " | " & vSecond)
Alarm SwapByRef(vFirst, vSecond)
document.writeln(" Afterwards Sub: " & vFirst & " | " & vSecond)
Sub SwapByRef(ByRef vLeft, ByRef vRight)
vTemp = vLeft
vLeft = vRight
vRight = vTemp
document.writeln(" In Sub: " & vLeft & " | " & vRight)
End Sub
</script>
</pre>
</body>
</html>
Here is the output:
Test 1: Swapping two literals by reference
Afore Sub: Angel | Orange
In Sub: Orange | Apple
Afterwards Sub: Angel | Orange
Test 2: Swapping two variables by reference
Afore Sub: Dog | Cat
In Sub: Cat | Dog
Afterwards Sub: Cat | Dog
Here are my comments about this example:
- Test 1 shows that data accurate can be acclimated for a "ByRef" argument.
By you will not be able to accept the change done by the subroutine.
- Test 2 shows that using capricious for a "ByRef" altercation lets to accept the change
by the subroutine. Afterwards the subroutine call, ethics in vFirst and vSecond accept been swapped.
- "ByRef" keyword is optional.
Example - Casual Arguments by Value
To see how casual arguments by amount works, I wrote the afterward example, function_swap_by_val.html:
<html>
<body>
<!-- function_swap_by_val.html
Absorb (c) 2006 by Dr. Yang. http://www.yang.com/
-->
<pre>
<script language="vbscript">
document.writeln("")
document.writeln("Test 1: Swapping two literals by value")
document.writeln(" Afore Sub: " & "Apple" & " | " & "Orange")
Alarm SwapByVal("Apple", "Orange")
document.writeln(" Afterwards Sub: " & "Apple" & " | " & "Orange")
vFirst = "Dog"
vSecond = "Cat"
document.writeln("")
document.writeln("Test 2: Swapping two variables by value")
document.writeln(" Afore Sub: " & vFirst & " | " & vSecond)
Alarm SwapByVal(vFirst, vSecond)
document.writeln(" Afterwards Sub: " & vFirst & " | " & vSecond)
Sub SwapByVal(ByVal vLeft, ByVal vRight)
vTemp = vLeft
vLeft = vRight
vRight = vTemp
document.writeln(" In Sub: " & vLeft & " | " & vRight)
End Sub
</script>
</pre>
</body>
</html>
(Continued on next part...)
|
document, writeln, vfirst, vsecond, vleft, vright, orange, swapping, reference, byref, example, function, arguments, html>, body>, vtemp, passing, script, pre>, swapbyval, subroutine, value, literals, swapbyref, variables, , document writeln, sub &, swapping two, & apple, & orange, writeln after, vright vtemp, & vsecond, vfirst &, & vfirst, writeln before, writeln test, < body>, < html>, function swap, body> <, < pre>, writeln document, pre> <, passing arguments, document writeln before, document writeln test, writeln document writeln, sub & apple, document writeln after, & vfirst &, sub & vfirst, document writeln document, & apple &, vright vtemp vleft, vtemp vleft vleft, vsecond document writeln, vfirst vsecond document, basic script tutorials, & vsecond call, vleft vleft vright, vleft vright vright, & vleft &, value document writeln, sub & vleft, vtemp document writeln, vright vright vtemp, vright vtemp document, script tutorials tutorial, cat document writeln, following example function, example passing arguments, example function swap, > document writeln, < script language, script language vbscript, reference document writeln, notes procedures functions, tutorials tutorial notes, & orange vfirst, orange document writeln, & orange call, tutorial notes procedures, visual basic script, < function swap, |
Also see ...
(Continued from antecedent part...)Here is the output: Test 1: Swapping two literals by value Afore Sub: Angel Orange In Sub: Orange Apple Afterwards Sub: Angel Orange
(Continuedfrompreviouspart...)VariableScopeinProceduresVariableScope Theareaofsourcecodewhereavariableisaccessible.Ifyouarenotusingprocedures,variablescopeisverysimple.Thescope
This affiliate describes:Variable DeclarationAssigning Ethics to VariablesVariable Absence ValuesVariable Declaration
(Continued from antecedent part...) c = 31 i = 777 l = 777777 f = 3.14159E+27 d = 3.33333E+202 y = 999999.5555 s = "Hello" b = True t = 12/31/1999 11:30
This affiliate describes:Variable InspectionVariable Analysis ExampleParsing Continued IntegersNotes and samples in this affiliate are based Behe
(Continued from antecedent part...) document.writeln(" ") document.writeln("Checking arrays:") Dim aFixed(5) document.writeln("A1 " & GetVarInfo(aFixed) & " (Fixed)") aFixed(5) = 555p
(Continued from antecedent part...)There are a amount of absorbing addendum here:Line V3 shows that (3.14) is appear as (Double). I was assured Single.Line V6 shows that (TRUE) is appear as (Num=Y).