Click here to Skip to main content
15,887,267 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: simple multi thread app behaving weirdly Pin
Tony Snowden7-May-14 4:31
Tony Snowden7-May-14 4:31 
GeneralRe: simple multi thread app behaving weirdly Pin
Dave Kreskowiak7-May-14 6:07
mveDave Kreskowiak7-May-14 6:07 
GeneralRe: simple multi thread app behaving weirdly Pin
Tony Snowden7-May-14 21:37
Tony Snowden7-May-14 21:37 
QuestionCombobox value not showed in the datagridview Pin
D.Manivelan1-May-14 23:33
D.Manivelan1-May-14 23:33 
SuggestionRe: Combobox value not showed in the datagridview Pin
Maciej Los2-May-14 8:55
mveMaciej Los2-May-14 8:55 
QuestionSubject message not passing to outlook window from VB6.0 Pin
kk20141-May-14 3:53
kk20141-May-14 3:53 
AnswerRe: Subject message not passing to outlook window from VB6.0 Pin
Dave Kreskowiak1-May-14 5:23
mveDave Kreskowiak1-May-14 5:23 
QuestionNeed help on "Competition Scheduling" Algorithm Pin
N.Wang30-Apr-14 16:43
professionalN.Wang30-Apr-14 16:43 
Here is the question:

12-player are in a 6-day competition. The competition have 6 different games. the rule is:

1. Every player must participate all 6 games.
2. Each player can only play the same game ONCE.
3, Each player can only play with the same opponent ONCE.

The problem is my algorithm cannot scheduling all the players into the games.

Here is my code:

VB
Public Class clsGame
    Public teams As ArrayList

    Public Sub New(ByVal intTeamNumber As Integer)
        teams = New ArrayList
        teams.Capacity = intTeamNumber
    End Sub

    Public Sub add(ByVal intTeam As Integer)
        If Not isFull() And Not contains(intTeam) Then teams.Add(intTeam)
    End Sub

    Public Function isEmpty() As Boolean
        If teams.Count = 0 Then Return True
        Return False
    End Function

    Public Function isFull() As Boolean
        If teams.Count = teams.Capacity Then Return True
        Return False
    End Function

    Public Function contains(ByVal intTeam As Integer) As Boolean
        If teams.Contains(intTeam) Then Return True
        Return False
    End Function

End Class

Public Class clsSummerCamp
    Public intDays As Integer
    Public teams As New Queue
    Public swimming() As clsGame
    Public games(,) As clsGame

    Public Sub New(ByVal intNewDays As Integer, ByVal intTeams As Integer)
        intDays = intNewDays
        ReDim swimming(intDays)
        ReDim games(intDays, 6)
        For intCount As Integer = 0 To intTeams - 1
            teams.Enqueue(intCount)
        Next
    End Sub

    Public Sub schedule(ByVal t As Queue)
        Dim temp As Queue = t.Clone
        initiateGames()
        While Not temp.Count = 0
            Dim intTeamNumber As Integer = temp.Dequeue
            For intDay As Integer = 0 To intDays - 1
                setGames(intDay, intTeamNumber)
            Next
        End While
    End Sub

    Public Sub initiateGames()
        For intGameDay As Integer = 0 To games.GetUpperBound(0) - 1
            For intCount As Integer = 0 To games.GetUpperBound(1) - 1
                games(intGameDay, intCount) = New clsGame(2)
            Next
        Next
    End Sub

    Public Sub setGames(ByVal intDay As Integer, ByVal intTeam As Integer)
        For intCount As Integer = 0 To games.GetUpperBound(1) - 1
            If games(intDay, intCount).isEmpty Then
                If Not isPlayed(intCount, intTeam) Then
                    games(intDay, intCount).add(intTeam)
                    Exit For
                End If
            ElseIf Not games(intDay, intCount).isFull Then
                If Not games(intDay, intCount).contains(intTeam) And Not isPlayed(intCount, intTeam) Then
                    If Not isPlayedWith(games(intDay, intCount).teams.Item(0), intTeam) Then
                        games(intDay, intCount).add(intTeam)
                        Exit For
                    End If
                End If
            End If
        Next
    End Sub

    Public Function isPlayed(ByVal intGame As Integer, ByVal intTeam As Integer) As Boolean
        For intDay As Integer = 0 To games.GetUpperBound(0) - 1
            If games(intDay, intGame).contains(intTeam) Then Return True
        Next
        Return False
    End Function

    Public Function isPlayedWith(ByVal intTeam1 As Integer, ByVal intTeam2 As Integer) As Boolean
        For intDay As Integer = 0 To games.GetUpperBound(0) - 1
            For intCount As Integer = 0 To games.GetUpperBound(1) - 1
                If games(intDay, intCount).contains(intTeam1) And games(intDay, intCount).contains(intTeam2) Then Return True
            Next
        Next
        Return False
    End Function

    Public Sub printSchedule()
        schedule(teams)
        For int1 As Integer = 0 To games.GetUpperBound(0) - 1
            Console.Write("Games: ")
            For int2 As Integer = 0 To games.GetUpperBound(1) - 1
                Console.Write("{0,-10}", games(int1, int2).teams.Item(0) & " vs " & games(int1, int2).teams.Item(1) & "  ")
            Next
            Console.WriteLine()
        Next

    End Sub

