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

  • SEARCH
  • Home
  • 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 131561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:07:29+00:00 2026-05-11T06:07:29+00:00

This is probally more of an elegance question than functionality. I am looking for

  • 0

This is probally more of an elegance question than functionality. I am looking for the absolutely safest way to check for an integer from a string and an object,

Using most of the built in functions for this in .net seem to generate a first chance exception, displayed in the Immediate window, and over time they just build up. what are the implications of these exceptions as they don’t seem to affect the operation of the system.

Here are my two attempts, both feel clunky and I know there has to be a better way than using VB.IsDBNull and Integer.TryParse… Or am I just being anal.

(to integer from object)

    Dim nInteger As Integer = 0     If oData Is Nothing OrElse VB.IsDBNull(oData) Then     Else         If bThrowErrorIfInvalid Then         Else             On Error Resume Next         End If         nInteger = CType(oData, Integer)     End If     Return nInteger 

(to integer from string)

    Dim nInteger As Integer = 0     If sText Is Nothing Then     Else         If bThrowErrorIfInvalid Then         Else             On Error Resume Next         End If         Integer.TryParse(sText, nInteger)      End If     Return nInteger 
  • 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. 2026-05-11T06:07:30+00:00Added an answer on May 11, 2026 at 6:07 am

    Whats wrong with using the Integer.TryParse? Thats what it was made for…

    int i = 0; string toTest = 'not number'; if(int.TryParse(toTest, out i)) {    // it worked  } 

    How is that clunky? (C# not VB i know, but same diff)

    EDIT: Added if you want to check from an object as well (since TryParse relies on a string) and im not too sure on how you actually plan to use it. Does that cover your concerns a little since this one method will check for both of your cases?

        static bool TryParseInt(object o, out int i)     {         i = 0;          if (o.GetType() == typeof(int))         {             i = (int)o;             return true;         }         else if (o.GetType() == typeof(string))         {             return int.TryParse(o as string, out i);         }          return false;     } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably more of a check than a question, but is the following
New to iOS coding, so this is probably more of a syntax question than
I know this question will probably provoke more discussion than concrete answers (which I
Searching on Stackoverflow and writing this question has taken more time than the change
This is probably more of a best practices question than a true code question.
This is probably more a Gradle question than a Caliper question, but I am
This is probably more a design or style question: I have just been considering
This is probably more a design or usage question but the main issue is
It's probably more a generic question about database, than a django one but let's
Sorry for the length of this, but more info is usually better than not

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.