ICT Tutorials
  • HOME
  • INTRO & WINDOWS
    • INTRODUCTION >
      • FUNDAMENTAL OF IT
      • TYPE OF COMPUTER DEVICES
      • COMPUTER GENERATION
      • SYSTEM COMPUTER
      • TYPE OF COMPUTERS
      • NUMBERING SYSTEM
      • TYPE OF MOUSE
      • KEYBOARD
      • DATA PROCESSING
      • OPERATING SYSTEM
      • HISTORY OF COMPUTER
    • MS WINDOWS >
      • ABOUT MS WINDOWS
      • WINDOWS DESKTOP
      • Win Control Activation
  • MS OFFICE
    • ABOUT MS-OFFICE
    • MS WORD >
      • INTRO TO MS-WORD
      • FILE >
        • INFO, NEW, OPEN
        • SAVE AND SAVE AS, PRINT
        • SHARE, EXPORT, CLOSE
      • HOME >
        • CUT, COPY, PASTE, FORMAT PAI
        • FONT
        • STYLES
        • FIND, GO TO, REPLACE
      • INSERT >
        • PAGES -COVER, BLANK, BREAK
        • TABLES
        • ILLUSTRATIONS >
          • PICTURES, ONLINE PICTURE
          • SHAPES, ICONS, 3D MODELS
          • SmartArt
          • CHART, SCREENSHOT
        • LINK, BOOKMARK, CROSS-REF
        • COMMENT, HEADER/FOOTER
        • TEXTS >
          • TEXT BOX, WORDART, DROP CAP, OBJECT
        • SYMBOL
      • DRAW >
        • PENS
      • DESIGN >
        • DOC STYLES, WATERMARK
        • PHARAGRAPH
        • PAGE COLOR, BORDERS
      • LAYOUT >
        • PAGE SETUP, SPACING
        • ARRANGE OBJECTS
      • REFERENCES >
        • TABLE OF CONTENTS
      • MAILINGS >
        • ENVELOPES
      • REVIEW >
        • DOC REVIEWS
      • VIEW >
        • WEB LAYOUT, NEW WIN, SPLIT
        • SWITCH WINDOWS, MACROS
    • MS EXCEL >
      • INTRO TO MS-EXCEL
      • FILE >
        • INFO, NEW, OPEN
        • SAVE/SAVE AS, PRINT
        • SHARE, EXPORT
      • HOME >
        • ALIGNMENT >
          • CELL ALIGN, ORIENTATION
          • INDENTS, MERGE & CENTER
        • NUMBER, COND FORMAT
        • TABLE, INSERT, DELETE
        • FORMAT >
          • ROW HEIGHT, COLUMN WIDTH
          • HIDE, RENAME, MOVE OR COPY
        • PROTECT SHEET, FILL
        • SORT & FILTER, AUTOSUM
      • FORMULAS >
        • INTRO TO FORMULAS
        • MATH & TRIM >
          • ABS( ), COMBIN( )
          • SUM FUNCTIONS( )
          • COS( ), SIN( )
          • BASE( )
        • STATISTICAL >
          • AVERAGE FUNCTIONS( )
          • MAX FUNCTIONS( )
          • MIN FUNCTIONS( )
          • COUNT FUNCTIONS( )
          • MODE FUNCTIONS( )
        • ENGINEERING >
          • BIN2DEC
          • CONVERT
        • TEXT FUNCTIONS >
          • LEFT( ) RIGHT( ) MID( )
          • FIND( ) LEN( ) PROPER( )
          • TRIM( ) EXACT( ) FIXED( )
          • REPLACE, UNICHAR, UNICODE
          • CODE( ) CHAR( ) REPT( )
        • DATE & TIME FUNCTIONS >
          • TODAY( ) YEAR( ) DAYS( )
        • LOGICAL >
          • IF( ), IFERROR( )
          • IFS( ), SWITCH( )
          • AND( ), OR( )
          • IFNA( ), XOR( )
      • INSERT >
        • CHARTS, SPARKLINES
      • PAGE LAYOUT >
        • PRINT TITLES, SHEET OPTION
      • DATA >
        • GET DATA, DATA VALIDATION
        • CONSOLIDATE
      • VIEW >
        • WORKBOOK VIEWS
      • Excel Functions Exercises >
        • Exercises 1 and 2
        • Exercises 3 and 4
    • MS POWER POINT >
      • INTRO TO MS-POWERPOINT
      • FILE >
        • INFO, NEW, OPEN
        • SAVE AND SAVE AS, PRINT
        • SHARE, EXPORT, CLOSE
      • HOME >
        • NEW SLIDE, STYLES, FILL
      • INSERT >
        • PHOTO ALBUM, VIDEO, AUDIO
        • SCREEN REC, SHOT, SLIDE NUM
      • DESIGN >
        • THEMES, SLIDESIZE, FORMAT
      • TRANSITION >
        • TRANSITION, SOUND
    • MS ACCESS >
      • INTRO TO MS-ACCESS
      • FILE >
        • HOME, NEW, OPEN
    • OFFICE QUESTION & ANSWER
  • VISUAL STUDIO
    • VISUAL BASIC .NET >
      • INTRODUCTION
      • .NET FRAMEWORK
      • OPERATORS IN VB.NET
      • DATAYPES IN VB.NET
      • VB.NET KEYWORDS
      • VARIABLE AND CONST
      • INTRO TO VB.NET PLATFORM
      • INTRO TO PROGRAMMING
      • OBJECTS USAGE IN WIN-FORM
    • Python >
      • Introduction
    • C++
  • GOOGLE TIPS
    • GMAIL ACCOUNT >
      • Email Forwarding
      • Setting up Authenticator App
      • SIGNATURE SET UP
    • GOOGLE WORKSPACE
  • INVENTS
    • NEW INVENTS
  • ABOUT ME

