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 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

Ask A Question

Stats

  • Questions 207k
  • Answers 207k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm 99% sure that this is a bug. I have… May 12, 2026 at 9:22 pm
  • Editorial Team
    Editorial Team added an answer Try this: <RemoveExistingProducts After="InstallFinalize"> <![CDATA[&UninstallOlderVersionFeature=3]]> </RemoveExistingProducts> It is the state… May 12, 2026 at 9:22 pm
  • Editorial Team
    Editorial Team added an answer There is no general answer; you'll have to be more… May 12, 2026 at 9:22 pm

Related Questions

I've inherited a legacy VB6 app to maintain, and my vb6 is more than
I'm trying to maintain a Setup Project in Visual Studio 2003 (yes, it's a
We basically need to be able to adjust behaviour at start-up time, by providing
I've got a legacy application which is implemented in a number of Excel workbooks.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.