Im having a bit of a problem passing variables from one form to another. If somone could help i would be really greatful! Oh and for some reason my saveing sub routine dosent work, i cant get it to save the file in text format. Thanks!

Public Class DijkstrasAlgorithmFinal
Dim x As Integer
Dim Dijkstras(4, 3) As Integer
Dim InputValues(4, 4) As Integer
Dim valNum As Single
Dim txtBxArray As TextBox()
Dim shortestPath As Integer
Dim validation(5) As Boolean
Dim path(5) As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtBxArray = New TextBox() {Aa, Ba, Ca, Da, Ab, Bb, Cb, Db, Ac, Bc, Cc, Dc, Ad, Bd, Cd, Dd}
Aa.Text = "0"
Bb.Text = "0"
Cc.Text = "0"
Dd.Text = "0"
End Sub

Private Function readgrid(ByVal x As Integer, ByVal y As Integer) As Integer
Dim index As Integer
index = 4 * (y - 1) + x - 1
readgrid = txtBxArray(index).Text
End Function

'Private Sub btnSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelect.Click
' 'example of how to use readgrid function to get data from grid
' Dim x As Integer
' Dim y As Integer
' x = txtX.Text
' y = txtY.Text
' txtOutput.Text = readgrid(x, y)
'End Sub

Private Sub Ab_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ab.TextChanged
Ba.Text = Ab.Text
End Sub

Private Sub Ba_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ba.TextChanged
Ab.Text = Ba.Text
Try
valNum = Ba.Text / Ab.Text
InputValues(1, 0) = Ba.Text
InputValues(0, 1) = Ab.Text
Catch ex As Exception
If x > 0 Then
MsgBox("You may only enter positive numbers! Error: " & Err.Number, MsgBoxStyle.Exclamation, "Error")
End If
x = x + 1
Ba.Text = ""
End Try
End Sub

Private Sub Ca_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ca.TextChanged
Ac.Text = Ca.Text
End Sub

Private Sub Ac_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ac.TextChanged
Ca.Text = Ac.Text
Try
valNum = Ac.Text / Ca.Text
InputValues(0, 2) = Ac.Text
InputValues(2, 0) = Ca.Text
Catch ex As Exception
If x > 0 Then
MsgBox("You may only enter positive numbers! Error: " & Err.Number, MsgBoxStyle.Exclamation, "Error")
End If
x = x + 1
Ac.Text = ""
End Try
End Sub

Private Sub Da_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Da.TextChanged
Ad.Text = Da.Text
End Sub

Private Sub Ad_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ad.TextChanged
Da.Text = Ad.Text
Try
valNum = Ad.Text / Da.Text
InputValues(0, 3) = Ad.Text
InputValues(3, 0) = Da.Text
Catch ex As Exception
If x > 0 Then
MsgBox("You may only enter positive numbers! Error: " & Err.Number, MsgBoxStyle.Exclamation, "Error")
End If
x = x + 1
Ad.Text = ""
End Try
End Sub

Private Sub Cb_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cb.TextChanged
Bc.Text = Cb.Text
End Sub

Private Sub Bc_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bc.TextChanged
Cb.Text = Bc.Text
Try
valNum = Bc.Text / Cb.Text
InputValues(1, 2) = Bc.Text
InputValues(2, 1) = Cb.Text
Catch ex As Exception
If x > 0 Then
MsgBox("You may only enter positive numbers! Error: " & Err.Number, MsgBoxStyle.Exclamation, "Error")
End If
x = x + 1
Bc.Text = ""
End Try
End Sub

Private Sub Dc_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Dc.TextChanged
Cd.Text = Dc.Text
End Sub

Private Sub Cd_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cd.TextChanged
Dc.Text = Cd.Text
Try
valNum = Cd.Text / Dc.Text
InputValues(2, 3) = Cd.Text
InputValues(3, 2) = Dc.Text
Catch ex As Exception
If x > 0 Then
MsgBox("You may only enter positive numbers! Error: " & Err.Number, MsgBoxStyle.Exclamation, "Error")
End If
x = x + 1
Cd.Text = ""
End Try
End Sub

