Electroteam__@hotmail.comElectro-TeamInteresting EducationVisual Basic 2010Functions A
Functions• Accept input and return a value. There are two typesof functions, the built-in functions (or internalfunctions)...
Built-in Functions (I)
MsgBox ( ) FunctionProduce a pop-up message box and prompt theuser to click on a command button.Format:MsgBox(Prompt, Styl...
Styles ValueStyle Value Named Constant Buttons Displayed0 vbOkOnly Ok button1 vbOkCancel Ok and Cancel buttons2 vbAbortRet...
ExampleMsgBox("Hello World", 1, "HW-Program")MsgBox("Hello World", vbOKCancel, "HW-Program")
Return ValuesValue Named Constant Button Clicked1 vbOk Ok button2 vbCancel Cancel button3 vbAbort Abort button4 vbRetry Re...
Ex: Return ValueDim x As Integerx = MsgBox("abcdefg", 1, "Eng")If x = 1 ThenMessageBox.Show("OK button")ElseMessageBox.Sho...
Message Box With IconValue Constant Icon16 vbCritical32 vbQuestion48 vbExclamation64 vbInformation
Ex: Message Box With IconDim x As Integerx = MsgBox("abcdef", vbYesNoCancel + vbExclamation, "Eng")If x = 6 ThenMessageBox...
The InputBox( ) Functiondisplay a message with TextBox where the user can entera value or a message in the form of text.Fo...
Ex: InputBoxDim txt As Stringtxt = Microsoft.VisualBasic.InputBox("What is your name?", "Names")If txt <> "" ThenMessageBo...
The Mid Function• Retrieve a part of text form a given phrase.• Format:– Mid(phrase, position, n)• Phrase is the string fr...
ExampleDim txt As Stringtxt = Microsoft.VisualBasic.InputBox("Enter your phrase")MsgBox(Mid(txt, 2, 6))
The Chr and the Asc functions• The Chr function returns the string that correspondsto an ASCII code while the Asc function...
End Of Part OneProduced byElectro-Teamelectroteam__@hotmail.com
Upcoming SlideShare
Loading in...5
×

Functions 1

107

Published on

Published in: Technology, Art & Photos
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
107
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Functions 1

  1. 1. Electroteam__@hotmail.comElectro-TeamInteresting EducationVisual Basic 2010Functions A
  2. 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. 3. Built-in Functions (I)
  4. 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. 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. 6. ExampleMsgBox("Hello World", 1, "HW-Program")MsgBox("Hello World", vbOKCancel, "HW-Program")
  7. 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. 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. 9. Message Box With IconValue Constant Icon16 vbCritical32 vbQuestion48 vbExclamation64 vbInformation
  10. 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. 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. 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. 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. 14. ExampleDim txt As Stringtxt = Microsoft.VisualBasic.InputBox("Enter your phrase")MsgBox(Mid(txt, 2, 6))
  15. 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. 16. End Of Part OneProduced byElectro-Teamelectroteam__@hotmail.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×