Writing Visual Basic statements

A statement in Visual Basic is a complete instruction. Each statement belongs to one of the following three categories:

  • declaration statements : which name (declare) a variables , constant , or procedure and can also specify a data type.
  • assignment statements: which assign a value or expression to a variable, constant or property .
  • executable statements: which initiate actions. These statements can execute a method or function , and they can loop or branch through blocks of code. Executable statements often contain mathematical or conditional operators.

Writing declaration statements

You use declaration statements to name and define procedures, variables, arrays, and constants. When you declare a procedure, variable, or constant, you also define its scope, depending on where you place the declaration and what keywords you use to declare it.

The following example contains three declarations.

The Sub statement (with matching End Sub statement) declares a procedure named ApplyFormat. All the statements enclosed by the Sub and End Sub statements are executed whenever the ApplyFormat procedure is called or run.

The Const statement declares the constant limit specifying the Integer data type and a value of 33.

The Dim statement declares the myCell variable. The data type is an object, in this case, a Microsoft Excel Range object. You can declare a variable to be any object that is exposed in the application that you are using. Dim statements are one type of statement used to declare variables. Other keywords used in declarations are ReDim, Static, Public, Private, and Const.

Writing assignment statements

Assignment statements assign a value or expression to a variable or constant. Assignment statements always include an equal sign (=).

The following example assigns the return value of the InputBox function to the variable.

The Set statement is used to assign an object to a variable that has been declared as an object. The Set keyword is required. In the following example, the Set statement assigns a range on Sheet1 to the object variable myCell.

Statements that set property values are also assignment statements. The following example sets the Bold property of the Font object for the active cell.

Writing executable statements

An executable statement initiates action. It can execute a method or function, and it can loop or branch through blocks of code. Executable statements often contain mathematical or conditional operators .

The following example uses a For Each...Next control statement to iterate through each cell in a range named MyRange on Sheet1 of an active Microsoft Excel workbook. The variable cell is a cell in the collection of cells contained in MyRange.

The If...Then...Else control statement in the example checks the value of the cell. If the value is greater than 33, the With statement sets the Bold and Italic properties of the Font object for that cell. If...Then...Else statements end with End If . The With statement improves the code by showing on what single specified object all the following actions apply (readability) and also makes the execution of code faster. The Next statement calls the next cell in the collection of cells contained in MyRange.

Programming Visual Basic .NET by

Get full access to Programming Visual Basic .NET and 60K+ other titles, with a free 10-day trial of O'Reilly.

There are also live events, courses curated by job role, and more.

In Visual Basic .NET, assignment statements are of the form:

Either the type of the expression must be the same as that of the item receiving the assignment, or there must exist an appropriate implicit or explicit conversion from the type of the expression to the type of the item receiving the assignment. For information on implicit and explicit conversions, see Section 2.5.5 earlier in this chapter.

When an assignment is made to a value type, the value of the expression is copied to the target. In contrast, when an assignment is made to a reference type, a reference to the value is stored in the target. This is an important distinction that is worth understanding well. Consider the code in Example 2-3 .

Example 2-3. Value-type assignment versus reference-type assignment

Get Programming Visual Basic .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.

Don’t leave empty-handed

Get Mark Richards’s Software Architecture Patterns ebook to better understand how to design components—and how they should interact.

It’s yours, free.

Cover of Software Architecture Patterns

Check it out now on O’Reilly

Dive in for free with a 10-day trial of the O’Reilly learning platform—then explore all the other resources our members count on to build skills and solve problems every day.

what is visual basic assignment

  • Search Search Please fill out this field.
  • What Is VBA?

Understanding VBA

Vba in excel, what can you do with vba, important vba terms, the bottom line.

  • Other Technologies

Visual Basic for Applications (VBA): Definition, Uses, Examples

what is visual basic assignment

Erika Rasure is globally-recognized as a leading consumer economics subject matter expert, researcher, and educator. She is a financial therapist and transformational coach, with a special interest in helping women learn how to invest.

what is visual basic assignment

Investopedia / Theresa Chiechi

What Is Visual Basic for Applications (VBA)?

