Function 2
Upcoming SlideShare
Loading in...5

Function 2



Visual basic 2010 functions

Visual basic 2010 functions



Total Views
Views on SlideShare
Embed Views



1 Embed 1 1


Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Function 2 Function 2 Presentation Transcript

    • Electroteam__@hotmail.comInteresting EducationElectro-TeamVisual Basic 2010Functions II
    • This Slides Will Cover1. The Right Function.2. The Left Function.3. The Trim Function.4. The Ltrim & Rtrim Function.5. The InStr function.6. The Ucase and the Lcase Functions.7. The Abs Function.8. The Exp function..9. The Fix Function.10. The Int Function.11. The Rnd( ) Function.12. The Round Function.
    • Open new project and add 2 Labels, 1 Textbox and 1 Button
    • 1. The Right FunctionThe format is:-Microsoft.Visualbasic.Right ("Phrase", n)ExampleMicrosoft.Visualbasic.Right (“Hello World", 5)=World
    • Label1Text = Right FunctionFont = 18 , BoldFormat Center in FormHorizontallyLabel2Text = …………Font = 16 , BoldButton1Text = GoFont = 14 , BoldForm1Text = Right Function Ex.Start Position = Center Screen
    • Button1 CodePrivate Sub Button1_ClickLabel2.Text = Microsoft.VisualBasic.Right(TextBox1.Text, 5)End Sub
    • 2. The Left FunctionThe format is:-Microsoft.Visualbasic.Left ("Phrase", n)Modify Previous Program code ..Private Sub Button1_ClickLabel2.Text = Microsoft.VisualBasic.Left(TextBox1.Text, 5)End Sub
    • Run Time
    • 3. The Trim FunctionThe format is:-Trim("Phrase")Example:Trim (" Visual Basic ") = Visual basicModify Previous Program code ..Private Sub Button1_ClickLabel2.Text = Trim(TextBox1.Text)End Sub
    • Run Time
    • 4. The Ltrim & Rtrim FunctionThe Ltrim FunctionThe format is:Ltrim("Phrase")Example:-Ltrim (" Visual Basic")= Visual basicThe Rtrim FunctionThe format is:Rtrim("Phrase")ExampleRtrim ("Visual Basic ") = Visual Basic
    • 5. The InStr functionThe format is:Instr (n, original phase, embedded phrase)Where n is the position where the Instr function willbegin to look for the embedded phrase.Private Sub Button1_ClickLabel2.Text = InStr(1, TextBox1.Text, "Egypt")End Sub
    • Run Time
    • Modify Button1 codeLabel2.Text = InStr(1, TextBox1.Text, "t")Modify Button1 codeLabel2.Text = InStr(5, TextBox1.Text, "t")And note the difference
    • 6. The Ucase and the Lcase FunctionsThe Ucase function converts all the characters of a stringto capital letters.The Lcase function converts all the characters of a stringto small letters.The format is:-Microsoft.VisualBasic.UCase(Phrase)Microsoft.VisualBasic.LCase(Phrase)
    • 7. The Abs FunctionReturn the absolute value of a given number.The syntax isMath. Abs (number)The Math keyword here indicates that the Absfunction belong to the Math class.
    • Run TimePrivate Sub Button1_ClickLabel2.Text = Math.Abs(Val(TextBox1.Text))End Sub
    • 8. The Exp functionThe Exp of a number x is the exponential valueof x………., i.e. e^xExp(1)=e=2.71828182The syntax is:Math.Exp (number)
    • 9. The Fix FunctionThe Fix function truncate the decimal part of apositive number and returns the largest integersmaller than the number.The syntax is:Fix(number)
    • Private Sub Button1_ClickLabel2.Text = Fix(Val(TextBox1.Text))End Sub
    • 10. The Int FunctionExample:-Int(2.4)=2, Int(6.9)=6 , Int(-5.7)=-6(XI) The Log FunctionExample:-Log(10)=2.302585
    • 11. The Rnd( ) FunctionThe Rnd function returns a random valuebetween 0 and 1.The traditional usage of this function is to covertits result to integer value …using the formula.Int(Rnd() * 10)Modify Previous Program code ..Private Sub Button1_Click()Label2.Text = Int(Rnd() * 10)End Sub
    • Run Time
    • 12. The Round FunctionThe Round function is the function that roundsup a number to a certain number of decimalplaces. The Format is Round (n, m) which meansto round a number n to m decimal places. ForExample:-Math.Round (7.2567, 2) =7.26
    • Run Time
    • Produced