Results 1 to 6 of 6

Thread: Format Exception Unhandled

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    2

    Format Exception Unhandled

    When I run this program I get a Format Exception was Unhandled Input String Format was not a correct format. It happens at the 2nd Listbox1.text line when I have the Sting formatted Anyone have any ideas
    vb.net Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim Pop As IO.StreamReader = IO.File.OpenText("populationdata.txt")
    3.         Dim Group As String
    4.         Dim Male, Female, Total, Male2, Female2, Total2 As Double
    5.         Dim Total3 As Double
    6.         Dim fmtstng As String = "{0,-15} {1,14} {2,13} (3,12:p} {4,11:p} {5,10:p}"
    7.  
    8.         Group = Pop.ReadLine
    9.         Total += CDbl(Pop.ReadLine)
    10.         Total += CDbl(Pop.ReadLine)
    11.         Group = Pop.ReadLine
    12.         Total += CDbl(Pop.ReadLine)
    13.         Total += CDbl(Pop.ReadLine)
    14.         Group = Pop.ReadLine
    15.         Total += CDbl(Pop.ReadLine)
    16.         Total += CDbl(Pop.ReadLine)
    17.         Pop.Close()
    18.         ListBox1.Items.Add("Age Group    Females     %Males   %Females   %Total")
    19.         Pop = IO.File.OpenText("populationdata.txt")
    20.         Group = Pop.ReadLine
    21.         Male = CDbl(Pop.ReadLine)
    22.         Female = CDbl(Pop.ReadLine)
    23.         Total2 = Male + Female
    24.         Male2 = Male / Total2 * 100
    25.         Female2 = Female / Total2 * 100
    26.         Total3 = Total2 / Total * 100
    27.         ListBox1.Items.Add(String.Format(fmtstng, Group, Male, Female, Male2, Female2, Total3)):wave:  This is where I have the issue
    28.         Group = Pop.ReadLine
    29.         Male = CDbl(Pop.ReadLine)
    30.         Female = CDbl(Pop.ReadLine)
    31.         Total2 = Male + Female
    32.         Male2 = Male / Total2 * 100
    33.         Female2 = Female / Total2 * 100
    34.         Total3 = Total2 / Total * 100
    35.         ListBox1.Items.Add(String.Format(fmtstng, Group, Male, Female, Male2, Female2, Total3))
    36.         Group = Pop.ReadLine
    37.         Male = CDbl(Pop.ReadLine)
    38.         Female = CDbl(Pop.ReadLine)
    39.         Total2 = Male + Female
    40.         Male2 = Male / Total2 * 100
    41.         Female2 = Female / Total2 * 100
    42.         Total3 = Total2 / Total * 100
    43.         ListBox1.Items.Add(String.Format(fmtstng, Group, Male, Female, Male2, Female2, Total3))
    44.         Pop.Close()
    Last edited by Hack; May 30th, 2007 at 10:45 AM. Reason: Added VB Highlight Tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width