Visual Basic for Applications (VBA) is part of Microsoft Corporation's (MSFT) legacy software Visual Basic. VBA is used to write programs for the Windows operating system and runs as an internal programming language in Microsoft Office (MS Office, Office) applications such as Access, Excel , PowerPoint, Publisher, Word, and Visio. VBA allows users to customize beyond what is normally available with MS Office host applications.

Key Takeaways

  • Visual Basic for Applications is a computer programming language developed and owned by Microsoft.
  • With VBA you can create macros to automate repetitive word- and data-processing functions, and generate custom forms, graphs, and reports.
  • VBA functions within MS Office applications; it is not a stand-alone product.
  • VBA is accessed in Excel by hitting Alt + F11 while having an Excel workbook present.
  • VBA leverages objects, variables, properties, projects, logical operators, and modules to make statements recognizable by debugging processes.

VBA is an event-driven tool, which means that you can use it to tell the computer to initiate an action or string of actions. To do this, you build custom macros—short for macroinstructions—by typing commands into an editing module.

A macro is essentially a sequence of characters whose input results in another sequence of characters (its output) that accomplishes specific computing tasks. You do not need to purchase the VBA software because VBA is the version of Visual Basic that ships with Microsoft Office.

VBA is not a stand-alone program. Instead, it allows users to manipulate graphical user interface (GUI) features such as toolbars and menus, dialogue boxes, and forms. You may use VBA to create user-defined functions (UDFs), access Windows application programming interfaces (APIs) , and automate specific computer processes and calculations.

Microsoft hosts various learning opportunities for entry-level developers to gain modest experience working with VBA.

All Office suite programs share common programming languages, and each have the capability of integrating VBA code to enhance the program. Due to the repetitive nature of spreadsheets, data analytics , and organizing data, VBA has been a natural fit with Excel more so than other Office suite programs.

The root of the relationship between VBA and Excel is often tied to the use of macros. To run a macro in Excel, you use VBA, though you can use VBA for non-macro activities as well.

How to Access VBA in Excel

To access VBA in Excel, simply press Alt + F11. Your existing Excel workbook will remain running, but a new window will appear for Microsoft Visual Basic for Applications. The top left of the VBA window will show the current projects; in the example below, the InvestopediaProject file is ready to receive VBA code.

In the bottom left, the window displays the properties of the selected project. As different projects or workbooks are selected, different properties are listed. These properties are listed alphabetically by default, though they can be sorted by category.

By double-clicking on a project on the top left, a new window appears. There is no information in this area, though there are two dropdowns that say "(General)" and "(Declarations)." This is the coding window for VBA code to be directly entered into.

An example of VBA code has been entered below.

Last, there are many important buttons and tools residing on the toolbar. The items below highlighted in yellow are the run, break, and reset toggles for the VBA code. The run button executes the code, the break button pauses the activity of the code, and the reset stops the execution of the code and brings the process back to the starting position of the code.

At its core, finance is about manipulating huge amounts of data; hence, VBA is endemic to the financial services sector . If you work in finance, VBA is likely running within applications that you use each day, whether you're aware of it or not. Some jobs in the sector require prior knowledge of VBA, and some do not. With VBA, you can:

  • Write macros. Macros allow financial professionals—whether accountants, commercial bankers, investment bankers , research analysts, salesmen, traders, portfolio managers, clerks, or administrators—to analyze and adjust huge amounts of data quickly.
  • Update data. You can use VBA in Excel to create and maintain complex trading, pricing, and risk-management models, forecast sales and earnings, and to generate financial ratios .
  • Perform scenario-analysis. With Visual Basic for Applications, you can create various portfolio-management and investment scenarios . This includes filtering through different situations that may impact outcomes differently.
  • Organize information. You also may use VBA to produce lists of customers’ names or any other content; create invoices, forms, and charts; analyze scientific data, and manage data display for budgets and forecasting.
  • Be unconventional. VBA can be used to copy and paste values, adjust cell styles for an entire workbook, and strike accelerator keys. You can perform very normal tasks but perform them in an easier, automated manner.
  • Prompt action. VBA can be used to interact with users. For example, you may need a user's input for their first and last name to put on a form. VBA can be used to prompt a user in a way that makes this input unavoidably mandatory.

