What's on your Ctrl+V?

Code:
Dim Pw1, Pw2 As String
        Dim ds As New DataSet
        Dim da As OleDb.OleDbDataAdapter
        Dim sql As String
        Dim con As New OleDb.OleDbConnection
        Dim I As Integer
        Dim maxrows As Integer
        Pw1 = Password1.Text
        Pw2 = Password2.Text
 
Code:
                // Get adjacent vertices by colour.
                var groupings = from v in vertex.Neighbours
                                where !v.IsEmpty
                                group v by v.Colour into vs
                                select new
                                {
                                    Colour = vs.Key,
                                    Vertices = vs
                                };

                // Consider each colour separately.
                foreach (var grouping in groupings.ToArray())
                {
                    // Get distinct adjacent groups.
                    var neighbours = grouping.Vertices;
                    var groups = (from v in neighbours
                                  select v.Group).Distinct();

                    int groupCount = groups.Count();
                    int neighbourCount = neighbours.Count();
                    if (groupCount == neighbourCount)
                    {
                        // We have as many adjacent groups as vertices, so no splitting is
                        // necessary.

                        // If there are more than one neighbour and group, then the current vertex
                        // cannot have been joining them; hence it must have been of a different
                        // colour. Otherwise, we must establish whether that group used to contain
                        // the current vertex.
                        if (neighbourCount == 1)
                        {
                            var group = neighbours.First().Group;
                            bool isInGroup = group.Contains(vertex);
                            if (isInGroup)
                            {
                                group.Update();
                                updatedGroups.Add(group);
                            }
                        }
                    }
                    else
                    {
                        // We have fewer groups than vertices, so we need to check that they are
                        // contiguous and split them if not.

                        // Examine each neighbouring group and generate a new group from its
                        // vertices.
                        foreach (var group in groups.ToArray())
                        {
                            var newGroups = Group.GetGroups(group);
                            if (newGroups.Count() > 1)
                            {
                                // This group needs to be split.

                                // Find a neighbour in this group whose (new) group is largest.
                                var largestGroup = newGroups.Aggregate((g1, g2) => g1.Count < g2.Count ? g2 : g1);
                                var largestGroupVertex = (from v in largestGroup
                                                          where neighbours.Contains(v)
                                                          select v).First();

                                // Keep the original group for members of this new group and update it
                                // from the vertex found (discarding the new group itself).
                                largestGroupVertex.Group.Update(largestGroupVertex);

                                // Use the new groups for all other vertices.
                                newGroups.Except(largestGroup).ForEach(g => g.ForEach(v => v.Group = g));

                                createdGroups.Add(newGroups.Except(largestGroup));
                                updatedGroups.Add(largestGroupVertex.Group);
                            }
                        }
                    }
                }

Part of some buggy code from a Go program I'm currently writing. The bug is that the colours (groups) of the three black pieces should be different:

http://i49.tinypic.com/mhgl5w.png
 
Last edited:
VEHA:
Windows("PC - LAP by VEHICLE GROUP.csv").Activate
Dim rngFound As Range
Set rngFound = Cells.Find(What:="0-9", After:=ActiveCell)
If rngFound Is Nothing Then GoTo VEHB
Cells.Find(What:="0-9", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.Range("A1", "BA1").Select
Selection.Copy
Windows("2010 Private Car PC Lapses.xls").Activate
Cells.Find(What:="0-9", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select
Windows("PC - LAP by VEHICLE GROUP.csv").Activate
Range("A1").Select

VEHB:
Windows("PC - LAP by VEHICLE GROUP.csv").Activate
Set rngFound = Cells.Find(What:="10 to 19", After:=ActiveCell)
If rngFound Is Nothing Then GoTo VEHC
Cells.Find(What:="10 to 19", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.Range("A1", "BA1").Select
Selection.Copy
Windows("2010 Private Car PC Lapses.xls").Activate
Cells.Find(What:="10-19", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select
Windows("PC - LAP by VEHICLE GROUP.csv").Activate
Range("A1").Select

VEHC:
Windows("PC - LAP by VEHICLE GROUP.csv").Activate
Set rngFound = Cells.Find(What:="20-29", After:=ActiveCell)
If rngFound Is Nothing Then GoTo VEHD
Cells.Find(What:="20-29", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.Range("A1", "BA1").Select
Selection.Copy
Windows("2010 Private Car PC Lapses.xls").Activate
Cells.Find(What:="20-29", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select
Windows("PC - LAP by VEHICLE GROUP.csv").Activate
Range("A1").Select

VEHD:
Windows("PC - LAP by VEHICLE GROUP.csv").Activate
Set rngFound = Cells.Find(What:="30-39", After:=ActiveCell)
If rngFound Is Nothing Then GoTo VEHE
Cells.Find(What:="30-39", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.Range("A1", "BA1").Select
Selection.Copy
Windows("2010 Private Car PC Lapses.xls").Activate
Cells.Find(What:="30-39", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select
Windows("PC - LAP by VEHICLE GROUP.csv").Activate
Range("A1").Select

VEHE:
Windows("PC - LAP by VEHICLE GROUP.csv").Activate
Set rngFound = Cells.Find(What:="40-49", After:=ActiveCell)
If rngFound Is Nothing Then GoTo VEHF
Cells.Find(What:="40-49", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.Range("A1", "BA1").Select
Selection.Copy
Windows("2010 Private Car PC Lapses.xls").Activate
Cells.Find(What:="40-49", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select
Windows("PC - LAP by VEHICLE GROUP.csv").Activate
Range("A1").Select

VEHF:
Windows("PC - LAP by VEHICLE GROUP.csv").Activate
Set rngFound = Cells.Find(What:="50", After:=ActiveCell)
If rngFound Is Nothing Then GoTo VEHG
Cells.Find(What:="50", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.Range("A1", "BA1").Select
Selection.Copy
Windows("2010 Private Car PC Lapses.xls").Activate
Cells.Find(What:="50", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select
Windows("PC - LAP by VEHICLE GROUP.csv").Activate
Range("A1").Select


VEHG:
Windows("PC - LAP by VEHICLE GROUP.csv").Close
 
Back
Top Bottom