Page tree
Skip to end of metadata
Go to start of metadata

Question from customer.

Dim tmpStr As String
<some code>
If Len(tmpStr) = 0 then
Dim tmpStr As String
<some code>
if( tmpStr.Len() = 0) then
Are there any switch to change to .Length?


I assume the user selected the "Lightweight Object Oriented" option for the translation.  This coding style results in .NET code that is more readable and generally more correct than the standard coding style.

The "Lightweight Object Oriented" option is one of the different coding styles distributed with gmStudio.  It is defined by various .NET code forms associated with <loc and <lob tags in and various rules scripts in the system configuration files.  When you have selected the "Lightweight Object Oriented" option, the tool will automatically use the loc/lob forms in the generated code.  There are hundreds of special coding forms associated with the "Lightweight Object Oriented" coding style and Len is one of them.  
For example, in VBASIC.XML you will find several different forms of expressing the VB6 Len operation:


      <subcode id="Len">
         <loc status="extension" narg="1" code="%1d.Len()"/>  <---- here is where .Len is specified
         <vbn narg="1" code="Strings.Len(%1d)"/>
         <jvs narg="1" code="len(%1d)"/>
         <csh narg="1" code="VBNET.Strings.Len(%1d)"/>


In a "Lightweight Object Oriented" translation, str.Len is an extension method in MigrationSupport.  The Len extension method can be satisfied by a stub authored by the tool or by the implementation distributed in  MigrationSupport.dll.  The reason loc uses str.Len instead of string.Length is that str.Length will throw an exception if str is null, but str.Len will return 0.  This null handling is more consistent with the VB6 Len function and it is better fit for general use in VB.NET.
If you want to handle nulls on your own, and use String.Length in the VB.NET, you use the standard coding style or create a custom coding style for your project.  
The "Lightweight Object Oriented" coding style is activated by the following statement in the translation script:
<ScriptRule id="LightWeightBias" /> 
Removing the above statement from the script will result in translations using the standard code forms.  The standard forms are the ones in the csh/vbn/all tags in the configuration files.
If you wish to create a custom coding style, please read the attached article and contact us for assistance:
1) A recent enhancement to the "Lightweight Object Oriented" coding style is to upgrade VB6.Collection and Scripting.Dictionary to strongly typed generic collections.
2) <ScriptRule id="LightWeightBias" /> rules is deprecated.  You may simply use the <Select SubSystem="loc" directly now.)
Please let me know if this answers your question.


  • No labels