There are many forums online that provide VBA code, allowing you to simply copy and paste the code for your personal use. Be cautious when using someone else's code, especially if you are unfamiliar with the source, individual, or logic of the code.

A module is where Excel stores the VBA code. Information regarding the modules within a spreadsheet can be found in the Project Explorer, one of the sections of the Visual Basic Editor. All modules may be saved within a modules folder, and modules are sometimes referred to as standard modules.

In VBA, most code is used to manipulate objects. Objects are items such as workbooks, worksheets, cells, cell ranges, or cell fonts. When coding in VBA, objects are often selected or referred to as part of the code. For example, VBA code may use the "ActiveCell" language to manipulate the object currently selected in the spreadsheet. In addition, you may create a process that executes when a bar chart is edited.

The procedure is the part of a computer program that performs a specific task. It's the block of code that starts with a declaration and finishes with an end declaration. There are two types of procedures in VBA: sub procedures form an action in Excel and begin with the text "Sub", and function procedures that carry out calculations and return a value.

A statement is an instruction that can be broken into two different types. First, a declaration statement is used to state something such as defining a constant or variable value. Second, executable statements designate code that specify that a certain action is

Variables are storage locations for defined items. They're used to hold specific values that may change as VBA scripts are performed. For example, the variable "FirstName" may not contain any value. However, after the user inputs their name, the variable may be assigned the FirstName variable and may be given the value "John". Similar to how variable costs may change over time, variables in coding may be different in different situations.

Logical Operators

Logical operators are the functions that allow for greater analytical and processing capabilities. They are bits of code that allow a computer to understand and compare items. For instance, VBA can analyze whether the user above's name is "Mary". Using the logical operators 'if, then', 'true', and 'false', the program can analyze the input and perform a logical evaluation.

Visual Basic for Applications is the only version of VB 6 that is still sold and supported by Microsoft, and only as an internal component of Office programs.

Basic Users

Within MS Office applications, Visual Basic for Applications allows users to perform myriad functions that go beyond simple word processing and spreadsheet operations . For the most basic user, VBA helps to make frequent everyday tasks less repetitive via macros.

Macros can automate just about any task—like generating customized charts and reports, and performing word- and data-processing functions. For example, you can write a macro that, with a single click, will make Excel create an entire balance sheet from a series of accounting entries in a spreadsheet.

Advanced Users

Programmers, however, use macros in more complex ways—like replicating large pieces of code, merging existing program functions, and designing specific languages. Advanced VBA code can convert a single row vector into a matrix, populate a range, or manipulate the characteristics of a sheet.

Companies and Organizations

VBA can also work in external—that is, non-Microsoft—settings by using a technology called COM interface , which allows commands to interact across computer boundaries. Many firms have implemented VBA within their own applications, both proprietary and commercial, including AutoCAD, ArcGIS, CATIA, Corel, raw, and SolidWorks.

Any firm may use VBA to customize Excel for a unique purpose, such as discerning how long it would take to earn $1 million in an investment portfolio based on a specific interest rate and other factors, like the number of years until retirement.

What Is VBA Used for?

VBA is used to further expand what some programs are able to accomplish. VBA is often used to create macros, automate processes, generate custom forms, or perform repetitive tasks that may need minimal human intervention.

Is VBA the Same As Excel?

VBA is a computer language that is used within Excel. While Excel is a broader software used for many different types of analytical functions, VBA enhances its capabilities.

Is VBA Easy to Learn?

Compared to other complex languages, VBA is relatively easier to learn. It is considered a beginner-friendly language, and VBA-coders often do not need to have prior experience as a coder to learn the language. In addition, the VBA community has many resources available for individuals new to programming.

Is VBA Still In Demand?

Yes, VBA is still useful and used by individuals interacting with Microsoft products. However, newer languages such as Python, C#, or R can be used to code in place of VBA. In addition, new tools such as Power Query may be able to perform tasks that could previously only be performed when using VBA.

First introduced in 1991, VBA has been used for decades to automate processes, generate macros, or help individuals by performing repetitive tasks. Though other, more powerful computer languages may have greater capabilities, VBA is still useful today and holds the advantage of being an easier, more basic language to learn.

Microsoft Corporation. " Apps and Services ."

Microsoft Learn. " Getting Started with VBA in Office ."

