|
-
May 17th, 2013, 11:41 AM
#1
Thread Starter
New Member
Stucky on a programing assignment
I'm suppose to write a diving competion program that
1. keeps score for up to 16 divers.
2. Each diver has 8 dives.
3. There are 8 judges scoring each dives w/scores ranging from 0-10 w/one decimal place.
4. Each dive has a degree of difficulty from 1-4 w/two decimal places.
5. To get the final score for each diver, throw-out the highest & the lowest scores and then add all 6 and multiply by the degree of difficulty.
The problem I'm running into is that the names of the divers are not showing up for me to pick when I run the program. Any help is greatly appreciated!
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
dt.Columns.Add(New DataColumn With
{.ColumnName = "Identifier", .DataType = GetType(Int32), .AutoIncrement = True})
dt.Columns.Add(New DataColumn With
{.ColumnName = "Description", .DataType = GetType(String)})
dt.Columns.Add(New DataColumn With
{.ColumnName = "Factor", .DataType = GetType(Decimal)})
dt.Rows.Add(New Object() {Nothing, "Bellyflop", 4D})
dt.Rows.Add(New Object() {Nothing, "Canonball", 2D})
dt.Rows.Add(New Object() {Nothing, "Back Flying Somersault", 3D})
dt.Rows.Add(New Object() {Nothing, "Back Flying 2 1/2 Somersault", 3.56D})
dt.Rows.Add(New Object() {Nothing, "Reverse Dive", 3.52D})
dt.Rows.Add(New Object() {Nothing, "Inward Somersault", 3.36D})
dt.Rows.Add(New Object() {Nothing, "Inward 1 1/2 Somersault", 3.54D})
dt.Rows.Add(New Object() {Nothing, "Forward Dive 1/2 Twist", 3.51D})
ListBox1.DisplayMember = "Description"
ListBox1.ValueMember = "Factor"
ListBox1.DataSource = dt
Label1.DataBindings.Add("Text", dt, "Factor")
ListBox1.Items.LoadFromFile("Names.txt")
End Sub
Private Sub ListBox1_SelectedIndexChanged(
ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Console.WriteLine("Factor {0}", CDec(ListBox1.SelectedValue))
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ScoreSum =
(
From T In Me.Controls.OfType(Of NumericUpDown)()
Select T.Value).Sum / CDec(ListBox1.SelectedValue)
TextBox1.Text = ScoreSum.ToString("n2")
End Sub
End Class
Module Module1
<System.Runtime.CompilerServices.Extension()> _
Public Sub LoadFromFile(
ByVal sender As ListBox.ObjectCollection,
ByVal FileName As String)
sender.AddRange(IO.File.ReadAllLines(FileName))
End Sub
End Module
-
May 17th, 2013, 12:23 PM
#2
Re: Stucky on a programing assignment
ListBox1.DataSource = dt
ListBox1.Items.LoadFromFile("Names.txt")
It has to be one or the other. It can't be both. The binding will take precedence.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 17th, 2013, 12:40 PM
#3
Thread Starter
New Member
Re: Stucky on a programing assignment
Ok now I understand, so I have to create another ListBox if I want to put the divers names in... Thanks! Now does anyone know how to reset the form when I would pick a new diver and/or dive???
-
May 17th, 2013, 02:28 PM
#4
Thread Starter
New Member
Re: Stucky on a programing assignment
After working on this off and on all day, I'm almost finished. Now all I have to do figure out how to eliminate the highest and lowest of the 8 judges' scores (right now I only have 6 judges listed) to get the final score for each diver and how to reset the form when I choose a new diver and/or dive. Again Any help would be greatly appreciated!
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
dt.Columns.Add(New DataColumn With
{.ColumnName = "Identifier", .DataType = GetType(Int32), .AutoIncrement = True})
dt.Columns.Add(New DataColumn With
{.ColumnName = "Description", .DataType = GetType(String)})
dt.Columns.Add(New DataColumn With
{.ColumnName = "Factor", .DataType = GetType(Decimal)})
dt.Rows.Add(New Object() {Nothing, "Bellyflop", 4D})
dt.Rows.Add(New Object() {Nothing, "Canonball", 2D})
dt.Rows.Add(New Object() {Nothing, "Back Flying Somersault", 3D})
dt.Rows.Add(New Object() {Nothing, "Back Flying 2 1/2 Somersault", 3.56D})
dt.Rows.Add(New Object() {Nothing, "Reverse Dive", 3.52D})
dt.Rows.Add(New Object() {Nothing, "Inward Somersault", 3.36D})
dt.Rows.Add(New Object() {Nothing, "Inward 1 1/2 Somersault", 3.54D})
dt.Rows.Add(New Object() {Nothing, "Forward Dive 1/2 Twist", 3.51D})
ListBox1.DisplayMember = "Description"
ListBox1.ValueMember = "Factor"
ListBox1.DataSource = dt
Label1.DataBindings.Add("Text", dt, "Factor")
End Sub
Private Sub ListBox1_SelectedIndexChanged(
ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Console.WriteLine("Factor {0}", CDec(ListBox1.SelectedValue))
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ScoreSum =
(
From T In Me.Controls.OfType(Of NumericUpDown)()
Select T.Value).Sum / CDec(ListBox1.SelectedValue)
TextBox1.Text = ScoreSum.ToString("n2")
End Sub
Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
' Set the caption bar text of the form.
Me.Text = "Divers"
ListBox2.Items.Add("Aaron Ferster")
ListBox2.Items.Add("Matt Redmon")
ListBox2.Items.Add("Jonathan Witmer")
ListBox2.Items.Add("Adam Kramer")
ListBox2.Items.Add("Daniar Tilaev")
ListBox2.Items.Add("Jordan Eyster")
ListBox2.Items.Add("Steve Boyer")
ListBox2.Items.Add("Chris Watson")
ListBox2.Items.Add("Jackson Lawton")
ListBox2.Items.Add("Henry Straub")
ListBox2.Items.Add("Matt Gessner")
ListBox2.Items.Add("Bryan Gessner")
ListBox2.Items.Add("Jeff Cole")
ListBox2.Items.Add("Sean Stout")
ListBox2.Items.Add("Bryan Stout")
End Sub
End Class
-
May 17th, 2013, 06:31 PM
#5
Re: Stucky on a programing assignment
Load the judges scores into an array. Sort the array then use only values 1 - 6 (0 and 7 being automatically the top and bottom).
Values in selectable controls will automatically 'reset' when a new selection is made so all you have to do then is set your NUDs to 0 using one of the Selected Changed events. You might want to disable the calculate button until all the NUDs have received a value.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|