• Like
Functions 1
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Published

 

Published in Technology , Art & Photos
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
75
On SlideShare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
7
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Electroteam__@hotmail.comElectro-TeamInteresting EducationVisual Basic 2010Functions A
  • 2. Functions• Accept input and return a value. There are two typesof functions, the built-in functions (or internalfunctions) and the functions created by theprogrammers.• The general format of a function is:-FunctionName (arguments)– The arguments are values that are passed on to thefunction.
  • 3. Built-in Functions (I)
  • 4. MsgBox ( ) FunctionProduce a pop-up message box and prompt theuser to click on a command button.Format:MsgBox(Prompt, Style Value, Title)Prompt: the message itself.Style Value: determine what type of command buttonsappear.
  • 5. Styles ValueStyle Value Named Constant Buttons Displayed0 vbOkOnly Ok button1 vbOkCancel Ok and Cancel buttons2 vbAbortRetryIgnore Abort, Retry and Ignore buttons.3 vbYesNoCancel Yes, No and Cancel buttons4 vbYesNo Yes and No buttons5 vbRetryCancel Retry and Cancel buttons
  • 6. ExampleMsgBox("Hello World", 1, "HW-Program")MsgBox("Hello World", vbOKCancel, "HW-Program")
  • 7. Return ValuesValue Named Constant Button Clicked1 vbOk Ok button2 vbCancel Cancel button3 vbAbort Abort button4 vbRetry Retry button5 vbIgnore Ignore button6 vbYes Yes button7 vbNo No button
  • 8. Ex: Return ValueDim x As Integerx = MsgBox("abcdefg", 1, "Eng")If x = 1 ThenMessageBox.Show("OK button")ElseMessageBox.Show("Cancel button")End If
  • 9. Message Box With IconValue Constant Icon16 vbCritical32 vbQuestion48 vbExclamation64 vbInformation
  • 10. Ex: Message Box With IconDim x As Integerx = MsgBox("abcdef", vbYesNoCancel + vbExclamation, "Eng")If x = 6 ThenMessageBox.Show("Yes button")ElseIf x = 7 ThenMessageBox.Show("NO button")ElseMessageBox.Show("Cancel button")End If
  • 11. The InputBox( ) Functiondisplay a message with TextBox where the user can entera value or a message in the form of text.Format:Microsoft.VisualBasic.InputBox(Prompt, Title, default_text, x-position, y-position)Microsoft.VisualBasic.InputBox(Prompt, Title)
  • 12. Ex: InputBoxDim txt As Stringtxt = Microsoft.VisualBasic.InputBox("What is your name?", "Names")If txt <> "" ThenMessageBox.Show(txt)ElseMessageBox.Show("No Message")End If
  • 13. The Mid Function• Retrieve a part of text form a given phrase.• Format:– Mid(phrase, position, n)• Phrase is the string from which a part of text is to beretrieved.• Position is the starting position of the phrase fromwhich the retrieving process begins.• n Is the number of characters to retrieve.
  • 14. ExampleDim txt As Stringtxt = Microsoft.VisualBasic.InputBox("Enter your phrase")MsgBox(Mid(txt, 2, 6))
  • 15. The Chr and the Asc functions• The Chr function returns the string that correspondsto an ASCII code while the Asc function converts ancharacter or symbol to the corresponding ASCII code.• Format:– Chr(ASCII code)• Chr(65)=A– Asc(Character)• Asc("B")=66
  • 16. End Of Part OneProduced byElectro-Teamelectroteam__@hotmail.com