Microsoft Learn. " Visual Basic Conceptual Topics ."

Microsoft Learn, Office Add-ins. " Develop Solutions and Customize Excel ."

Microsoft Learn. " Excel Performance: Improving Calculation Performance ."

Microsoft Learn. " Support Statement for Visual Basic 6.0 on Windows ."

Microsoft Learn, Windows App Development. " COM Objects and Interfaces ."

Retool. " Something Pretty Right: The History and Legacy of Visual Basic ."

what is visual basic assignment

  • Terms of Service
  • Editorial Policy
  • Privacy Policy
  • Your Privacy Choices
  • PyQt5 ebook
  • Tkinter ebook
  • SQLite Python
  • wxPython ebook
  • Windows API ebook
  • Java Swing ebook
  • Java games ebook
  • MySQL Java ebook

Visual Basic operators

last modified October 18, 2023

In this part of the Visual Basic tutorial, we talk about operators.

An operator is a special symbol which indicates a certain process is carried out. Operators in programming languages are taken from mathematics. Programmers work with data. The operators are used to process data.

We have several types of operators:

Arithmetic operators

Boolean operators.

  • Relational operators

Bitwise operators

An operator may have one or two operands. An operand is one of the inputs (arguments) of an operator. Those operators that work with only one operand are called unary operators . Those who work with two operands are called binary operators .

The + and - signs can be addition and subtraction operators as well as unary sign operators. It depends on the situation.

The plus sign can be used to indicate that we have a positive number. But it is mostly not used. The minus sign changes the sign of a value.

Multiplication and addition operators are examples of binary operators. They are used with two operands.

The assignment operator

The assignment operator = assigns a value to a variable. A variable is a placeholder for a value. In mathematics, the = operator has a different meaning. In an equation, the = operator is an equality operator. The left side of the equation is equal to the right one.

Here we assign a number to the x variable.

The previous expression does not make sense in mathematics. But it is legal in programming. The expression adds 1 to the x variable. The right side is equal to 2 and 2 is assigned to x .

This code example results in syntax error. We cannot assign a value to a literal.

The following is a table of arithmetic operators in Visual Basic.

The following example shows arithmetic operations.

In the preceding example, we use addition, subtraction, multiplication and division operations. This is all familiar from the mathematics.

Next we show the distinction between normal and integer division.

In the preceding example, we divide two numbers using normal and integer division operator. Visual Basic has two distinct operators for division.

We use floating point data types.

This is floating-point division.

This is integer division. The result of this operation is always and integer.

The last two operators that we mention are modulo operator and exponentiation operator.

The Mod operator is called the modulo operator. It finds the remainder of division of one number by another. 9 Mod 4 , 9 modulo 4 is 1, because 4 goes into 9 twice with a remainder of 1. Modulo operator can be handy for example when we want to check for prime numbers.

Finally, we mention exponentiation operator.

9 ^ 2 = 9 * 9 = 81

Concatenating strings

In Visual Basic we have two operators for string concatenation. The plus + operator and the & ampersand operator. We can also use the String.Concat method.

We join three strings.

In Visual Basic, we have the following logical operators. Boolean operators are also called logical.

Boolean operators are used to work with truth values.

Many expressions result in a boolean value. Boolean values are used in conditional statements.

Relational operators always result in a Boolean value. These two lines print False and True.

The body of the If statement is executed only if the condition inside the parentheses is met. The x > y returns True, so the message "y is greater than x" is printed to the terminal.

Example shows the logical And operator. It evaluates to True only if both operands are True.

The logical Xor operator evaluates to True, if exactly one of the operands is True.

The logical Xor evaluates to False if both operands are True or both False.

The logical Or operator evaluates to True, if either of the operands is True.

If one of the sides of the operator is True, the outcome of the operation is True.

The negation operator Not makes True False and False True.

The example shows the negation operator in action.

AndAlso , OrElse operators are short circuit evaluated. Short circuit evaluation means that the second argument is only evaluated if the first argument does not suffice to determine the value of the expression: when the first argument of And evaluates to false, the overall value must be false; and when the first argument of Or evaluates to true, the overall value must be true. Short circuit evaluation is used mainly to improve performance.

An example may clarify this a bit more.

