Visual Basic has a number of built in functions and constants that you can use. In this lesson, we will look at several that are representative of the functions and constants available to you.

PI Start a new project and name it Fun. We will add several button as we go along.
We will start with a Label label called LblMessage and a Button buttoncalled BtnPI.

Click on BtnPI and write the code as shown below:


Private Sub BtnPI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
      Handles BtnPI.Click
   Me.LblMessage.Text = "The value of PI is " & System.Math.PI
End Sub

Note that we have used the concatenation operator, &, to paste together the string literal "The value of PI is " and the value of the constant PI.

PI is found by typing System "dot", then selecting Math, another dot and then selecting PI.

If you move the mouse over System.Math.PI and wait for the tool tip you will see the declaration of PI as Double. (Double is a numeric type that includes decimal places.)

const



Run the program and click the button to see the result displayed in the label.

Experiment: Another constant is System.Math.E. Add another button to the program to display the value of E. (Note that System.Math.E is not the same as e that is the argument received by the procedure.)


INDEX, Built in Functions and Constants, Functions, Random Numbers, How Random Numbers Work, RGB Colors, Random Colors
Next lesson: Visual Basic Calculations

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

Built in Functions and Constants