|
||||
|
IntroductionWelcome! Forms, Timers & Text Boxes BasicsIn this lesson, we will introduce Visual Basic 104 and discuss what you will learn in this course, including working with multiple forms, sharing values between them, handling form events like load, unload, show, and hide, and adjusting project properties such as the startup form. We will talk about the timer control, calculating ages based on birth dates, and cover some key functions like Round, Date, Now, and IsDate. You will also see how to use multi-line text boxes, graphical command buttons, checkboxes, and toggle buttons, as well as where to find course resources and participate in the student forum. NavigationKeywords, Visual Basic multiple forms, share values between forms, load event, unload event, show event, hide event, project properties, startup form, timer control, calculate age birth date, Round function, Date function, Now function, IsDate, multi-line text bo
More InformationTranscriptWelcome to Visual Basic 104, brought to you by VBLearningZone.com. I am your instructor, Richard Rost. In today's class, we will be working with multiple forms. We will learn how to share values between two forms. We will learn about the load, unload, show, and hide events. We will take a look at the project properties and how to change the startup form. We will work with the timer control. I will show you how to calculate people's ages knowing their birth dates. We will learn some new functions, including Round, Date, Now, IsDate, IsNewAmerican, and a bunch more. We will work with multi-line text boxes and all their different properties. I will show you graphical command buttons, checkboxes, and toggle buttons. The prerequisite for this class is VB103. I strongly recommend you take 101 through 103 before taking this course. In today's class, I will be using Microsoft Visual Basic 6.0. If you are using a different version of VB, such as VB.NET or VB2005, you will find that the interface is different. However, most of the Visual Basic programming code is the same. I strongly recommend you sit back, relax, and watch each video once through without doing anything. Then replay the video again and follow along with the examples, building each project as I do. Do not try to apply what you are learning immediately to any other projects you might be working on. Instead, build the sample project in class with me. There is a web page for this class located at vblearningzone.com?GOVB104. On this page, you will find sample project files, the course outline, and the student discussion forum. If you have any questions about the material covered in today's class, post them here on the discussion forum. If you are watching this class in the Amocrine Video Player or the Online Theater, you will see this page load up just to the right of the videos. Join in the discussion by posting your thoughts here. IntroIn this lesson, we will introduce Visual Basic 104 and discuss what you will learn in this course, including working with multiple forms, sharing values between them, handling form events like load, unload, show, and hide, and adjusting project properties such as the startup form. We will talk about the timer control, calculating ages based on birth dates, and cover some key functions like Round, Date, Now, and IsDate. You will also see how to use multi-line text boxes, graphical command buttons, checkboxes, and toggle buttons, as well as where to find course resources and participate in the student forum. QuizQ1. What is one of the primary focuses of this Visual Basic class? A. Working with multiple forms and sharing values between them B. Writing advanced database queries C. Designing web pages with HTML D. Learning Python programming Q2. Which events will you learn about in this course? A. Load, Unload, Show, and Hide events B. Click and DoubleClick events only C. Initialize and Terminate events only D. KeyPress and MouseMove events only Q3. What prerequisite is strongly recommended for this class? A. VB103 B. CS101 C. VB104 D. Java101 Q4. Which control will be demonstrated for working with time-based actions? A. Timer control B. Combo box C. List box D. Tree view control Q5. What will you learn to calculate using birth dates in this class? A. A person's age B. A person's height C. The day of the week D. The average score Q6. Which of the following is a new function mentioned that you will be learning? A. Round B. Min C. Abs D. Sum Q7. What should you do before applying what you learn to your own projects? A. Build the sample project along with the instructor B. Immediately apply to your own project C. Skip the exercises D. Only read the documentation Q8. Which types of text boxes will be covered in this course? A. Multi-line text boxes B. Single-line text boxes only C. Password text boxes only D. Drop-down text boxes Q9. What should you do before following along with the examples in the video? A. Watch the video once through without doing anything B. Start building your own project immediately C. Skip straight to the final test D. Read the textbook only Q10. If you have questions about the material, where should you post them? A. On the student discussion forum B. By email directly to the instructor only C. On a social media page not mentioned in the course D. In a private journal Answers: 1-A; 2-A; 3-A; 4-A; 5-A; 6-A; 7-A; 8-A; 9-A; 10-A DISCLAIMER: Quiz questions are AI generated. If you find any that are wrong, don't make sense, or aren't related to the video topic at hand, then please post a comment and let me know. Thanks. SummaryToday's video from the Visual Basic Learning Zone is Visual Basic 104. I am your instructor, Richard Rost, and in this class, we are going to cover how to work with multiple forms in Visual Basic. I will show you the proper methods for sharing values between two forms, and we will take a close look at the different events such as load, unload, show, and hide that are associated with forms. We will also review project properties, including how to change the startup form in your project. In this course, you will get hands-on experience working with the timer control so you can add timed events to your programs. Additionally, I will explain how to calculate a person's age when you know their birth date. Along the way, we will explore some new functions including Round, Date, Now, IsDate, IsNewAmerican, and several more. You will also learn about the properties of multi-line text boxes and how to work with them in your forms. I will introduce you to graphical command buttons, along with checkboxes and toggle buttons, so you can make your user interface more interactive. Before you start this class, you should have completed VB103. I highly recommend working through VB101, 102, and 103 first, since the material builds on those previous lessons. For this series, I am using Microsoft Visual Basic 6.0. If you are using a different version such as VB.NET or VB2005, you will notice that the interface has changed, but the majority of the programming concepts and code remain the same. My recommendation is that you watch each video all the way through the first time without trying to follow along in the software. On your second viewing, go back and work step-by-step with me, building each of the sample projects. Avoid trying to use the new techniques on any of your current projects until you have created the sample project along with me, as this will help reinforce your learning. There is a dedicated web page for this class at vblearningzone.com?GOVB104. On this page, you will find the sample project files, the course outline, and access to the student discussion forum. If you have questions about anything that is covered in the material, use the forum to post your questions and discuss topics with other students. If you are viewing this course in the Amocrine Video Player or the Online Theater, you will see the class page appear next to the videos for easy reference. I encourage you to contribute to the discussion by sharing your thoughts and questions. You can find a complete video tutorial with step-by-step instructions on everything discussed here on my website at the link below. Live long and prosper, my friends. Topic ListWorking with multiple forms Sharing values between two forms Form load, unload, show, and hide events Changing the project startup form Using the timer control Calculating age from birth date Using functions: Round, Date, Now, IsDate Working with multi-line text boxes Setting properties for multi-line text boxes Using graphical command buttons Using checkboxes Using toggle buttons Adjusting project properties ArticleIn this tutorial, you will learn how to work with multiple forms in Visual Basic. Handling multiple forms is an essential skill for creating more advanced applications, allowing you to build user interfaces with different windows or dialogs. I will guide you through sharing values between forms, using events like Load, Unload, Show, and Hide, adjusting project properties such as the startup form, and working with timers and functions to add useful features to your projects. We will also look closely at multi-line text boxes, graphical command buttons, checkboxes, and toggle buttons to enhance your application's interface. Let us start by understanding how to display and interact with more than one form. Imagine you have two forms: Form1 and Form2. You may want to use one as the main window and the other to display additional information or prompt the user for input. You can display another form using the Show method, like this: Form2.Show If you want to hide a form without closing it, use the Hide method: Form2.Hide The Hide method keeps the form in memory, so you can later show it again with its data preserved. If you need to completely close a form, use the Unload statement: Unload Form2 To respond when a form is loaded or unloaded, you can use the Form_Load and Form_Unload events. For example: Private Sub Form_Load() MsgBox "Welcome to the form!" End Sub Private Sub Form_Unload(Cancel As Integer) MsgBox "Goodbye!" End Sub Sometimes you need to pass values between forms. For example, you might need to get user input from Form2 and use it in Form1. One straightforward way is to create public variables in a module: ' In a module: Public UserName As String Then, in Form2, after the user has entered a value, set the variable: UserName = txtName.Text Now, back in Form1, you can use the value of UserName to greet the user or for any other purpose. You can also refer directly to controls on another form, but this technique is only practical if the form is currently loaded. For example: Form1.Label1.Caption = Form2.txtName.Text For more organized code, consider creating properties or functions in your forms to expose needed values. Understanding project properties is also important. You can choose which form appears first when your program starts by changing the startup form in the project properties dialog. This allows you to control the user experience from the very beginning. Adding timers can create dynamic applications. The Timer control lets you execute code at regular intervals. For example, you may want to update the current time every second on your form: Private Sub Timer1_Timer() lblTime.Caption = Now End Sub To enable the timer, set its Enabled property to True and its Interval property to the desired number of milliseconds (1000 for one second). Calculating a person's age using their birth date is a common task. You can use the DateDiff function along with the current date like this: Dim Age As Integer Age = DateDiff("yyyy", txtBirthDate.Text, Date) If Date < DateSerial(Year(Date), Month(txtBirthDate.Text), Day(txtBirthDate.Text)) Then Age = Age - 1 End If lblAge.Caption = Age Here, we calculate the difference in years between the provided birth date and today, then adjust if their birthday has not occurred yet this year. Several useful functions are available in Visual Basic. Round is used to round a number to a specified number of decimal places: Dim roundedValue As Double roundedValue = Round(3.14159, 2) ' roundedValue is 3.14 The Date and Now functions return the current date and the current date and time, respectively. Use IsDate to check if a value can be interpreted as a date: If IsDate(txtInput.Text) Then MsgBox "Valid date!" Else MsgBox "Please enter a valid date." End If There is no built-in function called IsNewAmerican; this may have been a typo or a custom function in the original context. For now, focus on built-in functions like those mentioned above. Multi-line text boxes allow users to enter more than one line of text. To enable this, set the MultiLine property of the TextBox control to True. You can adjust properties such as ScrollBars to make editing easier: txtComments.MultiLine = True txtComments.ScrollBars = 2 ' Vertical scroll bars Graphical command buttons, checkboxes, and toggle buttons help you create richer user interfaces. A command button with a graphical style can display pictures instead of just text, enhancing visual appeal. Checkboxes allow users to select yes or no options. Toggle buttons give feedback by staying pressed when active. To set up a graphical button, you can set the Style property of a CommandButton to Graphical and assign a Picture to it. For a checkbox, use the CheckBox control and read its Value property to see if it is checked: If chkOption.Value = 1 Then MsgBox "Option selected." End If Toggle buttons behave similarly, giving you a way to provide on/off choices in your forms. By practicing these techniques, you will expand your Visual Basic programming skills. As you follow along, build sample projects for each topic. Work step by step and ensure you understand how each control and technique works before introducing them into your own applications. If you have questions about these topics, consider joining a discussion forum where you can share your experience and get answers. With hands-on practice, you will quickly become comfortable with multiple forms and the controls and functions that help make your applications more interactive and user-friendly. Primary Topicsmultiple forms, value sharing between forms, form events (load, unload, show, hide), timer control, project properties, startup form, age calculation, textbox properties Secondary Topicsgraphical command buttons, checkboxes, toggle buttons |
||
|
| |||
| Keywords: , Visual Basic multiple forms, share values between forms, load event, unload event, show event, hide event, project properties, startup form, timer control, calculate age birth date, Round function, Date function, Now function, IsDate, multi-line text bo PermaLink How To Work With Multiple Forms, Timers, and Text Boxes in Microsoft Visual Basic |