09-23-2012, 08:11 PM
Hey guys! I just finished up the application that will determine the winner of my website giveaway. I tried to make it as random as possible. The program also automatically deletes those pesky cheaters from entering...
Here's the code:
[code2=vbnet]Module Module1
Private randomCounterOne As Integer
Private randomCounterTwo As Integer
Sub Main()
Dim YouTubeComments As New List(Of String)
Dim BPForumsComments As New List(Of String)
Dim TotalComments As New List(Of String)
Console.WriteLine("Welcome to the Website Giveaway 2012. We will select 2 winners. Press ENTER to continue")
Console.ReadLine()
Console.WriteLine("To begin, please insert Random Counter One (1-500)")
randomCounterOne = CInt(Console.ReadLine())
Console.WriteLine("To begin, please insert Random Counter Two (1-314,159)")
randomCounterTwo = CInt(Console.ReadLine())
Console.WriteLine("Thanks! Now please press enter to continue")
Console.ReadLine()
Console.WriteLine("Please wait while we populate the list of YouTube commenters")
Dim reader As New System.IO.StreamReader(My.Application.Info.DirectoryPath + "/WGYT.txt")
Dim readEntries As String = reader.ReadToEnd
reader.Close()
For Each entry As String In readEntries.Split(vbNewLine)
If (entry.Length > 0) Then
entry = entry.Replace(" ", "")
entry = entry.ToUpper
YouTubeComments.Add(entry)
End If
Next
s()
Console.WriteLine("YouTube commenter list succesfully populated!")
Console.WriteLine("Please wait while we populate the list of BPFORUMS commenters")
reader = New System.IO.StreamReader(My.Application.Info.DirectoryPath + "/WGBP.txt")
readEntries = reader.ReadToEnd
reader.Close()
For Each entry As String In readEntries.Split(vbNewLine)
If (entry.Length > 0) Then
entry = entry.Replace(" ", "")
entry = entry.ToUpper
BPForumsComments.Add(entry)
End If
Next
s()
Console.WriteLine("BPFORUMS commenters have been populated. Determining and deleting cheaters")
Dim cheaters As New List(Of String)
s()
YouTubeComments.Sort()
For i As Integer = 1 To (YouTubeComments.Count - 1) Step 1
If (YouTubeComments.Item(i).Equals(YouTubeComments.Item(i - 1))) Then
cheaters.Add(YouTubeComments.Item(i - 1))
End If
Next
BPForumsComments.Sort()
For i As Integer = 1 To (BPForumsComments.Count - 1) Step 1
If (BPForumsComments.Item(i).Equals(BPForumsComments.Item(i - 1))) Then
cheaters.Add(BPForumsComments.Item(i - 1))
End If
Next
For Each cheater As String In cheaters
While (YouTubeComments.Contains(cheater))
YouTubeComments.Remove(cheater)
End While
While (BPForumsComments.Contains(cheater))
BPForumsComments.Remove(cheater)
End While
Next
'----
s()
Console.WriteLine("Cheaters purged. Combining lists")
TotalComments.AddRange(YouTubeComments.ToArray)
TotalComments.AddRange(BPForumsComments.ToArray)
s()
Console.WriteLine("Lists combined - Picking random winner # 1 & 2")
Dim rndIndex As Integer
For lol As Integer = 1 To randomCounterOne Step 1
rndIndex = CInt((Int(Rnd() * TotalComments.Count)))
Next
Dim secondRndIndex As Integer = rndIndex
For lol As Integer = 1 To randomCounterTwo Step 1
While (rndIndex = secondRndIndex)
secondRndIndex = CInt(Int((Rnd() * TotalComments.Count)))
End While
Next
s()
Console.WriteLine("Winner Indices determined! Drumroll please..")
s()
Console.WriteLine("3...")
s()
Console.WriteLine("2...")
s()
Console.WriteLine("1...")
s()
Dim gColor As ConsoleColor = Console.ForegroundColor
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("The first winner is: " & TotalComments.Item(rndIndex).ToString & " Congratulations!")
Console.ForegroundColor = gColor
s()
Console.WriteLine("Second winner is loading...")
Console.WriteLine("3...")
s()
Console.WriteLine("2...")
s()
Console.WriteLine("1...")
s()
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("The second winner is: " & TotalComments.Item(secondRndIndex).ToString & " Congratulations!")
Console.ReadLine()
End Sub
Public Sub s()
Threading.Thread.Sleep(1500)
End Sub
End Module[/code2]
P.S: I know this is not the best way to do this. Time was of the essence.
Here are the two files you'll need:
[attachment=0]<!-- ia0 -->txtFiles.zip<!-- ia0 -->[/attachment]
Here's the code:
[code2=vbnet]Module Module1
Private randomCounterOne As Integer
Private randomCounterTwo As Integer
Sub Main()
Dim YouTubeComments As New List(Of String)
Dim BPForumsComments As New List(Of String)
Dim TotalComments As New List(Of String)
Console.WriteLine("Welcome to the Website Giveaway 2012. We will select 2 winners. Press ENTER to continue")
Console.ReadLine()
Console.WriteLine("To begin, please insert Random Counter One (1-500)")
randomCounterOne = CInt(Console.ReadLine())
Console.WriteLine("To begin, please insert Random Counter Two (1-314,159)")
randomCounterTwo = CInt(Console.ReadLine())
Console.WriteLine("Thanks! Now please press enter to continue")
Console.ReadLine()
Console.WriteLine("Please wait while we populate the list of YouTube commenters")
Dim reader As New System.IO.StreamReader(My.Application.Info.DirectoryPath + "/WGYT.txt")
Dim readEntries As String = reader.ReadToEnd
reader.Close()
For Each entry As String In readEntries.Split(vbNewLine)
If (entry.Length > 0) Then
entry = entry.Replace(" ", "")
entry = entry.ToUpper
YouTubeComments.Add(entry)
End If
Next
s()
Console.WriteLine("YouTube commenter list succesfully populated!")
Console.WriteLine("Please wait while we populate the list of BPFORUMS commenters")
reader = New System.IO.StreamReader(My.Application.Info.DirectoryPath + "/WGBP.txt")
readEntries = reader.ReadToEnd
reader.Close()
For Each entry As String In readEntries.Split(vbNewLine)
If (entry.Length > 0) Then
entry = entry.Replace(" ", "")
entry = entry.ToUpper
BPForumsComments.Add(entry)
End If
Next
s()
Console.WriteLine("BPFORUMS commenters have been populated. Determining and deleting cheaters")
Dim cheaters As New List(Of String)
s()
YouTubeComments.Sort()
For i As Integer = 1 To (YouTubeComments.Count - 1) Step 1
If (YouTubeComments.Item(i).Equals(YouTubeComments.Item(i - 1))) Then
cheaters.Add(YouTubeComments.Item(i - 1))
End If
Next
BPForumsComments.Sort()
For i As Integer = 1 To (BPForumsComments.Count - 1) Step 1
If (BPForumsComments.Item(i).Equals(BPForumsComments.Item(i - 1))) Then
cheaters.Add(BPForumsComments.Item(i - 1))
End If
Next
For Each cheater As String In cheaters
While (YouTubeComments.Contains(cheater))
YouTubeComments.Remove(cheater)
End While
While (BPForumsComments.Contains(cheater))
BPForumsComments.Remove(cheater)
End While
Next
'----
s()
Console.WriteLine("Cheaters purged. Combining lists")
TotalComments.AddRange(YouTubeComments.ToArray)
TotalComments.AddRange(BPForumsComments.ToArray)
s()
Console.WriteLine("Lists combined - Picking random winner # 1 & 2")
Dim rndIndex As Integer
For lol As Integer = 1 To randomCounterOne Step 1
rndIndex = CInt((Int(Rnd() * TotalComments.Count)))
Next
Dim secondRndIndex As Integer = rndIndex
For lol As Integer = 1 To randomCounterTwo Step 1
While (rndIndex = secondRndIndex)
secondRndIndex = CInt(Int((Rnd() * TotalComments.Count)))
End While
Next
s()
Console.WriteLine("Winner Indices determined! Drumroll please..")
s()
Console.WriteLine("3...")
s()
Console.WriteLine("2...")
s()
Console.WriteLine("1...")
s()
Dim gColor As ConsoleColor = Console.ForegroundColor
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("The first winner is: " & TotalComments.Item(rndIndex).ToString & " Congratulations!")
Console.ForegroundColor = gColor
s()
Console.WriteLine("Second winner is loading...")
Console.WriteLine("3...")
s()
Console.WriteLine("2...")
s()
Console.WriteLine("1...")
s()
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("The second winner is: " & TotalComments.Item(secondRndIndex).ToString & " Congratulations!")
Console.ReadLine()
End Sub
Public Sub s()
Threading.Thread.Sleep(1500)
End Sub
End Module[/code2]
P.S: I know this is not the best way to do this. Time was of the essence.
Here are the two files you'll need:
[attachment=0]<!-- ia0 -->txtFiles.zip<!-- ia0 -->[/attachment]