We have two functions in the example. Functions, unlike subroutines, return values. This is the main difference between them.

The one function returns False. The short circuit AndAlso does not evaluate the second function. It is not necessary. Once an operand is False, the result of the logical conclusion is always False. Only "Inside one" is printed to the console.

In the second case, we use the And . In this case, both functions are called. Even though it is not necessary for the result of the expression.

Relational Operators

Relational operators are used to compare values. These operators always result in a boolean value.

Relational operators are also called comparison operators.

As we already mentioned, the relational operators return boolean values. Note that in Visual Basic, the comparison operator is = .

Notice that the relational operators are not limited to numbers. We can use them for other objects as well. Although they might not always be meaningful.

We can compare string objects too. Comparison operators in a string context compare the sorting order of the characters.

What exactly happens here? Computers do not know characters or strings. For them, everything is just a number. Characters are special numbers stored in specific tables. Like ASCII.

Internally, the a and b characters are numbers. So when we compare two characters, we compare their stored numbers. The built-in Asc function returns the ASCII value of a single character.

In fact, we compare two numbers, 97 with 98.

Say we have a string with more characters. If the first characters are equal, we compare the next ones. In our case, the b character at the second position has a greater value than the a character. That is why "ab" string is greater than "aa" string. Comparing strings in such a way does not make much sense, of course. But it is technically possible.

Finally, we mention the Is operator. The operator checks if two object references refer to the same object. It does not perform value comparisons.

We create three objects and compare them with the Is operator.

We declare and initialise two Object instances. The Object class is a base class for all classes in the .NET framework. We describe it later in more detail.

The third variable is only declared.

The o3 now refers to the o2 object. They are two references to the same object.

In the first case, we get False. The o1 and o2 are two different objects. In the second case, we get True. The o3 and o2 refer to the same object.

Decimal numbers are natural to humans. Binary numbers are native to computers. Binary, octal, decimal, or hexadecimal symbols are only notations of the same number. Bitwise operators work with bits of a binary number. Bitwise operators are seldom used in higher level languages like Visual Basic.

The bitwise negation operator changes each 1 to 0 and 0 to 1.

The operator reverts all bits of a number 7. One of the bits also determines, whether the number is negative or not. If we negate all the bits one more time, we get number 7 again.

The bitwise and operator performs bit-by-bit comparison between two numbers. The result for a bit position is 1 only if both corresponding bits in the operands are 1.

The first number is a binary notation of 6, the second is 3 and the result is 2.

The bitwise or operator performs bit-by-bit comparison between two numbers. The result for a bit position is 1 if either of the corresponding bits in the operands is 1.

The result is 00110 or decimal 7.

The bitwise exclusive or operator performs bit-by-bit comparison between two numbers. The result for a bit position is 1 if one or the other (but not both) of the corresponding bits in the operands is 1.

The result is 00101 or decimal 5.

Compound assignment operators

The compound assignment operators consist of two operators. They are shorthand operators.

The += compound operator is one of these shorthand operators. They are less readable than the full expressions but experienced programmers often use them.

Other compound operators are:

Operator precedence

The operator precedence tells us which operators are evaluated first. The precedence level is necessary to avoid ambiguity in expressions.

What is the outcome of the following expression, 28 or 40?

Like in mathematics, the multiplication operator has a higher precedence than addition operator. So the outcome is 28.

To change the order of evaluation, we can use parentheses. Expressions inside parentheses are always evaluated first.

The following list shows common Visual Basic operators ordered by precedence (highest precedence first):

Operators on the same line in the list have the same precedence.

In this code example, we show some common expressions. The outcome of each expression is dependent on the precedence level.

This line prints 28. The multiplication operator has a higher precedence than addition. First the product of 5*5 is calculated. Then 3 is added.

In this case, the negation operator has a higher precedence. First, the first True value is negated to False, than the Or operator combines False and True, which gives True in the end.

Associativity

Sometimes the precedence is not satisfactory to determine the outcome of an expression. There is another rule called associativity . The associativity of operators determines the order of evaluation of operators with the same precedence level.

What is the outcome of this expression? 9 or 1? The multiplication, deletion and the modulo operator are left to right associated. So the expression is evaluated this way: (9 / 3) * 3 and the result is 9.

