VBUC Documentation | Mobilize.Net
Mobilize.NetForumsBlogDocumentation Home
  • Mobilize.Net VBUC
  • Introduction
  • Install and Licenses
  • Get Started
  • Migration Guide
  • VBUC Features
  • Mappings Grammar
  • Generated Code
  • Upgrade Options
    • Data Access
    • Grids
    • Microsoft
    • Sheridan
    • Others
    • Code Conversion
    • C# Features
  • Third-party controls
  • Best Practices
  • EWIs
    • Warnings
    • Issues
    • ToDos
    • Notes
  • Issues and Troubleshooting
    • Microsoft.VisualBasic Uses
    • Safe and Unsafe Methods Layer
    • Third Party Components
    • Migration Process
    • Classic ADO Conversion to ADO.NET
    • VB6 and .NET integer division
    • VB6 On Error Statements
    • Running a .NET Core application in a machine with no Visual Studio installed
    • Databases issues
    • Unsupported assemblies on .NET Core and .NET 5
    • Icon Extraction Issues
    • HTTPS sites are not loaded in Windows XP
    • Short-Circuit Boolean Logic in C#
    • Assessment Report Issue
  • Knowledge Base
    • FAQ
      • Does the VBUC support the Sheridan VB 6.0 controls suit?
      • How effective is the Visual Basic Upgrade Companion tool at converting an application's front end?
      • What controls does the Visual Basic Upgrade Companion tool supports?
      • How does the VBUC handle VB6 Collections?
      • Can the VBUC migrate intrinsic VB6 functions and libraries?
      • Where is the source code for the support (helper) classes used by the VBUC?
      • How does the VBUC convert ADO to ADO.NET?
      • Can the Visual Basic Upgrade Companion tool be customized?
      • What are Stubs?
    • How-To
      • App.Config and Database Access
      • Avoid reflection in Hot Paths
      • Convert ESRI ArcGIS Visual Basic 6.0 applications to .NET
      • Drag and Drop Conversion Steps
      • Inserting elements in a ListView
      • String vs StringBuilder
      • Word Automation in VB6 vs .NET
      • Configure default Factory Database provider
      • GetPrivateProfileString Windows API working in migrated code
      • Upgrade projects with shared files
  • Release Notes
Powered by GitBook
On this page

Was this helpful?

  1. Issues and Troubleshooting

VB6 and .NET integer division

Description

In VBUC versions lower than 8.2, the division between two integers is migrated to a non-equivalent statement.

Consider the following VB6 code:

VB6 Code

Dim nLineCnt As Long
Dim nSplit As Long
Dim nItems As Long

'more code'

nItems = CLng(nLineCnt / nSplit)

The code was migrated to this:

.NET Code

int nLineCnt = 0;
int nSplit = 0;
int nItems = 0;

//more code 

nItems = nLineCnt / nSplit;

That division statement is not equivalent in .NET because, for operands of integer type, the / operator returns an integer, consisting of the quotient rounded towards zero.

Consider the following examples:

VB6 Code

Dim nLineCnt As Long
Dim nSplit As Long
Dim nItems As Long

'more code'

nLineCnt = 13
nSplit = 5

nItems = CLng(nLineCnt / nSplit) 'nItems is 3'

The result in VB6 is 3.

.NET Code

int nLineCnt = 13;
int nSplit = 5;
int nItems = 0;

//more code 

nItems = nLineCnt / nSplit; //nItems is 2

The result in .NET is 2.

To obtain a floating-point quotient, one of the operands should be cast as float, double, or decimal type:

.NET Code

int nLineCnt = 13;
int nSplit = 5;
int nItems = 0;

//more code 

nItems = Convert.ToInt32((double)nLineCnt / nSplit); //nItems is 3

The result with the modifications is 3.

The code is now equivalent. Notice the result should be converted to an integer.

PreviousClassic ADO Conversion to ADO.NETNextVB6 On Error Statements

Last updated 4 years ago

Was this helpful?