End Class

Module modTest

    Sub Main()

        Dim summerCamp As New clsSummerCamp(6, 12)
        summerCamp.printSchedule()

        Console.Read()

    End Sub

End Module

QuestionTwitter REST API V1.1 Pin
Pete_12328-Apr-14 8:10
Pete_12328-Apr-14 8:10 
AnswerRe: Twitter REST API V1.1 Pin
Richard Deeming28-Apr-14 8:27
mveRichard Deeming28-Apr-14 8:27 
GeneralRe: Twitter REST API V1.1 Pin
Pete_12328-Apr-14 9:20
Pete_12328-Apr-14 9:20 
AnswerRe: Twitter REST API V1.1 Pin
HenryHugo28-Apr-14 21:38
professionalHenryHugo28-Apr-14 21:38 
QuestionVB.Net - Best practice to store paths as relative path Pin
Bart Van Eyndhoven27-Apr-14 23:42
Bart Van Eyndhoven27-Apr-14 23:42 
AnswerRe: VB.Net - Best practice to store paths as relative path Pin
Richard Deeming28-Apr-14 2:07
mveRichard Deeming28-Apr-14 2:07 
GeneralRe: VB.Net - Best practice to store paths as relative path Pin
Bart Van Eyndhoven28-Apr-14 2:41
Bart Van Eyndhoven28-Apr-14 2:41 
GeneralRe: VB.Net - Best practice to store paths as relative path Pin
Richard Deeming28-Apr-14 2:48
mveRichard Deeming28-Apr-14 2:48 
Questionhow to combine 3 cells into one cell in datagridview Pin
sensizbenlik26-Apr-14 15:22
sensizbenlik26-Apr-14 15:22 
AnswerRe: how to combine 3 cells into one cell in datagridview Pin
khei-chan00729-Apr-14 20:48
khei-chan00729-Apr-14 20:48 
AnswerRe: how to combine 3 cells into one cell in datagridview Pin
Simon_Whale29-Apr-14 22:14
Simon_Whale29-Apr-14 22:14 
QuestionPrevent clicking on controls inside a groupbox without disabling Pin
dilkonika26-Apr-14 2:38
dilkonika26-Apr-14 2:38 
AnswerRe: Prevent clicking on controls inside a groupbox without disabling Pin
Dave Kreskowiak26-Apr-14 3:07
mveDave Kreskowiak26-Apr-14 3:07 
GeneralRe: Prevent clicking on controls inside a groupbox without disabling Pin
dilkonika26-Apr-14 4:06
dilkonika26-Apr-14 4:06 
GeneralRe: Prevent clicking on controls inside a groupbox without disabling Pin
Dave Kreskowiak26-Apr-14 13:31
mveDave Kreskowiak26-Apr-14 13:31 
GeneralRe: Prevent clicking on controls inside a groupbox without disabling Pin
dilkonika27-Apr-14 3:35
dilkonika27-Apr-14 3:35 
GeneralRe: Prevent clicking on controls inside a groupbox without disabling Pin
Dave Kreskowiak27-Apr-14 6:45
mveDave Kreskowiak27-Apr-14 6:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.