Table of Contents
What Is Programming Language In a Computer? | What Is Computer Programming Language? | What Is Programming Language And Its Types | Computer Programming Language In English
Introduction To Computer Programming Language Part-1 – In any natural language or colloquial language, there is a special grammar in addition to alphabets, words, phrases, and sentences. Grammar teaches us to speak the language properly and write its script. In the same way, the computer programming language has its own characters, words, phrases, and grammar. It is very important to take care of these things while writing a program.
The literal meaning of variable is something that always changes. It is like a compartment in your kitchen in the computer, in which sometimes something is kept. In technical terms, its definition would be as follows-
A variable is a holder of program-related information that can store one or more values. Whenever you want to store some information that is going to be used in the program, you can name it as a variable. The name of a variable usually does not change but there is a possibility that the value may change during the execution of the program. You can also think of a variable as the column heading of a table.
Variable Names And Values
Computer Programming Language Part-1 | Computer Programming Language – Which Is The First Computer Programming Language? | What Is Computer Programming Language
Naming Conventions Of Variable
Variables store values during the execution of the program. Runtime (implementation) variables in Visual Basic dot net are used to store data temporarily. A variable has a special name and its data is of a special type. The name of a variable is used to access and manipulate the value of the variable. The data type of a variable determines the type of data that a variable can store.
The name of a variable is very important in a program, so it is essential. It is important that you be careful while naming it. There are some standard rules for naming variables, which are generally almost the same in all programming languages. Let us see what these rules are-
- It is considered good practice to start the name of any variable with a letter. Although it is acceptable to start the variable name with an underscore (), it is not recommended. The rationale is that the variable name should be easily recognizable.
- In addition to alphabet, numeric and underscore in the name of the variable, white space is also not valid in the name of the special character.
- It is considered good to use Pascal casing in variable names. However, many programmers also use camel casing. EmpFirstName is an example of Pascal casing. (See Reflections to learn about Pascal and Camel Casing)
- The name of the variable is not unnecessarily long.
- The name of the bearer is B.B. Dot net should not have any reserved words ie keywords.
However, the above rules are not as strict as the Penal Code of a country, for non-observance of which there is a punishment.
But if these rules are followed, apart from avoiding many types of errors in the program, it helps in error prevention.
Can get it. Table lists the names of some valid and invalid variables and why they are valid or invalid.
It is understood that it has been told.
|EmpFirstName||valid / good||Small and following all the prevalent rules|
|Employee FirstName||valid / not good||emp can be used in the name of a slightly bigger employee.|
|_EmpFirstName||valid / not good||It’s a bit confusing.|
|Emp_First_Name||valid / not good||It’s a bit confusing.|
|01EmpFirstName||invalid||The starting character of the variable is numeric.|
|Emp FirstName||invalid||Space has been used after Emp.|
|Dim/For||invalid||VB Dot is a reserved word for net.|
|Emp$First Name||invalid||The dollar sign is used.|
The essence of the variable naming convention is that the name of the variable should not confuse you during the implementation of the programming and the implementation should be error free.
Declaring the variable means that what will be the name of the variable and what will be the type of its data. The Dim keyword is used to declare a variable in Visual Basic Dot Net. Its direct syntax is-
Dim Variable [As Type]
Here it would be necessary to understand why we specify the type of the variable. VB Dot Net recommends you to declare the type of the variable as well for some important reasons. The first reason is that you know which variable can store which type of data. Second, its big advantage is that there is no accumulation of many types of data in the same variable.
And since a variable is not just a name, it is also a part of memory management. So declaring the data type will have the advantage that you will be able to manage memory efficiently as different types of data take up different places in the memory. For example the following statement –
Dim EmpFirstName As String
The name of the variable EmpFirstName and the type of the stored array String is declared. Now suppose that what will happen if you forget to declare the data type of the variable? Like this statement –
VB In dot net, when we do not declare the data type of a variable, then V.B. Dot Net assigns it the Object type by default.
As you read in the previous article how important it is to declare the data type while declaring a variable in VB.NET. In order to manage memory as well as to make it easier to debug the program, it is necessary that you declare the data type of the variable with care. The data types of VB.net are explained in the table.
Question: Let’s say you name the variable EmpAge for the age of the employee. Tell me which data would be suitable for this?
Answer: The most suitable data type for this would be Byte. Its statement will be like this.
Dim EmpAge As Byte
This is because you can have a byte value from 0 to 225 and the age of the employee will also be in this range.
|Data Types||Storage Space||(Accepted Range of numbers/Description)|
|Object||4 or 8 byte (depending on platform Changes.)||It is used to store data in any way.|
|Integer||4 byte||–2, 147, 483, 648 to 2,147,647. It is used to store numeric data. It is stored in 32-bit number.|
|Char||2 byte||From 0 to 65535. We can use it to store character.|
|date||8 byte||Between January 1,000, and December 31,9999. It is used to store date information.|
|Decimal||16 byte||+/-79, 228, 162, 514, 264, 337, 593, 543, 950, 335 to any number of decimal points. +/-7.92281625142644375935439 50335 which can have 28 places to the right of the decimal point. The smallest non-zero number is +/- 0.00000000000000000000000000001. It is used to store very large floating point values. 50335 which can have 28 places to the right of the decimal point. The smallest non-zero number is +/- 0.00000000000000000000000000001. It is used to store very large floating point values. It is in doing.|
|Byte||1 byte||From 0 to 255. It is used to store binary data. It can also store its character values in numeric format.|
|Boolean||Varies by platform.||True (1) or False (0). It is used to store data whose values can only be true/false.|
|Long||8 byte||-9, 223, 372, 036, 854, 775, 808, up to 9, 223, 372, 036, 854, 775, 807. It is used to store numeric data. Long data is stored as a 64-bit number.|
|Short||2 byte||From -32,768 to 32,767. It is used to store a small range of numeric data. Short data is used to store signed 16-bit numbers.|
|UShort||2 byte||From 0 to 65,535. It is used to store small ranges of unsigned numeric data.|
|SByte||1 byte||– From 128 to 127. It is used to store signed integer data.|
|String||Varies by platform.||From 0 to 20 crore Unicode characters. It is used to store alpha numeric data.|
|UInteger||4 byte||From 0 to 4,294,967,295. It is used to store unsigned integer data.|
|ulog||8 byte||From 0 to 18,446,744,073,709,551,615 (1.8…E+19 ). It is used to store very large unsigned integer data.|
|Single||4 byte||-3.402823E + 38 to 1.401298E 45 (negative numbers) 1.401298E 45 to 3.402823E38 (positive numbers). It is used to store single precision floating point values.|
|Double||8 byte||-1.79769313486231E+ to 4.94065645841247E-324 (negative numbers) and 4.94065645841247E-324 1.79769313486232E308 (negative numbers). It is used to store large floating point numbers.|
Expresses E10 to the power in scientific notation. So 1.10E+2 would mean 1.10×102 or 110 and 1.10E-2 would mean 1.10/102 or 0.0110.
Question: Currency Day (Currency) is V.B. Available in dot net? If not then how can we convert currency into VB? Will store in dot net.
Answer: B.B. Currency data type in dot net VB. Not available as of 6. In this, you use the Decimal data type to assign the currency.
Identifier Type Character – V.B. Identifier Type Character – A unique way to declare data types in VB.Net
VB Dot Net has a unique way of declaring data types. This is called an identifier type character. Let’s say you are in a hurry and want a little less typing in programming, then this method can be useful. However, the method can also be confusing to you. Because which symbol represents which data type has to be remembered. Second, this method is only for certain data types. Shows the symbol representing the data type in the table.
for example you
Dim a As Integer
Just writing will be enough.
Dim EmpName As String
instead of only
And what if you want to declare two string variables at the same time? Don’t panic For this, you have to write that symbol in two ways like this-
Dim EmpFirstName$, EmpLastName$
There is no identifier type character instead of Boolean, Byte, Char, Date, Object, SByte, Short, UInteger, and ULong. You can also use identifier-type characters with functions. For example, by adding $ to the add function, you can get its value in the string.
What are Pascal and Camel Casings?
According to Microsoft design rules, it is customary to write field names in Camel casing and property names in Pascal casing. The first character of each word in the identifier is capitalized in Pascal case and the first character of each word is lowercase in Camel case. EmpName is an example of Pascal casing and empName is of Camel casing.
As a general rule, Pascal casing can be used anywhere except parameters and private or protected fields and Camel casing is used only for parameters and private or protected fields. That’s why when we write field, it is a pointer to the field while Field indicates the property.
Forcing Variable Declaration
The OPTION EXPLICIT statement specifies whether the compiler requires all variables to be explicitly declared before they can be used in the program. OPTION EXPLICIT has two modes ON or OFF. If OPTION EXPLICIT is in ON mode, you must declare the variables before using them in the program. If you don’t do this, compile time error for the undeclared variable will appear.
If OPTION EXPLICIT is OFF then VB.NET automatically creates the variable if the variable is undeclared. By default OPTION EXPLICIT is on. By setting OPTION EXPLICIT to ON mode, you can reduce the potential for errors that result from misspellings in variable names. Because if OPTION EXPLICIT is in ON mode then you have to declare each variable in the program to store the data.
For example, see the following program –
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, –
ByVal e As System. EventArgs) Handles Button1.Click
Dim str As String
str = “Option Explicit ON”
The above program declares a string variable, assigns a value to it, and displays it. Now if you want VB.NET to create the variable without declaring the variable, then you have to use OPTION EXPLICIT OFF. This is called preemptive variable declaration. For example see the following program –
OPTION EXPLICIT OFF
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,_
ByVal e As System. EventArgs) HandlesButton1. click
Dim str As String
str = “Option Explicit ON”
You will not get any error when you run this program. But as soon as you remove OPTION EXPLICIT OFF from it, the error will appear.
Scope of a Variable
Scope is an attribute of a programming language that designs the accessibility of variables within the program. This means that the scope determines which variables are accessible to which parts of the program. A variable may be limited to a block, a variable may be accessible by a procedure, a variable may be available to the entire module and a project. Variable scope totally depends on your requirement.
Let’s say you are declaring a variable whose requirement is limited to a particular block. A block is the smallest part of a program. If we make that variable accessible outside the block, then naturally the program will get an error.
Like see this block-
If A < B Then
Dim message As String
Message = “B is greater than A”.
TextBox1. Text = Message
The relevance of the variable named message which has been declared in the above program is IF…..END. Terminated in the IF block itself. Such scopes are generally used only with control flow statements. Further in the block, if you want the accessibility of the variable, then you can define the accessibility of the variable for the entire procedure.
A procedure is a part of a larger program which is also called a sub-program and completes a task. For example, to complete a print job within a larger project (a complete program). For example, see this program-
Private Sub btncompute_Click(…) Handles btncompute. click
Dim X, Y As Double
X = CDbl(txtFirstName.Text)
Y = CDbl(txtSecondNum Text)
The above program is an event handler program or a procedure inside which there are two variables X and Y. The accessibility of both of these is limited to inside this procedure only.
In VB.NET the variable can be declared outside the procedure also so that the variable can be available to more than one procedure. If you want to do this, you can use two other keywords Public and Private.
Public variable is available throughout the application. These are global variables, which are linked throughout the application. It is good to use variables sparingly. But they are useful when you need some value that will be used in many places in the program, such as in conjunction with a database or file. The use of a private keyword in the declaration statement makes it clear that its elements are accessible only inside the module, class or structure.
You can use private only at the module level. This means that you can declare private variables only inside a module, class, or struct and not at the source file or namespace level, in an interface, or inside a procedure. If you do not use any access specifier at the module level then it means private by default. But it is good if you use private. This makes the code easier to understand.
With the help of scope, we separate the data which is used by the process of our application. Very early versions of BASIC did not have the capability for scopes. And all variables could be changed as well as accessed from all parts of the program. The downside of this was that you could always make a mistake in typing the value, which would lead to an error.
Lifetime of a Variable
The lifetime of variables is the time during which they are available. For this purpose, the compiler treats procedure, parameter, and function returns as special cases of variables. The lifetime of a variable expresses the period of time during which it holds a value. Its values change throughout the lifetime but there is always some value in it.
A member variable (declared at the module level outside a procedure) has the same lifetime as the component in which it is declared. A non-shared variable declared in a class or structure exists as a separate copy for each instance of the class or structure in which it is declared. Each variable of this type has the same lifetime as its instance. But the shared variable has only one lifetime, which lasts for the whole time.
Constants are similar to variables but the value of the constant does not change during the execution of the program. That’s why they are called achar (non-changing) in Hindi. VB In dot net we declare the constant with const keyword. For example, look at the following coding-
Const Pi = 3.14159
Dim Radius, Area As Single
Radius = 1
Area = Pi*Radius*Radius
WriteLine(“Area = “&Str(Area))
In the above coding, a constant named Pi has been created along with two variables Radius and Area. This means that the value of Pi will not change in any case.
Constant and enumeration are somewhat related. Supposing you have to define a lot of eg fifty-hundred constants in a program and you want to break them down into smaller function groups, wouldn’t you wish that V.B. Is there any such feature in dot net which can remedy this? VB Dot net has an enumeration feature for this. Enumeration is a named constant. You can also call it the value set of a constant.
These are values that are unique throughout the program and these values can be globally identified. These constants give meaningful names to numerical values.
Enumeration is usually used to collect all possible sets of values for a particular variable. Each enumeration is given a unique name with which it is accessed. This is an option that you use to remember a set of values that can be used anywhere in the program. The Enum keyword is used to create an enumeration. Enumeration is a value data type. Every enumeration has an underlying numeric base data type, which is numeric. The syntax of enumeration is as follows-
<member1>> = [value]
<member2> = [value]
For example, for the names of the months, you can create an enumeration like this:
In the above coding, the name of the enumeration is Months. However, for enumeration member, we have not assigned any numerical value to it. In case of not assigning a value, VB.net by default starts assigning the value from 0. That is, the value of January will start from 0 and the value of December will be up to 11. We can also write this coding like this-
January = 5
February = 10
March = 15
April = 20
May = 25
June = 30
July = 35
August = 40
September = 45
October = 50
November = 55
December = 60
With this we can also give random values. See this coding to understand it-
March = 5
Now we will see how its numerical value will be. According to the above coding, the name of January will be 0 and the value of February will be 1 by default. And the value of March will be 5, April, May, July, August, September, October, November and December will be 6, 7, 8, 9, 10, 11, 12, 13 and 14 respectively.
Let’s Learn – Write a console program that shows how to use enumeration at the class, number, procedure, or block level.
Click on the File menu and select New Project.
After the New Project dialog box opens, click Console Application in the Templates pane.
Type Lab Exercise 4.1 in the Name textbox and click OK. After that the code editor will open. then type the following code
Module Module 1
Public Enum Months
Dim number As Integer
Dim int Input As Integer
Public Function GetMonth() As Months
System.Console.WriteLine(“Enter an Integer…”)
intInput = Val (System. Console. ReadLine ( ) )
If intInput < 4 Then
System.Console.WriteLine(“This is winter in India.”)
ElseIf intInput < 9 Then
System.Console.WriteLine(“This is Summer in India.”)
ElseIf intInput < 12 Then
System.Console.WriteLine(“This is autumn in India.”)
System.Console.WriteLine(“No Known Number.”)
Sub Main ( )
Press F5 and see the result.