variable and const in vb.net

5/11/2022

0 Comments

 
VARIABLE AND CONST IN VB.NET
A variable is used to store value that can be used in the future in the programming. Variables can be created in order to storing different type of data as they are numbers, characters or combination of anything. When we say variable that it is always a namespace in the memory or simply says a space allocated to store data in a namespace in the memory which can be created with letters only, letters and numbers, or letters, numbers and underscore.

In This Tutorial:
  • Understanding about Variables in VB.NET
  • Understanding about Const in VB.NET
  • Scopes of the Variables in VB.NET
​
Understanding about Variables in VB.NETActually, this is a first question: What is a Variable?
A variable is a namespace which is used to store and retrieve the data where needed in the programming.

Why is a variable in VB.NET?
​When a programmer needed something to store the data for temporarily or permanently in the purpose of reuse, variable will be the best option to do that. And most importantly variable can be used as predefined to store the data at the later time or preassigned as it is being assigned the data when it's created.

How to create a variable in VB.NET?
When you want to create a variable should be followed the syntax of variable declaration.
Syntax:
Dim [variable_name] As Datatype [Value (Optional)]
Picture
The declaration of a variable is simple that requires a variable name and data type followed by a Dim. A Dim is used in Class, Module, structure, Sub and procedure.

A valid declaration:
Dim First_Name As String
Dim Num_01 As Integer = 22

An invalid variable declaration:
Click here "VB.NET KEYWORDS" and read for further understanding.
​
Assigning more than one variable with one Dim:
When you want to create many variables with the ​same datatype use the comma at the end of each variable. And it's important that you should understand about all the variables will be the same datatype and can be used for store only the particular datatype(data) as if you've chosen as Integer, then you can't use that variable for storing the first name or last name and only can be used to store numbers. 

Syntax:
Dim [Variable_Name1], [Variable_Name2], [Variable_Name3] As Integer

A valid declaration:
Dim first_name, middle_name, lastname As String

After a declaration of a variable, how to assign a value/data to it?
Example: 
Dim first_name As String
Dim Age as Integer

first_name = "Mano"
Age = 22

The above data assigns are valid.

Const in VB.NET
The name constant refers to a fixed value that cannot be changed during the execution of a program. It is also known as literals. These constants can be of any data type, such as Integer, Double, String, Decimal, Single, character etc.

Declaration of Const:
The const is a keyword in VB.NET that is used to declare a variable as constant. The Const statement can be used with module, structure, procedure, form and class.

