By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,572 Members | 1,516 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,572 IT Pros & Developers. It's quick & easy.

Text file not displaying when I run my program

P: 1
I'm creating 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 their final scores, throw-out the highest & the lowest and then add the remaining 6 and multiply by the degree of difficulty.

The problem I'm running into is that the text file with the names of the divers isn't showing up when I run the program so that I can pick a name from the list.

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  3.         Dim dt As New DataTable
  4.         dt.Columns.Add(New DataColumn With
  5.             {.ColumnName = "Identifier", .DataType = GetType(Int32), .AutoIncrement = True})
  6.         dt.Columns.Add(New DataColumn With
  7.             {.ColumnName = "Description", .DataType = GetType(String)})
  8.         dt.Columns.Add(New DataColumn With
  9.             {.ColumnName = "Factor", .DataType = GetType(Decimal)})
  10.         dt.Rows.Add(New Object() {Nothing, "Bellyflop", 4D})
  11.         dt.Rows.Add(New Object() {Nothing, "Canonball", 2D})
  12.         dt.Rows.Add(New Object() {Nothing, "Back Flying Somersault", 3D})
  13.         dt.Rows.Add(New Object() {Nothing, "Back Flying 2 1/2 Somersault", 3.56D})
  14.         dt.Rows.Add(New Object() {Nothing, "Reverse Dive", 3.52D})
  15.         dt.Rows.Add(New Object() {Nothing, "Inward Somersault", 3.36D})
  16.         dt.Rows.Add(New Object() {Nothing, "Inward 1 1/2 Somersault", 3.54D})
  17.         dt.Rows.Add(New Object() {Nothing, "Forward Dive 1/2 Twist", 3.51D})
  18.         ListBox1.DisplayMember = "Description"
  19.         ListBox1.ValueMember = "Factor"
  20.         ListBox1.DataSource = dt
  21.         Label1.DataBindings.Add("Text", dt, "Factor")
  22.         ListBox1.Items.LoadFromFile("Names.txt")
  23.     End Sub
  24.  
  25.     Private Sub ListBox1_SelectedIndexChanged(
  26.         ByVal sender As System.Object,
  27.         ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
  28.         Console.WriteLine("Factor {0}", CDec(ListBox1.SelectedValue))
  29.     End Sub
  30.  
  31.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  32.         Dim ScoreSum =
  33.             (
  34.                 From T In Me.Controls.OfType(Of NumericUpDown)()
  35.                 Select T.Value).Sum / CDec(ListBox1.SelectedValue)
  36.         TextBox1.Text = ScoreSum.ToString("n2")
  37.     End Sub
  38. End Class
  39.  
  40. Module Module1
  41.  
  42.     <System.Runtime.CompilerServices.Extension()> _
  43.     Public Sub LoadFromFile(
  44.         ByVal sender As ListBox.ObjectCollection,
  45.         ByVal FileName As String)
  46.         sender.AddRange(IO.File.ReadAllLines(FileName))
  47.     End Sub
  48.  
  49. End Module
May 17 '13 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.