1 / 32

VB.Net Programming Console Application

VB.Net Programming Console Application. Walkthrough Example : Array (one Dimension). Narrative. Memory. The first line of the program indicates the main( ) procedure. Screen. Code. Sub Main() Dim myArray(4) As Integer Dim Count As Integer 'get data into array For Count = 0 To 4

Download Presentation

VB.Net Programming Console Application

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. VB.Net ProgrammingConsole Application Walkthrough Example : Array (one Dimension)

  2. Narrative Memory The first line of the program indicates the main( ) procedure. Screen Code Sub Main() Dim myArray(4) As Integer Dim Count As Integer 'get data into array For Count = 0 To 4 Console.Write("Enter myArray({0}) :", Count) myarray(Count) = Console.ReadLine() Next 'Print myArray to screen Console.WriteLine(“Show contents of myArray") For Count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", Count, myarray(Count)) Next Console.ReadKey() End Sub

  3. Narrative Memory This DIM statement creates a one dimension array called myArray with 5 elements ( numbered 0 to 4) Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub 0 1 2 3 4 myArray

  4. Narrative Memory 0 1 2 3 4 This DIM statement creates a variable called Count to store an integer value. myArray Count Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub

  5. Narrative Memory 0 1 2 3 4 This line is a comment and is used by the programmer to explain what is happening in the program. myArray Count Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub

  6. Narrative Memory 0 1 2 3 4 This is a For…….Next loop The statements within it will run once for each value of Count. Count starts with a value of 0 and the loop loops until Count reaches 4 myArray Count 0 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub

  7. Narrative Memory 0 1 2 3 4 This is a For…….Next loop This statements writes the the text in quotes to the console screen. The 0 in the curly brackets is replaced by the value of in the Count memory variable. myArray Count 0 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :

  8. Narrative Memory 0 1 2 3 4 This is a For…….Next loop This statements reads the input from the keyboard into the myArray element using Count to identify which element to use. in this case count is 0 so element 0 store the user input 12. myArray 12 Count 0 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12

  9. Narrative Memory 0 1 2 3 4 Second time around the loop Count has been incremented to 1. This statements writes the text in quotes to the console screen. The 0 in the curly brackets is replaced by the value of in the Count memory variable. myArray 12 Count 1 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) :

  10. Narrative Memory 0 1 2 3 4 Second time around the loop Count has been incremented to 1. This statements reads the user input from the keyboard, say 23, and puts it into myArray(count) I.e. myArray(1). myArray 12 23 Count 1 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23

  11. Narrative Memory 0 1 2 3 4 Third time around the loop Count has been incremented to 2. The text in quotes is written to the screen. The curly brackets are replaced by the value of count. myArray 12 23 Count 2 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23 Enter myArray(2) :

  12. Narrative Memory 0 1 2 3 4 Third time around the loop Count has been incremented to 2. This statement reads the input from the keyboard, say 34, and puts it into myArray using count as the element number, i.e. myArray(2) = 34 myArray 12 23 34 Count 2 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23 Enter myArray(2) : 34

  13. Narrative Memory 0 1 2 3 4 Fourth time around the loop Count has been incremented to 3. The text in quotes is written to the screen. The curly brackets are replaced by the value of count. myArray 12 23 34 Count 3 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23 Enter myArray(2) : 34 Enter myArray(3) :

  14. Narrative Memory 0 1 2 3 4 Fourth time around the loop Count has been incremented to 3. This statement reads the input from the keyboard, say 45, and puts it into myArray using count as the element number, i.e. myArray(3) = 45 myArray 12 23 34 45 Count 3 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23 Enter myArray(2) : 34 Enter myArray(3) : 45

  15. Narrative Memory 0 1 2 3 4 Fifth time around the loop Count has been incremented to 4. The text in quotes is written to the screen. The curly brackets are replaced by the value of count. myArray 12 23 34 45 Count 4 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23 Enter myArray(2) : 34 Enter myArray(3) : 45 Enter myArray(4) :

  16. Narrative Memory 0 1 2 3 4 Fifth time around the loop Count has been incremented to 4. This statement reads the input from the keyboard, say 56, and puts it into myArray using count as the element number, i.e. myArray(4) = 56 myArray 12 23 34 45 56 Count 4 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23 Enter myArray(2) : 34 Enter myArray(3) : 45 Enter myArray(4) :56

  17. Narrative Memory 0 1 2 3 4 The loop has finished and the array has the data entered by the user stored in its elements. This statement is a comment stating that the next section will print the array conents to the screen. myArray 12 23 34 45 56 Count 4 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23 Enter myArray(2) : 34 Enter myArray(3) : 45 Enter myArray(4) :56

  18. Narrative Memory 0 1 2 3 4 This statement writes the text in quotes to the screen. myArray 12 23 34 45 56 Count 4 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23 Enter myArray(2) : 34 Enter myArray(3) : 45 Enter myArray(4) :56 Show the contents of myArray

  19. Narrative Memory 0 1 2 3 4 This for loop is used to write the contents of the array to the screen. The count is set to 0. (again) myArray 12 23 34 45 56 Count 0 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23 Enter myArray(2) : 34 Enter myArray(3) : 45 Enter myArray(4) :56 Show the contents of myArray

  20. Narrative Memory 0 1 2 3 4 This statement will write the text in quotes to the screen. The curly brackets { } indicate a value from outside the quotes is to be used. 0 is the first value count & 1 is the second value myArray( ). myArray 12 23 34 45 56 Count 0 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23 Enter myArray(2) : 34 Enter myArray(3) : 45 Enter myArray(4) :56 Show the contents of myArray myArray(0) is…12

  21. Narrative Memory 0 1 2 3 4 This this is the end of the first loop. The value of count has not reached its end value so the loop will go round again. myArray 12 23 34 45 56 Count 0 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23 Enter myArray(2) : 34 Enter myArray(3) : 45 Enter myArray(4) :56 Show the contents of myArray myArray(0) is…12

  22. Narrative Memory 0 1 2 3 4 The second time round the loop The count is increased by 1 myArray 12 23 34 45 56 Count 1 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23 Enter myArray(2) : 34 Enter myArray(3) : 45 Enter myArray(4) :56 Show the contents of myArray myArray(0) is…12

  23. Narrative Memory 0 1 2 3 4 This statement will write the text in quotes to the screen. The curly brackets { } indicate a value from outside the quotes is to be used. 0 is the first value count & 1 is the second value myArray( ). myArray 12 23 34 45 56 Count 1 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23 Enter myArray(2) : 34 Enter myArray(3) : 45 Enter myArray(4) :56 Show the contents of myArray myArray(0) is…12 myArray(1) is…23

  24. Narrative Memory 0 1 2 3 4 This this is the end of the first loop. The value of count has not reached its end value so the loop will go round again. myArray 12 23 34 45 56 Count 1 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23 Enter myArray(2) : 34 Enter myArray(3) : 45 Enter myArray(4) :56 Show the contents of myArray myArray(0) is…12 myArray(1) is…23

  25. Narrative Memory 0 1 2 3 4 The third time round the loop The count is increased by 1 myArray 12 23 34 45 56 Count 2 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23 Enter myArray(2) : 34 Enter myArray(3) : 45 Enter myArray(4) :56 Show the contents of myArray myArray(0) is…12 myArray(1) is…23

  26. Narrative Memory 0 1 2 3 4 This statement will write the text in quotes to the screen. The curly brackets { } indicate a value from outside the quotes is to be used. 0 is the first value count & 1 is the second value myArray( ). myArray 12 23 34 45 56 Count 2 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23 Enter myArray(2) : 34 Enter myArray(3) : 45 Enter myArray(4) :56 Show the contents of myArray myArray(0) is…12 myArray(1) is…23 myArray(2) is…34

  27. Narrative Memory 0 1 2 3 4 The fourth time round the loop The count is increased by 1 myArray 12 23 34 45 56 Count 3 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23 Enter myArray(2) : 34 Enter myArray(3) : 45 Enter myArray(4) :56 Show the contents of myArray myArray(0) is…12 myArray(1) is…23 myArray(2) is…34

  28. Narrative Memory 0 1 2 3 4 This statement will write the text in quotes to the screen. The curly brackets { } indicate a value from outside the quotes is to be used. 0 is the first value count & 1 is the second value myArray( ). myArray 12 23 34 45 56 Count 3 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23 Enter myArray(2) : 34 Enter myArray(3) : 45 Enter myArray(4) :56 Show the contents of myArray myArray(0) is…12 myArray(1) is…23 myArray(2) is…34 myArray(3) is…45

  29. Narrative Memory 0 1 2 3 4 The fifth time round the loop The count is increased by 1 myArray 12 23 34 45 56 Count 4 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23 Enter myArray(2) : 34 Enter myArray(3) : 45 Enter myArray(4) :56 Show the contents of myArray myArray(0) is…12 myArray(1) is…23 myArray(2) is…34 myArray(3) is…45

  30. Narrative Memory 0 1 2 3 4 This statement will write the text in quotes to the screen. The curly brackets { } indicate a value from outside the quotes is to be used. 0 is the first value count & 1 is the second value myArray( ). myArray 12 23 34 45 56 Count 4 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23 Enter myArray(2) : 34 Enter myArray(3) : 45 Enter myArray(4) :56 Show the contents of myArray myArray(0) is…12 myArray(1) is…23 myArray(2) is…34 myArray(3) is…45 myArray(4) is…56

  31. Narrative Memory 0 1 2 3 4 Now that the count has reached its end value of 4 the loop will end. myArray 12 23 34 45 56 Count 4 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23 Enter myArray(2) : 34 Enter myArray(3) : 45 Enter myArray(4) :56 Show the contents of myArray myArray(0) is…12 myArray(1) is…23 myArray(2) is…34 myArray(3) is…45 myArray(4) is…56

  32. Narrative Memory 0 1 2 3 4 This statement waits for a key press. It keeps the screen visible. When a key is pressed the program ends with the End Sub command. myArray 12 23 34 45 56 Count 4 Screen Code Sub Main() Dim myArray(4) As Integer Dim count As Integer 'get data into array For count = 0 To 4 Console.Write("Enter myArray({0}) :", count) myarray(count) = Console.ReadLine() Next 'Print myarray to screen Console.WriteLine(“Show contents of myArray") For count = 0 To 4 Console.WriteLine("myArray({0}) is...{1}", count, myarray(count)) Next Console.ReadKey() End Sub Enter myArray(0) :12 Enter myArray(1) : 23 Enter myArray(2) : 34 Enter myArray(3) : 45 Enter myArray(4) :56 Show the contents of myArray myArray(0) is…12 myArray(1) is…23 myArray(2) is…34 myArray(3) is…45 myArray(4) is…56

More Related