Skip to content

Using Val(...)

Benjamin edited this page Feb 14, 2021 · 2 revisions

Issue

Using Val(...)

Issue

C# is a more strongly typed language than VB6 was. Use of Val(...) was preferred to convert many data types to a double, an integer, a currency, or whatever.

In C#, Val(...) returns a double, but we use a decimal type for currencies, as well, these don't convert to int types.

Solution

We create helper functions for the various types of Val(...) in which you don't want a double type. Additionally, Val() was often used to convert between types. These functions are overloaded to take most forms of reasonable input.

These should be substituted manually after conversion, as the converter can't tell what you intended at this time.

Examples

  • Val(...) - Already returned a double
  • ValI(...) - returns integer
  • ValD(...) - returns decimal
  • ValF(...) - returns a float
  • ValL(...) - returns a long

Rationale

Rather than spend the time to attempt to deep dive and probably get the datatype wrong anyway, the converter will leave Val(...) calls alone. If the C# compiler objects to the typing, due to stronger restrictions, simply use the appropriate replacement from above.

Again, our philosophy is to do 80%-90% of the work, not 100%. We let the C# compiler find the issues, then it's usually obvious which type it needs.

Clone this wiki locally