The InputBox function and the MsgBox function are two very important functions in VB. The InputBox function is to accept data from the user and the MsgBox function is to output data to the user. They are considered a form of simple dialog box for the user to interact with the VB program.
The Inputbox function with return a value of any data type, which means the value could be integer,single, string, boolean ,data and more. Normally you need to declare the data type for values to be accepted in the Inputbox.
Example:
Dim StudentName As String
Dim Mark As Integer
StudentName=InputBox("Enter Student Name")
Mark=InputBox("Enter Student Mark")
The first InputBox will return a string and the second InputBox will return an Integer. You can write error handling code to deal with wrong entry of data type using On Error Goto Error_Handler statement. For Example, if the user enters student Mark instead of student name into the first InputBox, you can write the error handling code as follow, which include the usage of the MsgBox function:
StudentName=InputBox("Enter Student Name")
On Error Goto Error_Handler
Error_Handler:
MsgBox "You have entered wrong data, please enter the student name again"
For more info on InputBox and MsgBox, please refer to Vbutor.net lesson 10:
http://www.vbtutor.net/lesson10.html
1 comment:
...please where can I buy a unicorn?
Post a Comment