Ministry of Higher Education And Scientific Research Babylon University College of Material Engineering Subject: Programming in Visual Basic Polymers Engineering Department 2015-2016 Language Class: Second Year Lecturer: Hussein Mohammed Salman Lecture-8: Input Tools and Methods In each language , there are many tools and methods used to read and input the data (values of the variables) such as read and input statement, in the Visual Basic there are main two methods for the input tools: First : by using the Text Box tool ; This tool basically used for dealing with the text data, however there is way to make it deal with the numeric data by using the val() function that convert the digits read by text box from the text format to the numeric format. This is very clear in the last lectures. Second : The InputBox ( ) Function An InputBox ( ) function will display a message box where the user can enter a value or a message in the form of text. The general format of the InputBox() is: InputBox (Prompt, [Title] , [default] , [x-position], [ y-position],[helpfile context]) The arguments are explained as follows , where each argument in the square bracket is an optional test : • Prompt : The message displayed in the input box. • Title : The title of the input box window. • Default : The default value that appears in the input field where users can use it as his intended input or he may change to another message. • X-position and y-position : the position or the coordinate of the input box. As in the following figure This Lecture allowed on: www.uobabylon.iq.edu 1 Ministry of Higher Education And Scientific Research Babylon University College of Material Engineering Subject: Programming in Visual Basic Polymers Engineering Department 2015-2016 Language Class: Second Year Lecturer: Hussein Mohammed Salman For example , suppose we read the variable x as the following statement: X=inputbox("read the number x",,30) In this example , notice that the second argument not found ,this means that we not focus on this argument because it is optional , where any optional argument may be used or not . Example: Design a project to read three numbers and add them by using the inputbox function. In this project will not need more tools also for all project used this function , as follow: 1st Stage: Form Design This Lecture allowed on: www.uobabylon.iq.edu 2 Ministry of Higher Education And Scientific Research Babylon University College of Material Engineering Subject: Programming in Visual Basic Polymers Engineering Department 2015-2016 Language Class: Second Year Lecturer: Hussein Mohammed Salman 2nd Stage: Set Properties Object (Tool) Command1 Text1 Property Setting Name Caption Font Font Size Name Text cmdAdd Add Times New Roman 14 txtAdd 3rd Stage: Code Write cmdAdd (Add) dim a as integer, b as integer, c as integer, sum as integer a=inputbox("read first number") b=inputbox("read second number",,12) c=inputbox("read third number","Third Number",10) sum=a+b+c txtAdd.text=sum When the project executed , the input box window of the –a- variable is as below , note it not include any default value and the title is set by the VB manipulator . While the input box window of the –b- variable is as below , note it includes a default value and but the title is set by the VB manipulator . This Lecture allowed on: www.uobabylon.iq.edu 3 Ministry of Higher Education And Scientific Research Babylon University College of Material Engineering Subject: Programming in Visual Basic Polymers Engineering Department 2015-2016 Language Class: Second Year Lecturer: Hussein Mohammed Salman While the input box window of the –c- variable is as below , note it includes a default value and a title is Third Number which set by the designer of the project. This Lecture allowed on: www.uobabylon.iq.edu 4