This is the assignment: Write a VB program that uses an Array of Strings to store state names as read in from the text file StatesBySize.txt.  I will make this file available for your use on our course Sakai web page (Under Resources / Assignments folder).   My suggestion:  On your C-Drive create a folder called VB2012 (its full name would be C:VB2012”.  We will put all data files used for this course into that folder.  If you do this then the call to ReadAllLines will refer to “C:VB2012StatesBySize.txt” This is my code: Public Class Form1 Private Property From As Object Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim States() As String = IO.File.ReadAllLines(“C:VB2012StatesBySize.txt”) For i As Integer = 0 To States.Count – 1 lstbx1.Items.Add(States(i)) Next End Sub Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click Dim txtbx1 As Integer Dim txtbx2 As Integer Dim states() As String = IO.File.ReadAllLines(“C:VB2012StatesBySize.txt”) If Not Integer.TryParse(From.text, txtbx1) Or txtbx1 < 0 Or txtbx1 > 50 Then MessageBox.Show(“Please Input Valid Number For From:”, “Error (Shelina Lewis”) Return End If lstbx1.Items.Clear() For i As Integer = txtbx1 – 1 To txtbx2 – 1 lstbx1.Items.Add(states(i)) Next End Sub

The code provided is an example of a Visual Basic program that reads data from a text file called “StatesBySize.txt” and populates a ListBox control with the state names. The program is written using the WinForms framework.

In the Form1_Load event handler, the program reads all the lines from the text file into an array of strings called “States”. It then iterates over each element in the array using a For loop and adds the state names to the ListBox control using the Add method.

In the btn1_Click event handler, the program reads the lines from the text file again into the “states” array. It then performs some validation on the input value in a TextBox control named “From”. The program checks if the input can be parsed into an integer and if it falls within a specific range. If the validation fails, a message box is displayed and the program returns. Otherwise, the ListBox control is cleared and another For loop is used to add the state names to the ListBox based on the input values stored in TextBox controls named “txtbx1” and “txtbx2”.

This code demonstrates the use of the File.ReadAllLines method to read the contents of a text file and the ListBox.Items.Add method to add items to a ListBox control. It also shows how to perform basic validation on input values using the Integer.TryParse method and how to display a message box using the MessageBox.Show method.

It is important to note that the code assumes that the text file “StatesBySize.txt” exists in the specified location (“C:VB2012”). The file should contain one state name per line.

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.

Click Here to Make an Order Click Here to Hire a Writer