Arithmetic, boolean, relational and bitwise operators are all left o right associated.

On the other hand, the assignment operator is right associated.

If the association was left to right, the previous expression would not be possible.

The compound assignment operators are right to left associated.

You might expect the result to be 1. But the actual result is 0. Because of the associativity. The expression on the right is evaluated first and than the compound assignment operator is applied.

AddressOf operator

The AddressOf operator creates a function delegate that points to another function. Delegates are type safe function pointers, they are used to call methods of other objects.

In the code example, we use the AddressOf operator to point to two different subroutines.

We need to declare a delegate.

The delegate takes the address of a subroutine using the AddressOf operator. Now we have a type-safe pointer to the Message1 subroutine.

The Invoke method calls the method, to which the delegate points.

Now we give the delegate an address of another subroutine.

Both messages are printed to the console.

In this part of the Visual Basic tutorial, we covered the operators.

what is visual basic assignment

  • API & MACROS
  • PDM PROFESSIONAL (EPDM) API
  • DOCUMENT MANAGER API
  • EDRAWINGS API
  • VISUAL BASIC

Declaration and assignment of variables and constants in Visual Basic

Declaring variables.

Variables can be declared either explicitly or implicitly in Visual Basic. To declare variable explicitly it is required to use Dim keyword or Public keyword to declare the variable as public class or module member (refer the Variables Scope article for more information).

Type of the variable can be declared using As keyword.

If type of the variable is not explicitly stated than it is defaulted to Variant

Dim keyword is not used when variable is declared implicitly. In this case value of the variable assigned directly.

This is not recommended approach as it may introduce the ambiguity and potential issues with the code.

In order to force explicit variable declaration in Visual Basic it is required to use Option Explicit statement. In this case compile error will occur if implicit variable is identified.

Compile error when Explicit option is enabled and implicit variable assignment is used

Declaring group of variables of the same type

Variables can be declared in the group.

This approach allows to make code more readable and compact.

Declaring group of variables with different types

It is allowed to use declaration characters for each variable to declare the type explicitly using the short declaration

Refer the Standard Types article for the list of declaration characters.

This is a legacy way to declare the variables. This approach is not recommended way to declare the variables.

Assigning the values

In order to assign the value of the variable it is required to use equal (=) sign, where the variable name appears on the left and variable value appears on the right.

it is possible to copy the value from one variable to another

It is possible to assign the value to the variable as the result of calling another function. Refer Functions and Procedures article on more information about functions.

Declaring constants

Constant allows to define the value which will not change during execution. It is usually used for declaring mathematical constants (e.g. PI, gravitational constant, etc.), conversions factors (e.g. hours to minutes, inches to meters etc.) or any other program specific values.

Constant is declared using Const statement and must assign the value on declaration.

Same as variable declaration constant type can be defined explicitly (using As keyword) or implicitly.

Once declared value of the constant cannot be changed. Otherwise the compile error will occur.

Compile error assignment to constant not permitted when changing the value of constant variable

This code example demonstrates different ways of declaring and assigning constants and value variables.

Assigning reference variables

Unlike value types, references types must follow several additional rules when assigning the value.

Custom User Defined Type

  • It is required to use new keyword to create new instance of the referenced type. Otherwise Run-time error '91' will be displayed

Run-time error '91': Object variable or With block variable not set when calling the member of uninitialized reference

  • It is required to use Set keyword to assign the value, otherwise the Run-time error '91' will be displayed

Run-time error '91': Object variable or With block variable not set when Set keyword is not used to assign the reference to the variable

See code below for the correct assignment of reference type variable.

References variables are only holding the pointer to the actual value, i.e. Set keyword assigns the reference (not the actual value like in value types). That means if reference of one variable is assigned to another variables, both of them now refer the same data.

Binding is a process of assigning object to a variable. When early binding is used the specific object type is declared in advanced so the binding can occur at compile time. Late binding is resolved at runtime and specific object type is not known in advance.

Early Binding

Early bound objects are usually initiated with new keyword

  • Performance. Compiler can perform required optimization as the type of the object and its size is known at compile time
  • Maintainability. Code is cleaner and easier to maintain and read when specific type is declared
  • Dynamic help and IntelliSense (code completion) features are available for early bound objects

