Support Statement: Modifying the migration of a VB6 Intrinsic Function (e.g., Split)
One of our default metalang files (vbmethods.xml
) has this definition of the VB6Â Split method:
<method id="Split" type="String[]" opcode="VBF.112"> <argument id="Expression" type="String" status="ByVal"/> <argument id="Delimiter" type="String" status="ByVal" optional=" "/> <argument id="Limit" type="Integer" status="ByVal" optional="-1"/> <argument id="Compare" type="VbCompareMethod" status="ByVal" optional="1"/> </method>
It indicates that the last three args are optional.Â
Another default metalang file (VBASIC.XML
) has these standard target patterns for Split:
Â
<subcode id="Split"> <loc status="extension" role="function" narg="4" code="%1d.Split(%2d)"/> <vbn role="function" narg="4" code="Strings.Split(%1d,%2d,%3d,%4d)"/> <jvs role="function" narg="4" code="Split(%1d,%2d)"/> <csh role="function" narg="4" code="VBNET.Strings.Split(%1d,%2d,%3d,%4d)"/> </subcode>
Â
Notice that the loc
form explicitly omits all arguments but the second one. Â Â
Â
Our MigrationSupport.dll has overloaded extension methods that support different number of arguments.
To take advantage of these overloaded extension methods you need to use a custom metalang configuration.  You can activate a custom metalang file from the Settings form. Find vbasic.xml
in the Metalang files list, then right click and select Activate
. This will copy the default file to your user folder and modify the metalang script to reference that copy. Repeat the process for vbmethods.xml
.
Next, open the usr/VBASIC.XML
file and change the loc
target pattern for Split
. Use %o
notation in a target pattern to tell the tool to only emit an actual argument if one was specified in the source. For example:
<loc status="extension" role="function" narg="4" code="%1d.Split(%2d,%3o,%4o)"/>
Â
Note the above changes will author a ",," malformation if actual arg 4 is given and arg 3 is omitted in a call. Normally, this is not a big issue; however if it is, custom handling of the Split
operation will be needed to select different patterns.
Then in usr/vbmethods.xml
mark the last two arguments as overloaded:
<method id="Split" type="String[]" opcode="VBF.112"> <argument id="Expression" type="String" status="ByVal"/> <argument id="Delimiter" type="String" status="ByVal" optional=" "/> <argument id="Limit" type="Integer" status="ByVal" optional="DEF.Overload"/> changed <argument id="Compare" type="VbCompareMethod" status="ByVal" optional="DEF.Overload"/> changed </method>
Use snapshot, translate, compare to check the result. Â