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 116605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:12:16+00:00 2026-05-11T03:12:16+00:00

I need to maintain a legacy VB.NET web application. Data typing is, I would

  • 0

I need to maintain a legacy VB.NET web application. Data typing is, I would say, inconsistent. Especially, there are data that is stored sometimes as integers and sometimes as strings, and I have to parse strings to integers reliably. If parsing goes wrong it should always return 0.

The problem is, I can’t use any of the .NET/VB.NET parsing functions for this, but I have to rely on a self-made function.

Could I use a one-liner standard framework call to do every String-to-Integer parsing task?

Let’s say there is a string that can be null, empty, contain an integer representation like ’10’ or contain something else.

I have tried these with an empty input string ”:

CType(string, Integer) -> Conversion from string '' to type 'Integer' is not valid. Convert.ToInt32(string) -> Input string was not in a correct format. Integer.Parse(string) -> Input string was not in a correct format. CInt(string) -> Conversion from string '' to type 'Integer' is not valid. Val(string) -> Success! 

But even Val can fail. The surefire way is to call a self-made function:

   Public Function ToInteger(ByVal s As String) As Integer          s = Trim(s)         Dim i As Integer          Try             i = Val(s)         Catch ex As Exception             i = 0         End Try          Return i      End Function 

I think this sucks. This is bad because:

  • I’m trying to parse strings to integers! This is not rocket science, even if semantics are involved
  • Self-made standards do not stick very well. Somewhere in the code you will always find broken standard framework solutions

As a result there are unnecessary bugs in the software. And I accuse the standard framework for this. Unless, of course a better solution is found 🙂


Thanks for all the answers. Int32.TryParse is perfect here.

But if you have to cast the input to a string first, the cast can fail. Like when reading from a database object with a possible DBNull value.

  • 1 1 Answer
  • 3 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-11T03:12:16+00:00Added an answer on May 11, 2026 at 3:12 am

    Use Int32.TryParse and ignore the return value – just use the value in the out parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm in a very bad situation: I need to maintain asp.net web application hosted
I have an Panel control that I need to maintain position across postbacks. I
I need to maintain session information between REST calls to an Apache server. Not
Have a use case wherein need to maintain a connection open to a database
I have a table of records in mySql. I need to maintain an order
Large datasets, millions of records, need special programming to maintain speed in DBGrids. I
I have a list wrapper that maintains two Tstringlists and a TClassList I need
Need a function that takes a character as a parameter and returns true if
I have to maintain some legacy codes,parts of it look like the following: /*
I need to do some refactoring in Java, and I need to maintain some

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.