Late Binding

While late bound objects are usually initiated with CreateObject or GetObject functions

But it is still acceptable to use new keyword in late binding and CreateObject or GetObject in early binding.

  • No need to maintain 3rd party references which may be an issue when code is ported to another environment or another version of 3rd party references is released. Refer this Example of references issue

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Visual Basic Fundamentals for Absolute Beginners: (15) Understanding and Creating Classes

Now that you have a good sampling of basic Visual Basic syntax under your belt, it's time to tackle some of the more challenging topics. Classes are integral to the .NET Framework, particularly the .NET Framework Class Library. As a means of better understanding what classes are -- particularly as utilized in the .NET Framework -- we demonstrate how to create your own custom classes. In this lesson we demonstrate how classes are defined and new instances are created. We demonstrate how to define Properties (using the prop "code snippet" to create auto implemented properties) and how to both set their values and get their values for a given instance of the class as well as creating Methods in our classes. We talk about how the classes you create are really custom dat types and can be used as such in helper method declarations and such.

Full course outline:

  • Mod 01: Series Introduction
  • Mod 02: Installing Visual Studio Express 2013 for Windows Desktop
  • Mod 03: Creating Your First Visual Basic Program
  • Mod 04: Dissecting the First Visual Basic Program You Created
  • Mod 05: Quick Overview of the Visual Basic Express Edition IDE
  • Mod 06: Declaring Variables and Assigning Values
  • Mod 07: Branching with the If..Then..Else Decision Statement
  • Mod 08: Operators, Expressions and Statements
  • Mod 09: For..Next Iterations
  • Mod 10: Creating Arrays of Values
  • Mod 11: Creating and Calling Simple Overloaded Helper Methods
  • Mod 12: While Iterations and Reading Data from a Text File
  • Mod 13: Working with Strings
  • Mod 14: Working with Dates
  • Mod 15: Understanding and Creating Classes
  • Mod 16: More about Classes and Methods
  • Mod 17: Working with Classes and Inheritances in the .NET Framework Class Library
  • Mod 18: Understanding Namespaces and Adding References to Assemblies
  • Mod 19: Understanding Modules, Scope and Utilizing Accessibility Modifiers
  • Mod 20: Enumerations and the switch Decision Statement
  • Mod 21: Gracefully Handling Exceptions
  • Mod 22: Working with Collections
  • Mod 23: Filtering and Managing Data in Collections using LINQ
  • Mod 24: Understanding Event Driven Programming
  • Mod 25: Getting Familiar with the My Namespace
  • Mod 26: Where To Go From Here

Have feedback? Submit an issue here .

