Calculates the power of a value, defaults to square : Function « Class Module « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Class Module » Function 
6.2.3.Calculates the power of a value, defaults to square
Public Class Tester
   Public Shared Sub Main
      Console.WriteLine(Power(12))

      Console.WriteLine(Power(2,2))
    End Sub 
   
  ' use iteration to calculate power
   Shared Function Power(ByVal base As Integer, _
      Optional ByVal exponent As Integer = 2As Integer

      Dim total As Integer = 1
      Dim As Integer

      For i = To exponent
         total *= base
      Next

      Return total
   End Function ' Power

End Class
144
4
6.2.Function
6.2.1.Define function in a Module
6.2.2.Pass Double to a function
6.2.3.Calculates the power of a value, defaults to square
6.2.4.Assign function return value to variables
6.2.5.Call function as a statement
6.2.6.Use function in If statement
6.2.7.Function procedure to square a number.
6.2.8.Finds the maximum of three numbers input
6.2.9.Function with string return
6.2.10.Return double type value from Function
6.2.11.Define function and call it in a Module
6.2.12.Functions with different parameter number
6.2.13.Return string type value from function
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.