0 Replies - 1345 Views - Last Post: 05 December 2012 - 04:41 PM Rate Topic: -----

#1 alexjm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-December 12

Problem Displaying Data From 2D Array

Posted 05 December 2012 - 04:41 PM

I'm having trouble figuring out how to display the data I have in my 2D array into a textbox. The array contains data from a text file, and the data is listed as:

xxxx, xxxx, xxxx, xxxx
xxxx, xxxx, xxxx, xxxx

and so on, and when the user selects one destination point from the combo box on my form and one departure site from the second combo box, the mileage traveled should be displayed in a text box after pressing a button. I'm stuck on how to retrieve the right line of code for the users' selection in the combo box. Can anyone help? Here' the code I have so far:

Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim distance As String = "Airports.txt"
        Dim distanceTraveled() As String = IO.File.ReadAllLines(distance)
        For d As Integer = 0 To distanceTraveled.Count - 1
            cboDeparture.Items.Add(distanceTraveled(d))
            cboDestination.Items.Add(distanceTraveled(d))
        Next
    End Sub

    Private Sub cboDeparture_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboDeparture.SelectedIndexChanged
        txtDistance.Clear()
    End Sub

    Private Sub cboDestination_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboDestination.SelectedIndexChanged
        txtDistance.Clear()
    End Sub

    Private Sub btnCalculate_Click(sender As System.Object, e As System.EventArgs) Handles btnCalculate.Click
        If cboDeparture.SelectedIndex = -1 Then
            MsgBox("A selection is required from the Departure list", vbCritical, "Departure Point Required")
            cboDeparture.Focus()
            Exit Sub
        End If
        If cboDestination.SelectedIndex = -1 Then
            MsgBox("A selection is required from the Destination list", vbCritical, "Destination Point Required")
            cboDestination.Focus()
            Exit Sub
        End If
        Dim fileName As String = "Mileage.txt"
        Dim sr As New IO.StreamReader("Mileage.txt")
        Dim linesCount As Integer = sr.ReadToEnd.Split(New String() {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries).Count
        sr = New IO.StreamReader("Mileage.txt")
        Dim array2D(linesCount - 1, 4) As Integer
        For l As Integer = 0 To linesCount - 1
            Dim line() As String = sr.ReadLine.Split(","c)
            For x As Integer = 0 To line.GetUpperBound(0)
                array2D(l, x) = CInt(line(x))
            Next
        Next
    End Sub

End Class


Is This A Good Question/Topic? 0
  • +

Page 1 of 1