Function 2

396 views

Published on

Visual basic 2010 functions

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
396
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
19
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Function 2

  1. 1. Electroteam__@hotmail.comInteresting EducationElectro-TeamVisual Basic 2010Functions II
  2. 2. 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.
  3. 3. Open new project and add 2 Labels, 1 Textbox and 1 Button
  4. 4. 1. The Right FunctionThe format is:-Microsoft.Visualbasic.Right ("Phrase", n)ExampleMicrosoft.Visualbasic.Right (“Hello World", 5)=World
  5. 5. Label1Text = Right FunctionFont = 18 , BoldFormat Center in FormHorizontallyLabel2Text = …………Font = 16 , BoldButton1Text = GoFont = 14 , BoldForm1Text = Right Function Ex.Start Position = Center Screen
  6. 6. Button1 CodePrivate Sub Button1_ClickLabel2.Text = Microsoft.VisualBasic.Right(TextBox1.Text, 5)End Sub
  7. 7. 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
  8. 8. Run Time
  9. 9. 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
  10. 10. Run Time
  11. 11. 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
  12. 12. 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
  13. 13. Run Time
  14. 14. Modify Button1 codeLabel2.Text = InStr(1, TextBox1.Text, "t")Modify Button1 codeLabel2.Text = InStr(5, TextBox1.Text, "t")And note the difference
  15. 15. 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)
  16. 16. 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.
  17. 17. Run TimePrivate Sub Button1_ClickLabel2.Text = Math.Abs(Val(TextBox1.Text))End Sub
  18. 18. 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)
  19. 19. 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)
  20. 20. Private Sub Button1_ClickLabel2.Text = Fix(Val(TextBox1.Text))End Sub
  21. 21. 10. The Int FunctionExample:-Int(2.4)=2, Int(6.9)=6 , Int(-5.7)=-6(XI) The Log FunctionExample:-Log(10)=2.302585
  22. 22. 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
  23. 23. Run Time
  24. 24. 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
  25. 25. Run Time
  26. 26. Produced byElectro-TeamElectroteam__@hotmail.com

×