When you want to declare a variable with const should be followed the syntax of const variable declaration.
Syntax:
Const const_name As Datatype = Value
Picture
How to declare variables with different Const Structurals?
Examples:
  1. Const num As Integer = 22  
  2. Static name As String  
  3. Private Const PI As Double = 3.14
  4. Public Const name As String = "First_Name"

Scope of Variable in VB.NET
The scope of a variable determines the accessible range of a defined variable at the time of declaration in any block, module, and class. You can access it if the variable is in a particular region or scope in the same block. And if the variable goes beyond the region, its scope expires.

Following are the methods to represent the scope of a variable in VB.NET.
  1. Global Scope
  2. Local Scope
  3. Module Scope

Global (Public) Scope
The global variable is a variable that is used to access the variables globally in a program. It means these variables can be accessed by all the procedures or modules available in a program. To access the variables globally in a program, you need to use the friend or public keyword with a variable in a module or class at the top of the first procedure function. Global scope is also known as the Namespace scope.

Example: Public string_hw As String = "Hello World" 

Procedure (local) scope
A local variable is a type of variable defined within a procedure scope, block, or function. It is available with a code inside the procedure, and it can be declared using the Dim or static statement. These variables are not accessible from outside of the local method. However, the local variable can be easily accessed by the nested programming function in the same method.
  • Example: Dim Num As Integer

The local variables exist until the procedure in which they are declared is executed. Once a procedure is executed, the values of its local variables will be lost, and the resources used by these variables will be released. And when the block is executed again, all the local variables are rearranged.

Module Scope
The existing procedures can easily identify a variable that is declared inside a module sheet is called a module-level variable. The defined module variable is visible to all procedures within that module only, but it is not available for other module's procedures. The Dim or private statement at the top of the first procedure declaration can be declared the module-level variables. It means that these variables cannot be declared inside any procedure block. Further, these variables are useful to share information between the procedures in the same module. And one more thing about the module-level variable is that these variables can remains existence as long as the module is executed.

 Below is the declaration section of the module:
  1. Private num As Integer (A private module-level variable)
  2. Dim name As String (Another private module-level variable)
0 Comments



Leave a Reply.

    Archives

    November 2022

    RSS Feed

