Table of Contents
What Is A Programming Language In Computers? | What Is A Computer Programming Language? | What Is A Programming Language And Its Types | Computer Programming Languages Part-2
Computer Programming Languages Part-2 – In any natural language or colloquial language, there is 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.
Arrays
You must have read about variables earlier. A variable is a name to assign a value. Thus-
Dim Student As String
A variable named Student is assumed in the program, which is of type String. Now suppose that you have to extract the mark sheet of different classes of a school. There are 50 students in a class, which can be used according to the variable in only one way and that is-
Dim Student1 As String
Dim Student2 As String
Dim Student3 As String
Dim Student4 As String
Dim Student5 As String
Now understand that if the number remains large, then what trouble can come. How painful it can be to process 50 students on different variables and different variables separately. So is there any way to declare the variables of 50 students only once? Yes there is a solution! The array can be done like this-
Dim Student(50) As String
The above statement is array declaration statement. So what is an array? The definition of array is- Array is such a data structure, which is a collection of variables of the same type of data. That is, more than one value of the same type can be contained in the array. It can also be called a set of integer, double, or string variables. An array has the same name even if it contains more than one value. Their values are accessed by their index value. VB Array index in dot net starts from 0.
Computer Programming Languages Part-2 | Programming Language And Its Types

Facts related to Array:
The array is a data structure, which is a collection of more than one variable of the same type.
The array has only one name.
The counting of the elements of the array starts from 0. That is, the first variable of array collection will be Variable (0) and not Array Variable (1).
The numbers inside the brackets of each variable are called subscripts.
Each variable of the array is called a subscripted variable.
We rarely use Student(0). We refer to this collection of variables as the array variable Student(0). The number inside the brackets of each individual variable is called the subscript. And each variable (or each element of the array) is called a subscripted variable or element. For example, Student(3) is the third subscripted variable of the array Student ). The elements of the array also get a place in the memory according to their order.
If arrayName is the name of the array and n is an integer literal, variable or expression, then the declaration statement –
Dim arrayName(n) As VarType
array Name (0), array Name (1), array Name (2), arrayName (n) Reserves space in memory to hold the values of the subscripted variables. The value of n is called the upper bound of the array. The lower bound of an array is always 0. The number of elements in the array n+1 is the size of the array.
Values can be assigned to individual subscripted variables with the assignment statement and displayed in text boxes and list boxes just like the values of ordinary variables. You learned about an array and that an array is a collection of variables of the same data. But what if such a situation comes that you want to store variables of different types of data from the array? The remedy for this too is VB. in dot net. You can do this by declaring the data type Object. Thus-
Dim Student As object
Types of Array
Arrays can be mainly of four types:
- One-dimensional array
- Multi-dimensional array
- Dynamic array
- Jagged array
1- Single Dimensional Array – Till now all the discussion that happened behind was focused on one-dimensional array only. A one-dimensional array is like a table with only one column.
Student (0)
student (1)
student (2)
student (3)
Student (4)
One-dimensional array – The number of items to be stored in the array can be thought of as the number of rows. In a one-dimensional array, you can store information using a single index, for example, the names of students.
Creating Single Dimensional Array and Putting Values on them – To create a one-dimensional array, you give the name, size, and data type of the array. To declare an array, the Dim keyword is used just like a variable declaration. For example, to create an array containing a collection of 50 students, the following statement would be used:
Dim Student (49) String
The above statement will create Student ) array whose data type will be string and its size will be 49. But, in this array we will collect the values of 50 students. Because as mentioned the index will start from 0. Now to assign the element value of the array let’s define the index location with that value. Thus-
Student(0) = “Rama”
Student(1) = “John”
Student(2) = “Alisha”
Now we can access an element anytime by giving reference to that index. You can do it like this-
TextBox1.
Text = Student ( 1 )
The above statement will display the value of Student (1) in the text box.
2- Multi-Dimensional Array – The dimension of the array mainly depends on its index. The number inside the brackets of the index array is called. Arrays with one index are one-dimensional, similarly arrays with more than one index are called multi-dimensional arrays. A multidimensional array is like a table with two or more columns.
Normally when we talk about multi-dimensional array we are talking about two-dimensional array. Each of its columns represents a feature of the element. Each element of a multidimensional array has two indexes associated with it. where one index represents the row of the array and the other index represents the column of the array.
(0,0) (0,1) (0,2) (0,3) (0,4)
(1,0) (1,1) (1,2) (1,3) (1,4)
(2,0) (2,1) (2,2) (2,3) (2,4)
(3,0) (3,1) (3,2) (3,3) (3,4)
Its format is as follows-
Dim 2DArray(rows, columns) As DataType
Similarly you can create a 3D array with this format-
Dim 3DArray(X, Y, Z) As DataType
With the use of multi-dimensional arrays, each array element occupies space in memory to hold the data, whether the data is null or the empty string. As a result, multi-dimensional arrays take up space in memory without even being useful. Hence it is suggested to use multi-dimensional arrays judiciously.
3- Jagged Arrays – VB Dot Net also provides an array whose every element is an array. This array is called Zgood array or Array of arrays. Jagged array can be one-dimensional or multi-dimensional and its elements can also be one-dimensional or multi-dimensional.
Note: Having an array as an element is not the same thing as a multidimensional array. In multidimensional there is more than one index on the same array.
Sometimes the data structures in your application are two-dimensional, but not rectangular. For example, you can have a months array whose each element is an array of days. Since different months may have different number of days, the elements do not form a rectangular two-dimensional array.
In this case, you use a Zgood array instead of a multidimensional array. The following example declares an array to hold a zand array of elements with double data type. Sales ) array is itself an array, representing the month. each month) array holds the values for each day of that month.
Dim Sales () () As Double = New Double (11) ) {}
Dim month As Integer
Dim days As Integer
For month = 0 to 11
days = DateTime. DaysInMonth (Year (Now), month + 1)
Sales (month) = New Double (days –1) {}
next month
The New clause in the declaration of Sales sets the array to be a 12 element array. Each element of which is of type Double. In the For loop (Year (Now)) determines how many days each month has and sets the incoming element of Sales into a Double array of the appropriate size. In this example, the zagged array saves seven elements (6 in leap years) compared to a two-dimensional array. In complex cases this can save even more memory.
4- Dynamic Array – When you create an array, you initialize it. You initialize the array using the index number. In some arrays, the number of elements is not known at the time of its construction. When this happens we can specify the size of the array later. Such array is called dynamic array. For example an array named DynArray whose size is not known at the time of creation. Thus-
Dim dynArray() As Integer
Whose size we set later through ReDim command. Thus-
ReDim dynArray(n) As Integer
where n is the size of dynArray.
Control Array
We’ve seen several examples of the usefulness of arrays or subscripted variables. It is essential for writing concise solutions to many programming problems. Because of the utility provided by subscripted variables, V.B. Dot net also provides arrays for labels, textboxes and buttons. Since Label, Textbox and Button are V.B. Controls are commonly understood in dot net, the array of these objects is called control array.
The control array is also created in the same way as we create other arrays. Thus-
Dim arrayName(n) As ControlType
Or,
Dim arrayName() As ControlType
For example, the following three statements create a control array of Label, Textbox and Button respectively-
Dim lblTitle(10) As Label
Dim txtNumber(8) As TextBox
Dim btrArront() As Button
The subscript/index is not given in the last statement.
Structures
You have already worked with data types like Double, Integer, String and Boolean. Structure is such a data type that helps you to keep different types of variables as units. In other programming languages, we know it as User Defined Type. For example, Name, Capital, Population, NumberOfStates and PerCapitaIncome are four pieces of information related to the Country. In Structure Type in India, we can consider these four pieces of information as follows-
Structure Country
Dim Name As String
Dim Capital As String
Dim Population As Integer
Dim NumberOfStates As Integer
Dim PerCapitaIncome As Double
end structure
Four sub-variables of the struct type Country are members of this type. Country type structure variable can be declared by the statement in this way-
Dim Country1 As Country
Each member can be accessed by giving the name of the structure variable and the member and a period (.) between them. For example, the five members of the Country1 structure variable can be accessed by Country1. Name, Country1.Capital, Country1.Population, Country 1.NumberOfStates and Country 1.PerCapitaIncome. In general, a structure type is defined by a structure block of the form. Thus-
Structure Structure Type
Dim MemberName1 As MemberType1
Dim MemberName2 As MemberType2
end structure
Where StructureType is the name of a user defined data type. MemberName1, MemberName2 are the names of the members of the structure. And MemberType1, MemberType2 are their respective data types.
Subroutine
When you double click a button on the form, its Click event is displayed when the code editor opens, which starts and ends like this-
Private Sub…..
end sub
Here Sub is actually the short form of subroutine. This means that this routine is executed every time you click the button. You can also create this type of subroutine yourself. By doing this, other code in your application can call that subroutine when needed.
The advantage of subroutine is that to complete the work for which you have created the subroutine, you can call it anywhere in the application using the Call keyword, although the use of the Call keyword is optional. Just the name of the subroutine will also work.
Function
VB Dot Net already has many functions which can be seen in Appendix A. Functions are actually small programs. They take inputs, process them and return outputs to you. VB Apart from using the pre-built functions in dot net, we can also define our own functions. These functions are called function programs or user defined functions. They are defined in the same way as we define subroutines. And they are used in the same way as pre-built functions. Function procedures can be used in expressions in the same way as in VB.NET. Dot net’s basic functions are used
Is. The program refers to these functions as literals, variables or expressions. This is the method of creating a function-
Function FunctionName (By Val Var1 As Type1, By Val Var2 As Type2) As DataType
Statement(s)
return expression
end function
Variables appearing on the first line are called parameters. Variables declared by statements inside a function block are accessible only within that block. There is no limit to the name of the function, but it is good that its name should indicate the work it does. All the rules for naming it are the same as for naming a variable. DataType specifies the type of the output, which can be String, Integer, Double, etc. like subroutine or sub procedure
Function procedures are also written in the code window itself. Variables passed to the function are passed by value. But it can also be passed by reference. When these variables are passed by reference, their value can also be changed. Here we are defining two functions FtoC and FirstName.
Function FtoC (ByVal t As Double) As Double
Return (5/9) * (t-32) // Converts Fahrenheit to Celsius.
end function
This function converts Fahrenheit to Celsius. The FirstName function separates only the first part of the name from the full name.
Function FirstName (ByVal Name As String) As String
Dim FirstSpace As String
FirstSpace = name.Index Of (” “)
Return name. Substring(0, FirstSpace) End function
What Did You Learn Today
- Any natural language or colloquial language has a special grammar in addition to letters, words, phrases, sentences. Grammar teaches us to speak the language properly and write its script. In the same way, 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.
- 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 give it a name in the form of a variable.
- Variables store values during the execution of the program. Runtime (implementation) variables are used to store data temporarily in Visual Basic.Net.
- A variable has a specific name and its data is of a specific type. The name of a variable is used to access and manipulate the value of the variable.
- 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.
- 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.
- The name of the variable is not unnecessarily long.
- Name of the variable V.B. Dot net should not have any reserved words ie keywords.
- The essence of the variable naming rule 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. To declare the variable in Visual Basic Dot Net, the Dlm keyword is used.
- In order to manage memory as well as to make it easier to debug the program, it is necessary that you declare the rel data type with care.
- In scientific notation, B represents the power of 10. So 1.10B+2 means 1.10 X 102 or 110 and 1.10E-2 means 1.10 / 102 or 0.0110.
- B.B. Currency data type BB in dot net. Not available as of 6. In this you use the Decimal die to assign the currency.
- V.B. Dot Net has a unique way of declaring data types. This is called the identifier m character.
- 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.
- The OPTION EXPLICIT statement ensures that the compiler explicitly declares all variables
- Need to declare before use in the program or not.
- 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.
- By default option EXPLICIT is on. By setting OPTION EXPLICIT to ON mode, you can reduce the potential for error that results from a mistake in the name of a variable.
- Scope is that attribute of a programming language, which designs the accessibility of variables inside the program. This means that the scope determines which variables are accessible to which parts of the program.
- Public variable is available throughout the application. These are global variables, which are linked throughout the application.
- Use of private keyword in the declaration statement makes it clear that its elements are accessible only inside the module class or structure.
- 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.
- Constants are similar to variables but the value of the constant does not change during the execution of the program.
- Enumeration is generally used to collect all the possible set of values for a particular variable. Each enumeration is given a unique name with which it is accessed.
- Array is such a data structure, which is a collection of variables of the same type of data. That is, more than one value of the same type can be contained in the array. It can also be called a set of integer, double, string variables.
- Individual subscript variables can be assigned values with an assignment statement and displayed in a list box just like the values of ordinary variables.
- is actually the short form of subroutine. This means that whenever you click the button. This sptine executes. You can also create this type of subroutine yourself. By doing this, other code in your application can call that subroutine when needed.
- The most important thing about substein is that you don’t have to write the same code again and again. You create a subroutine once for a specific task and call it whenever you want in the application.
- V.B. Apart from using the pre-built functions in dot net, we can also define our own functions. Those functions are called function programs or user defined functions.