Computer Science, asked by RaviRoyal9161, 1 day ago

Using variables and input box function. Write a program that accept a person's name and display it to list box.

Answers

Answered by shrutithakuryoyo
0

Answer:

 

Lesson 12 : MsgBox and InputBox

❮ Previous LessonNext Lesson ❯

A function in Visual Basic 2012 is similar to a normal procedure but the main purpose of the function is to accept a certain input and return a value which is passed on to the main program to finish the execution. There are two types of functions in Visual Basic 2012, the built-in functions (or internal functions) and the functions created by the programmers.

The syntax of a function is

FunctionName (arguments)

The arguments are values that are passed on to the function.In this lesson, we are going to learn two very basic but useful internal functions of Visual Basic 2012 , i.e. the MsgBox( ) and InputBox ( ) functions.

12.1 MsgBox ( ) Function

The objective of MsgBox is to produce a pop-up message box and prompt the user to click on a command button before he /she can continues. This format is as follows:

yourMsg=MsgBox(Prompt, Style Value, Title)

The first argument, Prompt, will display the message in the message box. The Style Value will determine what type of command buttons appear on the message box, please refer to Table 12.1 for types of command button displayed. The Title argument will display the title of the message board.

Table 12.1: Style ValuesStyle ValueNamed ConstantButtons Displayed0vbOkOnlyOk button1vbOkCancelOk and Cancel buttons2vbAbortRetryIgnoreAbort, Retry and Ignore buttons.3vbYesNoCancelYes, No and Cancel buttons4vbYesNoYes and No buttons5vbRetryCancelRetry and Cancel buttons

We can use named constants in place of integers for the second argument to make the programs more readable. In fact, Visual Basic 2012 will automatically shows up a list of named constants where you can select one of them.

For example:

yourMsg=MsgBox( "Click OK to Proceed", 1, "Startup Menu")

and

yourMsg=Msg("Click OK to Proceed". vbOkCancel,"Startup Menu")

are the same.

yourMsg is a variable that holds values that are returned by the MsgBox ( ) function. The values are determined by the type of buttons being clicked by the users. It has to be declared as Integer data type in the procedure or in the general declaration section. Table 12.2 shows the values, the corresponding named constant and buttons.

Similar questions