arnelgp
..forever waiting... waiting for jellybean!
- Local time
- Tomorrow, 05:25
- Joined
- May 7, 2009
- Messages
- 19,245
Dear arnelgp,i think you need to "group" all A first, all B first.
what i mean is there must be an order first.
you have your data popping out of nowhere.
i am sorting it using macro.
also the map is outdated so you must follow your
chart data.
Dear arnelgp,use matrix2, i updated its VBA code.
you do not need to sort it manually.
the VBA will sort it before doing the
calculation.
i just told you not to sort manually.Any new entries Sources, I am sorting manually...
I thank you for your excellent efforts...
Dear arnelgp,i just told you not to sort manually.
when you click the blue button, VBA will sort it.
Dear arnelgp,try this one, I complete remove the sorting.
and i think there is no need to for you or the program to sort with
the current code.
OK Sir, I will ...thanks..Try on bigger dataset.
on your post #27 there is a blank row on 18, make sure you press delete in side the cells
so it will not be included.
Option Compare Database
Option Explicit
Type TNode
start As String
end As String
size As Long
End Type
Dim point As String
Dim nodes(20) As TNode
Dim results As String
Sub process(frompoint As String, target As String, path As String, length As Long)
Dim x As Long
If frompoint = target Then
If Len(results) > 0 Then
results = results & vbCrLf
End If
results = results & path & "," & target & " Length: " & length
Exit Sub
End If
For x = 1 To 20
If nodes(x).start = frompoint Then
If path = "" Then
process nodes(x).end, target, nodes(x).start, length + nodes(x).size
Else
process nodes(x).end, target, path & "," & nodes(x).start, length + nodes(x).size
End If
End If
Next
End Sub
Sub main()
Dim x As Long
Dim fno As Long
Dim fname As String
For x = 1 To 20
nodes(x).start = ""
nodes(x).end = ""
nodes(x).size = 0
Next
results = ""
nodes(1).start = "A"
nodes(1).end = "F"
nodes(1).size = 2
nodes(2).start = "A"
nodes(2).end = "B"
nodes(2).size = 10
nodes(3).start = "A"
nodes(3).end = "C"
nodes(3).size = 5
nodes(4).start = "A"
nodes(4).end = "D"
nodes(4).size = 12
nodes(5).start = "B"
nodes(5).end = "F"
nodes(5).size = 5
nodes(6).start = "B"
nodes(6).end = "C"
nodes(6).size = 2
nodes(7).start = "F"
nodes(7).end = "Z"
nodes(7).size = 4
nodes(8).start = "B"
nodes(8).end = "Z"
nodes(8).size = 15
nodes(9).start = "C"
nodes(9).end = "Z"
nodes(9).size = 10
nodes(10).start = "D"
nodes(10).end = "Z"
nodes(10).size = 14
nodes(11).start = "E"
nodes(11).end = "Z"
nodes(11).size = 1
nodes(12).start = "B"
nodes(12).end = "E"
nodes(12).size = 5
nodes(13).start = "D"
nodes(13).end = "E"
nodes(13).size = 3
process "A", "Z", "", 0
'MsgBox results
fno = FreeFile
fname = "d:\graph.txt"
Open fname For Output As #fno
Print #fno, results
Close #fno
Application.FollowHyperlink fname
End Sub
Dear arnelgp,Try on bigger dataset.
on your post #27 there is a blank row on 18, make sure you press delete in side the cells
so it will not be included.
Excellent Sir, it is improved.it is slow considering it goes on recursively.
somewhat improve by storing "data" in collection/dictionary.
it would be realistic if you work on the data provided.Just open module1, and run the sub called "main