Message and input boxes are intrinsic functions in Visual Basic 6.0 which allow the end
user to interact with the program.
Follow the instructions Add new form to menu at the end of session 1 to create a new form with a menu heading on the main form. Call this “Message and Input Boxes”
• Make the Form.Caption = “Message and Input Boxes”
• Put a label on the top of the form “Computer Conversation”. Underneath have a command button with the caption “Talk to me!” Name the command button cmdTalk.
• Double click the command button to add the following code sequence.
PrivateSub cmdTalk_Click()
Dim strQuestion As String
Dim intAnswer As Integer
‘Firstyoumustdeclareyourvariables’
‘Thenusetheinputandmessageboxfunctions’
strQuestion=InputBox(“Typeinyourname!”,“Ebeneezer”)
intAnswer=MsgBox(“Hellothere”&strQuestion,vbOKCancel,“Chat”)
EndSub
• Add a return button, called cmdBack as you did in the ColourChanger, using the code
PrivateSub cmdBack_Click()
Form1.Show
EndSub
Form1.Show
EndSub
Here are some handy literals (values that don’t change). You don’t have to learn them as the help prompt supplies a drop down list as you start to type.
Remarks are added in code to explain the purpose of a section of code or to add information for code maintenance. If Rem or ‘ is placed in front of the remark, that line of code is ignored completely.
No comments:
Post a Comment