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 95k
  • Answers 95k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Can't you simply use the Control.Parent property? Granted, it will… May 11, 2026 at 6:55 pm
  • Editorial Team
    Editorial Team added an answer You can: typeof(Foo) .GetField("bar",BindingFlags.Instance|BindingFlags.NonPublic) .SetValue(foo,567); May 11, 2026 at 6:55 pm
  • Editorial Team
    Editorial Team added an answer Is this homework? :) You need to create one or… May 11, 2026 at 6:55 pm

Related Questions

I'm trying to maintain a Setup Project in Visual Studio 2003 (yes, it's a
I've got a legacy application which is implemented in a number of Excel workbooks.
Clarification: this is not about user agent calls to pages, but Classic ASP calling
Guys, I’ve been writing code for 15+ years, but managed to avoid Web Development

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.