COMMENTS

  1. Assignment Operators

    The following are the assignment operators defined in Visual Basic. = Operator ^= Operator *= Operator /= Operator \= Operator += Operator-= Operator <<= Operator >>= Operator &= Operator. See also. Operator Precedence in Visual Basic; Operators Listed by Functionality; Statements

  2. Statements in Visual Basic

    A statement in Visual Basic is a complete instruction. It can contain keywords, operators, variables, constants, and expressions. Each statement belongs to one of the following categories: Declaration Statements, which name a variable, constant, or procedure, and can also specify a data type. Executable Statements, which initiate actions.

  3. Writing assignment statements (VBA)

    Assignment statements assign a value or expression to a variable or constant. Assignment statements always include an equal sign ( = ). The following example assigns the return value of the InputBox function to the variable. Dim yourName As String.

  4. Understanding assignment/comparison vb.net

    The first = is an assignment. So we assign the right part to the dictionary. Now for the right part: Me.demandas2.Item(label3 = label) = (dictionary.Item(label3) - 1) The = between the two expressions is a comparison, so it returns a Boolean. So the supposed "dictionary" is assigned a boolean value. If we check the left part of that expression:

  5. Writing Code with Visual Basic .NET

    Earlier Visual Basic versions (Visual Basic 4.0 to 6.0) had two different ways of assigning a value to a variable—one for simple variables (including structures and arrays) and one for object variables. Fortunately, the developers of Visual Basic .NET decided to remove the assignment method used for object variables, and rely only on the ...

  6. Writing Visual Basic statements

    A statement in Visual Basic is a complete instruction. Each statement belongs to one of the following three categories: declaration statements: which name (declare) a variables , constant, or procedure and can also specify a data type. assignment statements: which assign a value or expression to a variable, constant or property.

  7. Introduction to Visual Basic Programming

    There are 4 modules in this course. This course is the second course in a series that aims to prepare you for a role working as a programmer. In this course, you will be introduced to the five main concepts in procedural programming: user input, console output, variable declaration and assignment, decision branching and iteration.

  8. Introduction to Computer Programming with Visual Basic

    Learners will use new skills in various programming assignments designed to help you master the most used features of Visual Basic. Each programming assignment includes a video solution to ensure that you completely understand the concepts and are able to complete the tasks.

  9. Assignment

    Assignment. In Visual Basic .NET, assignment statements are of the form: variable, field, or. property =. expression. Either the type of the expression must be the same as that of the item receiving the assignment, or there must exist an appropriate implicit or explicit conversion from the type of the expression to the type of the item ...

  10. = Operator

    The element on the left side of the equal sign ( =) can be a simple scalar variable, a property, or an element of an array. The variable or property cannot be ReadOnly. The = operator assigns the value on its right to the variable or property on its left. The = operator is also used as a comparison operator. For details, see Comparison Operators.

  11. += Operator

    This assignment operator implicitly performs widening but not narrowing conversions if the compilation environment enforces strict semantics. For more information on these conversions, see Widening and Narrowing Conversions.For more information on strict and permissive semantics, see Option Strict Statement.. If permissive semantics are allowed, the += operator implicitly performs a variety of ...

  12. PDF Variables in Visual Basic

    Visual Basic, just like most programming languages, uses variables for storing values. A variablehas a name (the word that you use to refer to the value that the variable contains). A variable also has a data type (which determines the kind of data that the variable can store).

  13. Visual Basic for Applications (VBA): Definition, Uses, Examples

    Visual Basic For Applications - VBA: Visual Basic is a computer programming language allows the creation of user-defined functions and the automation of specific computer processes and ...

  14. Operators in Visual Basic

    The last two operators that we mention are modulo operator and exponentiation operator. Console.WriteLine(9 Mod 4) ' Prints 1. The Mod operator is called the modulo operator. It finds the remainder of division of one number by another. 9 Mod 4, 9 modulo 4 is 1, because 4 goes into 9 twice with a remainder of 1.

  15. What Is Visual Basic Used For?

    Visual Basic (VB) is an object-oriented programming language (OOP) introduced by Microsoft in 1991. It derives from an earlier programming language called BASIC, which stands for "Beginners' All-purpose Symbolic Instruction Code.". VB was designed to enable rapid application development (RAD) of graphical-user interface-based (GUI-based ...

  16. Declaration and assignment of variables and constants in Visual Basic

    Assigning the values. In order to assign the value of the variable it is required to use equal (=) sign, where the variable name appears on the left and variable value appears on the right. Dim varName As String. varName = "VarValue". it is possible to copy the value from one variable to another.

  17. PDF Statements in Visual Basic

    A statement in Visual Basic is a complete instruction. It can contain keywords, operators, variables, constants, and expressions. Each statement belongs to one of the following categories: Declaration Statements, which name a variable, constant, or procedure, and can also specify a data type. Executable Statements, which initiate actions.

  18. &= Operator

    Remarks. The element on the left side of the &= operator can be a simple scalar variable, a property, or an element of an array. The variable or property cannot be ReadOnly. The &= operator concatenates the String expression on its right to the String variable or property on its left, and assigns the result to the variable or property on its left.

  19. Navigating the Programming Realm with Ease: Visual Basic Assignment

    Visual Basic is a programming language developed by Microsoft, known for its simplicity and ease of use. It enables developers to create applications with graphical user interfaces (GUIs) quickly ...

  20. Visual Basic Fundamentals for Absolute Beginners: (15) Understanding

    Now that you have a good sampling of basic Visual Basic syntax under your belt, it's time to tackle some of the more challenging topics. Classes are integral to the .NET Framework, particularly the .NET Framework Class Library. As a means of better understanding what classes are -- particularly as utilized in the .NET Framework -- we demonstrate how to create your own custom classes. In this ...