Documents

vb.net-ii

Description
vb.net-ii
Categories
Published
of 6
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Related Documents
Share
Transcript
  ArguS academy  V.B PART 2 Page 1   Looping Constructs A loop construct is used whenever a statement or group of statements have to be executed a number of time. VB.NET supports the following type of loops: While …..end  while Do….loop   For…. Next   For Each….next   While..End While Loop The control first checks for the condition and as long as the condition is true, the statements enclosed within the While….En d While block is executed. Each time before it before it executes the statements, the condition is tested. If the condition evaluates to False before the control enters the loop, the loop statements will not be executed even once. E.g. Module mloop Sub main() Dim i as integer i=1 While i<=10 System.Console.WriteLine(i) i=i+1 End while End sub End module Do….loop   Do loop construct is similar to the while …end while construct. If the condition evaluates to True, then the loop statements  are executed until the condition becomes False. The Do keyword may be followed by a while or until keyword along with a condition expression but this is not mandatory. If however there is no while or until keyword included after the do, then the loop Module mloop2 Sub main() Dim a as integer Dim b as integer Dim c as integer Dim n as integer a=0 b=1 n=3 System.Console.Write(a&” “)   System.Console.Write(b&” “)  Do c=a+b System.Controle.WriteLine(c&” ”)  a=b b=c n=n+1 loop while<=10 end sub end module Fool….Next loop   This loop construct is usually used when the limit of the loop is known for certain. A for… next statement specifies a lower limit, a higher limit, and an optional step value. Module mloop3 Sub main() Dim i as integer For i=1 to 10 System.Console.WriteLine(i) Next i End sub  ArguS academy  V.B PART 2 Page 2   End module For Each….next   Module mloop4 Sub main() Dim i as integer For i=0 to 10 step 2 System.Console.WriteLine(i) Next End sub End module Nested loop It is possible to nest one loop within another in vb.net. the loops may be of the same type or different types. For instance, we can have a for…next loop embedded within another for ….next loop.  Module mloop5 Sub main() Dim i as integer Dim j as integer For i=1 to 5 For j=1 to i System.Console.Write(“*”)  Next j System.Console.Writeline() Next j End sub End module Exit statement The exit statement causes control to be transferred to another section of the program. Module mloop6 Sub main() Dim i as integer i=10 while i<100 System.Console.WriteLine(i) if i mod 7=0 exit while end if i=i+1 end while end sub end module Array An array is an entity that contains multiple variables of the same type. These variables are referred to by a single name. the variables are called as the elements of the array. The elements within an array are stored consecutively one after another. If we need to store the names of 15 students, instead of using 15 variables, we can use an array which can be accessed using a single name. Example 1 Module marr Sub main() Dim values() as Boolean={False,True,True} Dim i as Integer For i=0 to 2 System.Console.WriteLine(values(i)) Next  ArguS academy  V.B PART 2 Page 3   End sub End module Example 2  Module marr1 Sub main() Dim names(5 ) as String Dim i as integer System.Console.WriteLine(“Enter 5 name”)  For i=0 to 5 names(i)=System.Console.ReadLine() next System.Console.WriteLine(“The name entered are - ”)  For i=0 to 5 System.Console.WriteLine( “Name (i) is ”&names(i) ) Next End sub End module Example 3 Module marr2 Sub main() Dim arr(10) as integer Dim i as integer Dim sum as integer sum=0 System.Console.writeLine (“Enter 10 nunber”)  For i=0 to 9 arr(i)=System.Console.ReadLine() next System.Console.WriteLine(“Array Element”)  For i=0 to 9 System.Console.WriteLine(arr(i)) sum=sum+arr(i) Next System.Console.WriteLine(“Sum of all no. ”&sum)  End sub End module Array related functions VB.Net provides a number of functions and keywords that are used with arrays. Module mrra5 Sub main() Dim nums(9) as Single Dim nums2() as Single Dim i as Integer For i=0 to 9 nums(i)=(i+1)/10 next nums2=nums System.Console.writeLine(isArray (nums2)) System.Console.writeLine(ubound (nums2)) System.Console.writeLine(LBound (nums2)) End sub End module Redim keyword Redim cannot be used to change the data type of an array nor can it be used to changed the initialization values of an array. It is only used to change the size of an array.  ArguS academy  V.B PART 2 Page 4   Module marr6 Sub main() Dim nums(10) as integer Dim i as integer Redim nums(5) ‘Array is redeclared with upper bound 5 For i=0 to 5 nums(i)=i next Sy stem.Console.writeLine(“Array elements”)  For i=0 to 5 System.Console.WriteLine(nums(i)) Next End sub End module Multidimensional Arrays We can also create multidimensional arrays in VB.Net. An array can have a maximum of 32 dimensions though we rarely use more than three dimensions. Module mrra9 Sub main() Dim arr(3,3) as integer Dim i as integer Dim j as integer System.Console.w riteLine(“Enter array element”)  For i=0 to 2 For j=0 to 2 arr(i,j)=System.Console.ReadLine() next next System.Console.writeLine(“Array Element”)  For i=0 to 2 For j=0 to 2 System.Console.write(arr(i ,j)&” ”)  Next System.Console.WriteLine() Next End sub End module Procedures and Function Procedures and functions are blocks of code in a program. They are also termed as sub programs and are basically used to avoid repetition of the same code a number of times. By making use of procedures and functions, we save time thereby making development faster. Procedures A VB.NET procedures is written within a sub …End sub block.  Module mf1 Sub main() Dim j as integer System.Console.WriteLine(“Enter any no”)   j=System.Console.ReadLine() square(j) System.Console.WriteLine(“End of Main program”)  End sub Sub square(x as integer) System.Console.WriteLine(x*x) End sub End module Example 2 Module mf2

VB net1

Jul 23, 2017

vb.net-iii

Jul 23, 2017
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks