EDN Admin
Well-known member
This is the code we have so far and we are trying to assign the values in our combo box to our arrays.
e.g. Southampton to London is array (0,1)
Public Class frmDistance
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Stating what file needs to be opened to retrieve the correct data
Dim sr As IO.StreamReader = IO.File.OpenText("distance.txt")
We need 7 Arrays because there is 7 cities
Dim cityArray(7, 7) As String
Dim row, col As Integer
populating the arrays
col = 0
row = 0
Do While sr.Peek() <> -1
sr.ReadLine()
cityArray(row, col) = CInt(sr.ReadLine)
col = col + 1
If (col = 7) Then
row = row + 1
col = 0
End If
Loop
sr.Close()
assigning value to array
convert and desplay the value
col = CStr(cboDestination.Text)
row = CStr(cboOrigin.Text)
If (col >= 0 And col <= 7) And (row >= 0 And row <= 7) Then
lblOutput.Text = "The milage is " & CInt(cityArray(col, row))
End If
from string to integer
End Sub
End Class
View the full article
e.g. Southampton to London is array (0,1)
Public Class frmDistance
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Stating what file needs to be opened to retrieve the correct data
Dim sr As IO.StreamReader = IO.File.OpenText("distance.txt")
We need 7 Arrays because there is 7 cities
Dim cityArray(7, 7) As String
Dim row, col As Integer
populating the arrays
col = 0
row = 0
Do While sr.Peek() <> -1
sr.ReadLine()
cityArray(row, col) = CInt(sr.ReadLine)
col = col + 1
If (col = 7) Then
row = row + 1
col = 0
End If
Loop
sr.Close()
assigning value to array
convert and desplay the value
col = CStr(cboDestination.Text)
row = CStr(cboOrigin.Text)
If (col >= 0 And col <= 7) And (row >= 0 And row <= 7) Then
lblOutput.Text = "The milage is " & CInt(cityArray(col, row))
End If
from string to integer
End Sub
End Class
View the full article