There are the following categories of in-built functions or library functions available in VB .net :  –

(1.) VB Math in-Built Functions

  • CInt()
    • This function is used to convert the value(practically numeric) of different data types into an integer type.
    • Syntax: CInt(val)
  • Fix()
    • Fix Function in Visual Basic.net is used to return the integer part of the given number. But when the number is negative it returns a negative number greater than or equal to the number.
    • Syntax: Fix(Number)
    • Example:
Module Module1
     Sub Main()
          Console.WriteLine(“Integer part of 12.27 is: ” & Fix(12.27))
          Console.WriteLine(“Integer part of 0.23 is: ” & Fix(0.23))
          Console.WriteLine(“Integer part of -4.2 is: ” & Fix(-4.2))
          Console.WriteLine(“Integer part of -8.8 is: ” & Fix(-8.8))
          Console.ReadLine()
     End Sub
End Module
                   
                        Output: 
                                  Integer part of 12.27 is: 12
                                  Integer part of 0.23 is: 0
                                  Integer part of -4.2 is: -4
                                  Integer part of -8.8 is: -8
  • Hex()
    • The Hex() function is used to convert the corresponding number into its Hexadecimal value.
    • Syntax: Hex(number)
  • Math.Abs():
    • Math.Abs() Function in VB.net is used to return the absolute value of a number.
    • Syntax: Math.Abs(number)
    • Example: 
 Module Module1
     Sub Main()
          Console.WriteLine(“Absolute Value of -5 is = ” & Math.Abs(-55))
          Console.WriteLine(“Absolute Value of 5.5 is = ” & Math.Abs(-5.53))
          Console.ReadLine()
     End Sub
End Module
Output: 
Absolute Value of -5 is = 55
Absolute Value of 5.5 is = 5.53
  • Math.Exp():
    • The Math.Exp() function returns the exponential value of a number.
    • Syntax: Math.Exp(num)
  • Math.Log():
    • The Math.Log() function returns the natural logarithm of a number.
    • Syntax: Math.Log(num)
  • Math.Sqrt()
    • The Math.Sqrt() function is used to return the square root of a number(num).
    • Syntax: Math.Sqrt(num)
  • Oct()
    • The Oct() function is used to convert the corresponding number into its Octal value.
    • Syntax: Oct(number)
  • Rnd()
    • The Rnd() function is used to Return a randomly generated value between 0 and 1.
    • Syntax: Rnd(num)
  • Val()
    • Val() function is used to convert a numeric string into an integer number.
    • Syntax: Val(numeric_string)
    • Example: Val(“245”)

Output: 245 [in numeric form]

(2.) VB String in-Built Functions

  • Asc()
    • The function Asc() is used to obtain the corresponding ASCII value of the given character (letter).
    • Syntax: Asc(character)
    • Example: 
Module Module1
     Sub Main()
          Dim val As Integer
          val = Asc(“m”)
          Console.WriteLine(“Ascii value = {0}”, val)
     End Sub
End Module
        Output:
        Ascii value = 109
  • Chr()
    • The Chr() function returns the corresponding ASCII value for the character(numeric value).
    • Syntax: Chr(Num)
    • Example: 
Module Module1
Sub Main()
Dim num As Integer = 75
Dim ch As Char
ch = Chr(num)
Console.WriteLine(“Character is = {0}”, ch)
End Sub
End Module
Output:
     Character is = K
  • CStr()
    • This function is used to convert the value of different data types into a string type.
    • Syntax: CStr(val)
  • InputBox()
    • The InputBox() function displays a pop-up input box to take user inputs at run time with a user-customized message.
    • Syntax : returnString = InputBox (prompt, title, defaultText, xpos, ypos)
      • The returnString is the value returned by the InputBox() function which is the text entered by the user.
      • The prompt parameter is a text string (either a string literal or a string variable) given by the programmer that prompts the user to guide/enter some information.
      • The title parameter is another string literal or string variable that supplies the title for the input box.
      • The defaultText parameter can be used to enter default content in the input box (although it would probably leave blank in most cases).
      • The xpos and ypos parameters specify the x and y coordinates for the input box on the screen.
  • LCase()
    • The LCase() function is used to convert the specified string into a lowercase string.
    • Syntax: LCase(String)
  • LTrim()
    • This function removes the extra white space (if any) at the left-hand end of the text string.
    • Syntax: LTrim(Str)
  • Msgbox()
    • The MsgBox() function displays a customized message in a pop-up message box. 
    • The format/syntax of the statement used to invoke a message box is as follows: –
      returnVal = MsgBox (prompt, styleVal, title)
      • The prompt parameter is a string value (either a string literal or a string variable) that gives the message to be displayed.
      • The styleVal parameter is either an integer style value, from 0 to 5, or a named constant that can be used instead of the corresponding integer value, that determines which command buttons will appear on the message box.
      • The title parameter is another string literal or string variable that supplies the title for the message box.            

VB .Net String in-built Functions : Coders Helpline

    • For Example:

(i) MsgBox (“This message is for info!”, 64, “Info”)
(ii) MsgBox (“This message is for info!”, vbOKOnly + vbInformation, “Info”)

  • RTrim()
    • This function removes the extra white space (if any) at the right-hand end of the text string.
    • Syntax: RTrim(Str)
  • Trim()
    • This function removes the extra white space (if any) at either end of the text string.
    • Syntax: Trim(Str)
  • UCase()
    • The UCase() function is used to convert the specified string into an uppercase string.
    • Syntax: UCase(String)

(3.) VB Date & Time in-Built Functions

  • Format()  [ For more details use this link ]
    • The Format() function is used to specify how date and time values are displayed. 
    • Syntax: Format (Date/Now, “styleArguments”)

 Here, styleArguments value may be – 

     Style Arguments                           Description
“General Date” Displays the date and time value in the format – 
    dd/mm/yyyy hh:mm:ss
“Long Date” Displays the date value in the format –
    06 October 2009
“Short Date” Displays the date value in the format –
    dd/mm/yyyy
“Long Time” Displays the time value in the format –
    h:mm:ss
“Short Time” Displays the time value in the format –
    hh:mm

Loading


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.