Visual Basic.NET Programming. Beginners Lesson 3. Output and Variables

Share

Summary

This tutorial covers output methods and the introduction of variables in Visual Basic.NET. It explains how to display messages using MessageBox and MessageBox.Show, discusses the concept of sequence in programming, and details how to declare, assign values to, and use string variables, emphasizing naming conventions and common pitfalls.

Highlights

Setting up a New Project and Displaying Output
00:00:06

The video begins by creating a new Visual Basic Windows Forms application. The form is set up with a button, which is renamed 'btnGo' using camel notation. The text property of the button is also changed. The code behind the button is accessed by double-clicking it, and the first output method, 'MessageBox', is introduced to display a message on the screen. The importance of not altering automatically generated code is highlighted.

Understanding Programming Sequence
00:02:12

The fundamental programming construct of 'sequence' is explained. Sequence means that statements in a program run one after another in the order they are written. This is demonstrated by displaying multiple messages sequentially, and then by changing the order of the commands to alter the display sequence.

Alternative Output Method: MessageBox.Show
00:03:54

An alternative, more modern way to display messages, 'MessageBox.Show', is introduced. The video notes that while 'MsgBox' is an older style, 'MessageBox.Show' represents an object-oriented approach and either can be used for now.

Introducing Variables: Declaration and Assignment
00:04:53

The concept of variables is introduced by adding a second button, 'btnVariables', to the form. A variable is defined as a temporary storage location in the computer's memory. The 'Dim' statement is used to declare a variable, specifying its name (e.g., 'stFirstName' using camel notation and a type prefix) and data type (e.g., 'As String'). The process of assigning a value to the variable is then demonstrated.

Outputting Variable Contents and String Concatenation
00:09:00

The video shows how to output the contents of a variable using 'MessageBox', emphasizing that no double quotes are used around the variable name. To create more friendly messages, string concatenation using the ampersand '&' operator is demonstrated, combining literal text with variable contents. The importance of adding spaces within literal strings for readability is also shown.

Declaring Multiple Variables and Common Mistakes
00:10:50

Another string variable, 'stLastName', is declared and assigned a value, which is then concatenated with the first name and other text. Common syntax errors related to missing ampersands and double quotes in concatenation are illustrated, highlighting the importance of matching pairs for these operators. A method to insert a space between two concatenated variables is also explained.

Variable Scope and Mutability
00:12:37

The video clarifies that variable declarations ('Dim' statements) can be placed anywhere before the variable is used, though it's good practice to place them at the top of a procedure. The temporary nature of variables is reiterated, explaining that memory is released when the program ends. Finally, the concept of a variable's contents changing during program execution is demonstrated by re-assigning new values to the existing variables and outputting them again, thus explaining why they are called 'variables'.

Recently Summarized Articles

Loading...