Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. FormatExceptionWasUnhandled bug

FormatExceptionWasUnhandled bug

Scheduled Pinned Locked Moved Visual Basic
help
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    amatbrewer
    wrote on last edited by
    #1

    I need help with a bug in a program for a PPC device. The following line of code results in a “FormatExceptionWasUnhandled” error: If Mid(DecimalPart, 1, 1) <> "1" Then DecimalPart is a String variable containing the text “.5”. When I set up a Watch for Mid(DecimalPart, 1, 1) the result is “.” and for Mid(DecimalPart, 1, 1) <> "1" the result is “True”. I am sure I am missing something incredably simple, I just can not figure out what. Thanks,

    David Wilkes

    D 1 Reply Last reply
    0
    • A amatbrewer

      I need help with a bug in a program for a PPC device. The following line of code results in a “FormatExceptionWasUnhandled” error: If Mid(DecimalPart, 1, 1) <> "1" Then DecimalPart is a String variable containing the text “.5”. When I set up a Watch for Mid(DecimalPart, 1, 1) the result is “.” and for Mid(DecimalPart, 1, 1) <> "1" the result is “True”. I am sure I am missing something incredably simple, I just can not figure out what. Thanks,

      David Wilkes

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      The FormatException gets thrown when the formatting for an argument does match the parameter specifications of the method. There's nothing in this code that would throw that exception because the Mid function doesn't expect the string parameter to be in any format. Besides, why are you using the old VB6 Mid function? You should be using the methods in the String class, like

      If DecimalPart.StartsWith("1") Then
      

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      A 1 Reply Last reply
      0
      • D Dave Kreskowiak

        The FormatException gets thrown when the formatting for an argument does match the parameter specifications of the method. There's nothing in this code that would throw that exception because the Mid function doesn't expect the string parameter to be in any format. Besides, why are you using the old VB6 Mid function? You should be using the methods in the String class, like

        If DecimalPart.StartsWith("1") Then
        

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        A Offline
        A Offline
        amatbrewer
        wrote on last edited by
        #3

        Thanks for the reply! This is what I get for being lazy. Using MID? I was using a function someone else wrote (no sense reinventing the wheel right?). I figured out last night that it was part of the line just prior to this that was actually throwing the error (not used to this environment yet). When I stripped it down I figured out it was trying to do Val(".") So I just did what I should have done from the start and write my own function.

        David Wilkes

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups