Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please complete in visual basic .net Provide sample code for one of the followin

ID: 3756706 • Letter: P

Question

please complete in visual basic .net

Provide sample code for one of the following items. When possible, choose an item that has not yet been selected:


Provide an example of an infinite loop (a loop that never ends).


Provide an example of a For/Next loop that steps through a list of items in a Combobox, displays the text of each item in a messagebox and deletes the item from the Combobox.


Provide an example of a Do/While or Do/Until loop identical to the For/Next loop above.


Write a subroutine that will take a string argument and print the string centered on the page. (This one is a challenge.)


Declare a two-dimensional array to hold the first and last names of each person in the class, and initialize it to 3 students in the class.


Declare a structure that will hold a last name and a first name. Declare a one-dimensional array to hold the structure, and initialize it to 3 students in the class.


Write a loop that will search for a string value in an array.


Declare an array that holds a list of names, and write a For/Each loop to display each name in the array in a messagebox.


Note: You will not be marked down for errors in your code posted here. Errors in your code will, in fact, generate good discussion that will help the class learn the topic at hand.


Explanation / Answer

According to the question, sample code is required for one of them. But for your better understanding I will give sample code for others too:

1. An example of an Infinite Loop:

For i as Integer = 0 To 1 Step 0

Explanation: Loop starts with i=0 and it will end at i=1. The increment is of 0. So, the loop will never end thus Infinite Loop.

2. Provide an example of a For/Next loop that steps through a list of items in a Combobox, displays the text of each item in a messagebox and deletes the item from the Combobox.

***Note: We have taken array here in place of Combox Item because we can simply bind our array with ComboBox and show all item there.

This is a list that the ComboBox contain

Dim cmbBox As Array = {"Vegflakes", "Wheet", "Chicken"}

For x = 0 To cmbBox.Length - 1 'a loop that will repeat for the length of the ComboBox

MessageBox.Show(cmbBox(x))

cmbBox.Remove x ' Remove an item

End If

Next

3. Provide an example of a Do/While or Do/Until loop identical to the For/Next loop above.

Dim cmbBox As Array = {"Vegflakes", "Wheet", "Chicken"}

Dim x As Integer = 0

Do While x = cmbBox.Length - 1

MessageBox.Show(cmbBox(x))

cmbBox.Remove x ' Remove an item

x += 1

}

Loop

4. Write a subroutine that will take a string argument and print the string centered on the page.

Sub printCenter(text1 task As String)

using (Font font1 = new Font("Arial", 12, FontStyle.Bold, GraphicsUnit.Point))

{

Rectangle rect1 = new Rectangle(10, 10, 130, 140);

// Create a StringFormat object with the each line of text, and the block

// of text centered on the page.

StringFormat stringFormat = new StringFormat();

stringFormat.Alignment = StringAlignment.Center;

stringFormat.LineAlignment = StringAlignment.Center;

// Draw the text and the surrounding rectangle.

e.Graphics.DrawString(text1, font1, Brushes.Blue, rect1, stringFormat);

e.Graphics.DrawRectangle(Pens.Black, rect1);

}

End Sub

5. Declare a two-dimensional array to hold the first and last names of each person in the class, and initialize it to 3 students in the class.

Dim strData(,) As String 'Use String variable type, even for the numbers

Dim intRowCount As Integer = 2

Dim intColumnCount As Integer = 3

ReDim strData(intColumnCount - 1, intRowCount – 1

'first row

strData(0, 0) = "Barry" 'Range start

strData(0, 1) = "Allen" 'Range end

'second row

strData(1, 0) = "Bruce"

strData(1, 1) = "Wayne"

'third row

strData(0, 2) = "Oliver"

strData(2, 0) = "Queen"

6. Declare a structure that will hold a last name and a first name. Declare a one-dimensional array to hold the structure, and initialize it to 3 students in the class.

***Structure Declaration

Structure Name

Public LastName As String

Public FirstName As String

End Structure

***Array of Structure Type

Public allStudents(3) As Name = New Name() { _

{New Name("Barry", "Allen"), New Name("Bruce","Wayne"), New Name("Oliver","Queen")}

7. Write a loop that will search for a string value in an array.

*** Here I will search "ghi"

Dim lst As New List(Of String) _

From {"abc", "def", "ghi"}

Dim flag Integer = 0

' Iterate through the list.

For Each item As String In lst

IF(item == "ghi")

MessageBox.Show("String Found")

flag = 1

Next

If (flag == 0)

MessageBox.Show("String Not Found")

8. Declare an array that holds a list of names, and write a For/Each loop to display each name in the array in a messagebox.

Dim Names As Array = {"Barry Allen", "Bruce Wayne", "Oliver Queen"}

For Each item As String In Name

MessageBox.Show(item)

Next

That's it, Happy Coding!