Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 694807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:53:40+00:00 2026-05-14T02:53:40+00:00

I am getting the error Format Exception was unhandled at Do While objectReader.Peek <>

  • 0

I am getting the error “Format Exception was unhandled at “Do While objectReader.Peek <> -1
” and after. any help would be wonderful.

'Date: Class    03/20/2010
'Program Purpose:  When code is executed data will be pulled from a text file
'that contains the named storms to find the average number of storms during the time
'period chosen by the user and to find the most active year. between the range of
'years 1990 and 2008 

Option Strict On

Public Class frmHurricane

    Private _intNumberOfHuricanes As Integer = 5
    Public Shared _intSizeOfArray As Integer = 7
    Public Shared _strHuricaneList(_intSizeOfArray) As String
    Private _strID(_intSizeOfArray) As String
    Private _decYears(_intSizeOfArray) As Decimal
    Private _decFinal(_intSizeOfArray) As Decimal
    Private _intNumber(_intSizeOfArray) As Integer

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As             System.EventArgs) Handles MyBase.Load
        'The frmHurricane load event reads the Hurricane text file and
        'fill the combotBox object with the data.

        'Initialize an instance of the StreamReader Object and declare variable page 675 on the book
        Dim objectReader As IO.StreamReader
        Dim strLocationAndNameOfFile As String = "C:\huricanes.txt"
        Dim intCount As Integer = 0
        Dim intFill As Integer
        Dim strFileError As String = "The file is not available.  Please restart application when available"

        'This is where we code the file if it exist.
        If IO.File.Exists(strLocationAndNameOfFile) Then
            objectReader = IO.File.OpenText(strLocationAndNameOfFile)
            'Read the file line by line until the file is complete
            Do While objectReader.Peek <> -1
                **_strHuricaneList(intCount) = objectReader.ReadLine()
                _strID(intCount) = objectReader.ReadLine()
                _decYears(intCount) = Convert.ToDecimal(objectReader.ReadLine())
                _intNumber(intCount) = Convert.ToInt32(objectReader.ReadLine())
                intCount += 1**
            Loop
            objectReader.Close()

        'With any luck the data will go to the Data Box
        For intFill = 0 To (_strID.Length - 1)
            Me.cboByYear.Items.Add(_strID(intFill))
        Next
    Else
        MsgBox(strFileError, , "Error")
        Me.Close()

    End If
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:53:40+00:00Added an answer on May 14, 2026 at 2:53 am

    Instead of using Convert.ToDecimal an Convert.ToInt32, try using Decimal.TryParse() and Int32.TryParse(). If they don’t parse, you know your file isn’t setup correctly. If they do parse, then you’ve loaded the value into a variable for your use.

    EDIT:

    Use it like this.

    Dim myDecimal As Decimal
    
    If Decimal.TryParse(objectReader.ReadLine(), myDecimal) Then
        'your string successfully parsed. Use myDecimal however you want. It has the parsed value.
    Else
        'your string is not a decimal. Now that you know that, you can handle this situation here without having to catch an exception.
    End If
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting a FormatException: Input string was not in a correct format error that
I'm getting an error when my application starts. It appears to be after it's
I am getting An unhandled exception of type 'System.StackOverflowException' occurred in System.Data.dll in my
Hello while trying to connect to a derby db i'm getting ERROR XJ040: Failed
Checkbox[,] checkArray = new Checkbox[2, 3]{{checkbox24,checkboxPref1,null}, {checkbox23,checkboxPref2,null}}; I am getting error . How do
Anyone getting this error when using the new free chart controls MS bought from
I am getting this error now that I hit version number 1.256.0: Error 4
I am getting this error when trying to run internet information services on a
I'm getting an error message when I try to build my project in eclipse:
I'm getting an error whenever I load Management Studio or open a folder in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.