User:Klever: Difference between revisions

Content added Content deleted
Line 15: Line 15:


In MS Office program (Word, Excel, Access...): open the Visual Basic window. Paste the code in a module. Execute it by typing a suitable command in the Immediate Window. Output will be directed to the Immediate Window unless stated otherwise...
In MS Office program (Word, Excel, Access...): open the Visual Basic window. Paste the code in a module. Execute it by typing a suitable command in the Immediate Window. Output will be directed to the Immediate Window unless stated otherwise...

==[[Greatest element of a list]]==
<lang>
Public Function ListMax(anArray())
'return the greatest element in array anArray whose length is unknown to this function
n0 = LBound(anArray)
n = UBound(anArray)
theMax = anArray(n0)
For i = (n0 + 1) To n
If anArray(i) > theMax Then theMax = anArray(i)
Next
ListMax = theMax
End Function


Public Sub ListMaxTest()
Dim b()
'test function ListMax
'fill array b with some numbers:
b = Array(5992424433449#, 4534344439984#, 551344678, 99800000#)
'print the greatest element
Debug.Print "Greatest element is"; ListMax(b())
End Sub
</lang>

Result:
<pre>
ListMaxTest
Greatest element is 5992424433449
</pre>


==[[Reverse a string]]==
==[[Reverse a string]]==