​WELCOME TO WWW.COMTEACHERS.COM and We Would Love To Have You Visit Next Time Too! FOR MOBILE USERS, TO READ THE NOTES PLEASE CLICK MENU ICON, IT SHOULD BE EITHER ON TOP LEFT OR RIGHT CORNER OF YOUR SCREEN AND THEN CLICK MENU BY MENU TO CONTINUE READINGS...
  • HOME
  • INTRO & WINDOWS
    • INTRODUCTION >
      • FUNDAMENTAL OF IT
      • TYPE OF COMPUTER DEVICES
      • COMPUTER GENERATION
      • SYSTEM COMPUTER
      • TYPE OF COMPUTERS
      • NUMBERING SYSTEM
      • TYPE OF MOUSE
      • KEYBOARD
      • DATA PROCESSING
      • OPERATING SYSTEM
      • HISTORY OF COMPUTER
    • MS WINDOWS >
      • ABOUT MS WINDOWS
      • WINDOWS DESKTOP
      • Win Control Activation
  • MS OFFICE
    • ABOUT MS-OFFICE
    • MS WORD >
      • INTRO TO MS-WORD
      • FILE >
        • INFO, NEW, OPEN
        • SAVE AND SAVE AS, PRINT
        • SHARE, EXPORT, CLOSE
      • HOME >
        • CUT, COPY, PASTE, FORMAT PAI
        • FONT
        • STYLES
        • FIND, GO TO, REPLACE
      • INSERT >
        • PAGES -COVER, BLANK, BREAK
        • TABLES
        • ILLUSTRATIONS >
          • PICTURES, ONLINE PICTURE
          • SHAPES, ICONS, 3D MODELS
          • SmartArt
          • CHART, SCREENSHOT
        • LINK, BOOKMARK, CROSS-REF
        • COMMENT, HEADER/FOOTER
        • TEXTS >
          • TEXT BOX, WORDART, DROP CAP, OBJECT
        • SYMBOL
      • DRAW >
        • PENS
      • DESIGN >
        • DOC STYLES, WATERMARK
        • PHARAGRAPH
        • PAGE COLOR, BORDERS
      • LAYOUT >
        • PAGE SETUP, SPACING
        • ARRANGE OBJECTS
      • REFERENCES >
        • TABLE OF CONTENTS
      • MAILINGS >
        • ENVELOPES
      • REVIEW >
        • DOC REVIEWS
      • VIEW >
        • WEB LAYOUT, NEW WIN, SPLIT
        • SWITCH WINDOWS, MACROS
    • MS EXCEL >
      • INTRO TO MS-EXCEL
      • FILE >
        • INFO, NEW, OPEN
        • SAVE/SAVE AS, PRINT
        • SHARE, EXPORT
      • HOME >
        • ALIGNMENT >
          • CELL ALIGN, ORIENTATION
          • INDENTS, MERGE & CENTER
        • NUMBER, COND FORMAT
        • TABLE, INSERT, DELETE
        • FORMAT >
          • ROW HEIGHT, COLUMN WIDTH
          • HIDE, RENAME, MOVE OR COPY
        • PROTECT SHEET, FILL
        • SORT & FILTER, AUTOSUM
      • FORMULAS >
        • INTRO TO FORMULAS
        • MATH & TRIM >
          • ABS( ), COMBIN( )
          • SUM FUNCTIONS( )
          • COS( ), SIN( )
          • BASE( )
        • STATISTICAL >
          • AVERAGE FUNCTIONS( )
          • MAX FUNCTIONS( )
          • MIN FUNCTIONS( )
          • COUNT FUNCTIONS( )
          • MODE FUNCTIONS( )
        • ENGINEERING >
          • BIN2DEC
          • CONVERT
        • TEXT FUNCTIONS >
          • LEFT( ) RIGHT( ) MID( )
          • FIND( ) LEN( ) PROPER( )
          • TRIM( ) EXACT( ) FIXED( )
          • REPLACE, UNICHAR, UNICODE
          • CODE( ) CHAR( ) REPT( )
        • DATE & TIME FUNCTIONS >
          • TODAY( ) YEAR( ) DAYS( )
        • LOGICAL >
          • IF( ), IFERROR( )
          • IFS( ), SWITCH( )
          • AND( ), OR( )
          • IFNA( ), XOR( )
      • INSERT >
        • CHARTS, SPARKLINES
      • PAGE LAYOUT >
        • PRINT TITLES, SHEET OPTION
      • DATA >
        • GET DATA, DATA VALIDATION
        • CONSOLIDATE
      • VIEW >
        • WORKBOOK VIEWS
      • Excel Functions Exercises >
        • Exercises 1 and 2
        • Exercises 3 and 4
    • MS POWER POINT >
      • INTRO TO MS-POWERPOINT
      • FILE >
        • INFO, NEW, OPEN
        • SAVE AND SAVE AS, PRINT
        • SHARE, EXPORT, CLOSE
      • HOME >
        • NEW SLIDE, STYLES, FILL
      • INSERT >
        • PHOTO ALBUM, VIDEO, AUDIO
        • SCREEN REC, SHOT, SLIDE NUM
      • DESIGN >
        • THEMES, SLIDESIZE, FORMAT
      • TRANSITION >
        • TRANSITION, SOUND
    • MS ACCESS >
      • INTRO TO MS-ACCESS
      • FILE >
        • HOME, NEW, OPEN
    • OFFICE QUESTION & ANSWER
  • VISUAL STUDIO
    • VISUAL BASIC .NET >
      • INTRODUCTION
      • .NET FRAMEWORK
      • OPERATORS IN VB.NET
      • DATAYPES IN VB.NET
      • VB.NET KEYWORDS
      • VARIABLE AND CONST
      • INTRO TO VB.NET PLATFORM
      • INTRO TO PROGRAMMING
      • OBJECTS USAGE IN WIN-FORM
    • Python >
      • Introduction
    • C++
  • GOOGLE TIPS
    • GMAIL ACCOUNT >
      • Email Forwarding
      • Setting up Authenticator App
      • SIGNATURE SET UP
    • GOOGLE WORKSPACE
  • INVENTS
    • NEW INVENTS
  • ABOUT ME