Private Sub Bd_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bd.TextChanged
Db.Text = Bd.Text
End Sub

Private Sub Db_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Db.TextChanged
Bd.Text = Db.Text
Try
valNum = Db.Text / Bd.Text
InputValues(3, 1) = Db.Text
InputValues(1, 3) = Bd.Text
Catch ex As Exception
If x > 0 Then
MsgBox("You may only enter positive numbers! Error: " & Err.Number, MsgBoxStyle.Exclamation, "Error")
End If
x = x + 1
Db.Text = ""
End Try
End Sub

Private Sub refreshTxt(ByVal shortestpath As Integer, ByRef validation As Array, ByRef path As Array)
Dim i As Integer
shortestpath = 0
For i = 1 To 5
validation(i) = False
path(i) = 0
Next
End Sub

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim whichPath As Integer

Call refreshTxt(shortestPath, validation, path)

If Ad.Text = 0 Then
validation(1) = False
Else
validation(1) = True
path(1) = Val(Ad.Text)
End If

If Ab.Text = 0 Or Bd.Text = 0 Then
validation(2) = False
Else
validation(2) = True
path(2) = Val(Ab.Text) + Val(Bd.Text)
End If

If Ac.Text = 0 Or Cd.Text = 0 Then
validation(3) = False
Else
validation(3) = True
path(3) = Val(Ac.Text) + Val(Cd.Text)
End If

If Ab.Text = 0 Or Bc.Text = 0 Or Cd.Text = 0 Then
validation(4) = False
Else
validation(4) = True
path(4) = Val(Ab.Text) + Val(Bc.Text) + Val(Cd.Text)
End If

If Ac.Text = 0 Or Cb.Text = 0 Or Bd.Text = 0 Then
validation(5) = False
Else
validation(5) = True
path(5) = Val(Ac.Text) + Val(Cb.Text) + Val(Bd.Text)
End If

Call calculateShortestPath(validation, path, shortestPath, whichPath)
MsgBox("Path " & whichPath & " is the shortest route and has a distance of " & shortestPath, , "Results")
btnVisualRepresentation.Enabled = True
End Sub

Private Sub btnPaths_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPaths.Click
MsgBox("Path 1 is A-D", MsgBoxStyle.Information, "Path#")
MsgBox("Path 2 is A-B-D", MsgBoxStyle.Information, "Path#")
MsgBox("Path 3 is A-C-D", MsgBoxStyle.Information, "Path#")
MsgBox("Path 4 is A-B-C-D", MsgBoxStyle.Information, "Path#")
MsgBox("Path 5 is A-C-B-D", MsgBoxStyle.Information, "Path#")
End Sub

Private Sub btnVisualRepresentation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVisualRepresentation.Click
VisualRepresentation.Show()
End Sub

Sub calculateShortestPath(ByVal validation As Array, ByVal path As Array, ByRef shortestPath As Integer, ByRef whichPath As Integer)
Dim i As Integer
For i = 1 To 5
If validation(1) = True Then
shortestPath = path(i)
End If
Next
For i = 1 To 5
If validation(i) = True Then
If path(i) < shortestPath Then
shortestPath = path(i)
whichPath = i
End If
End If
Next
End Sub

Private Sub btnInfo1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInfo1.Click
MsgBox("Please enter your node distances in the grid provided then use this button to calculate the shortest path", MsgBoxStyle.Information, "Calculate")
End Sub

Private Sub btnInfo2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInfo2.Click
MsgBox("Use this button to aquire a list of routes", MsgBoxStyle.Information, "Paths")
End Sub

Private Sub btnInf03_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInf03.Click
MsgBox("Use this button to view a visual representation of the algorithm (you must use calculate first)", MsgBoxStyle.Information, "VisualRepresentation")
End Sub