June 2006
Intermediate to advanced
1344 pages
42h 52m
English
Functions (known as Function procedures in earlier versions of Visual Basic) are methods that return a value to the caller (whereas subroutines do not). The console application in Fig. 7.2 uses the function Square to calculate the squares of the integers from 1–10.
1 ' Fig. 7.2: SquareInteger.vb 2 ' Function that squares a number. 3 Module SquareInteger 4 Sub Main() 5 Console.WriteLine("Number" & vbTab & "Square") 6 7 ' square integers from 1 to 10 8 For counter As Integer = 1 To 10 9 Console.WriteLine(counter & vbTab & Square(counter)) 10 Next 11 End Sub ' Main 12 13 ' function Square is executed when it is explicitly called 14 Function Square(ByVal y ... |
Read now
Unlock full access