Jump to content
aldebaran

Migrate properties from VB6 to C#

Recommended Posts

Migration of properties doesn’t work. What do we have to change, for migrating successful properties?
Original Code (one example of many):

Property:

Public Property Get Duty_lmt(ByVal iIndex As Integer) As Double
    Duty_lmt = mvarLmt(iIndex)
End Property
Public Property Let Duty_lmt(ByVal iIndex As Integer, ByVal vData As Double)
    mvarLmt(iIndex) = vData
End Property

Setting/Getting Property:

For iLoop = 1 To 2
        If .Duty_T1 <> NOVALUE And .Duty_T2 <> NOVALUE And .Duty_T3 <> NOVALUE And .Duty_T4 <> NOVALUE Then
            If iLoop = 1 Then
                .Duty_lmt(iLoop) = (.Duty_T1 + .Duty_T2) / 2
            Else
                .Duty_lmt(iLoop) = (.Duty_T3 + .Duty_T4) / 2
            End If
        Else
            If .Duty_T1 = NOVALUE Then
                .Duty_lmt(1) = .Duty_T2
            Else
                .Duty_lmt(1) = .Duty_T1
            End If
            If .Duty_T3 = NOVALUE Then
                .Duty_lmt(2) = .Duty_T4
            Else
                .Duty_lmt(2) = .Duty_T3
            End If
        End If
        .Duty_Dens(iLoop) = Densitet(.Duty_lmt(iLoop))
        .Duty_Spech(iLoop) = Kapacitivitet(.Duty_lmt(iLoop))
        .Duty_Cond(iLoop) = Ledntal(.Duty_lmt(iLoop))
        .Duty_visk(iLoop) = Dynvisk(.Duty_lmt(iLoop))
        .Duty_Pran(iLoop) = Prandtl(.Duty_lmt(iLoop))

 

Migrating this we get following result:

Properties:

public double GetLmt(int iIndex)
{
    return mvarLmt[iIndex - 1];
}
public void SetLmt(int iIndex, double value)
{
    mvarLmt[iIndex - 1] = value;
}


Properties are renamed, e.g. (All Properties has in migration the same pattern, this is one of many examples):

And they are mapped in a file named "ExtendedMappings.xml":
<Mapping DotNetTypeName='Calculators.CoilDuty.Set' VB6MemberName='lmt'>set_lmt</Mapping>
<Mapping DotNetTypeName='Calculators.CoilDuty.Get' VB6MemberName='lmt'>get_lmt</Mapping>

In code both pattern are used:

if (mvarDuty.T1 == CalcSupport.NOVALUE)

                                  {

                                        mvarDuty. set_lmt (1, mvarDuty.T2);

                                  }

                                  else

                                  {

                                        mvarDuty.set_lmt(1, mvarDuty.T1);

                                  }

                                  if (mvarDuty.T3 == CalcSupport.NOVALUE)

                                  {

                                        mvarDuty.set_lmt(2, mvarDuty.T4);

                                  }

                                  else

                                  {

                                        mvarDuty.set_lmt(2, mvarDuty.T3);

                                  }

                           }

                           mvarDuty.set_Dens(iLoop, Waterfunctions.Densitet(mvarDuty.GetGLmt(iLoop)));

                           mvarDuty.set_Spech(iLoop, Waterfunctions.Kapacitivitet(mvarDuty.GetGetGetLmt(iLoop)));

                           mvarDuty.set_Cond(iLoop, Waterfunctions.Ledntal(mvarDuty.GetGetGetGetLmt(iLoop)));

                           mvarDuty.set_visk(iLoop, Waterfunctions.Dynvisk(mvarDuty.GetGetGetGetGetLmt(iLoop)));

                           mvarDuty.set_Pran(iLoop, Waterfunctions.Prandtl(mvarDuty.GetGetGetGetGetGetLmt(iLoop)));

Questions:

CoilDuty (mvarDuty) does not contain a definiton for set_lmt. CoilDuty does contain a definition for SetLmt. Why set_lmt is used? What is the mapping in ExtendedMappings.xml for?

Why is "GetLmt" called with growing number of "Get"?

mvarDuty.set_Dens(iLoop, Waterfunctions.Densitet(mvarDuty.GetGLmt(iLoop)));

                           mvarDuty.set_Spech(iLoop, Waterfunctions.Kapacitivitet(mvarDuty.GetGetGetLmt(iLoop)));

                           mvarDuty.set_Cond(iLoop, Waterfunctions.Ledntal(mvarDuty.GetGetGetGetLmt(iLoop)));

                           mvarDuty.set_visk(iLoop, Waterfunctions.Dynvisk(mvarDuty.GetGetGetGetGetLmt(iLoop)));

                           mvarDuty.set_Pran(iLoop, Waterfunctions.Prandtl(mvarDuty.GetGetGetGetGetGetLmt(iLoop)));

Share this post


Link to post
Share on other sites

Hi Aldebaran,

I created a single vb6 project with a class having a similar property definition as you indicates and it doesn't compile: The vb6 compiler doesn't like having two property methods Get and Let with parameters. Do you mind if share with me (via email) the file where Duty property is defined? Also, which version of the VBUC you're using.

Regards,

OlmanQ

 

Share this post


Link to post
Share on other sites

The ExtendedProperties.xml is mostly a report that the VBUC generates about some of the changes that it applies. I think it is also used by the ReflectionHelper class as an aid when trying to dynamically invoke a member.

Share this post


Link to post
Share on other sites

Hi Aldebaran,

I recommend to run the migration again and running the pre-process step before 

We would like you to run the migration again from scratch, making sure you have all the references right and you run the preprocess.  Please make sure the ADODB reference is resolved and make sure the output folder is empty before running the migration process: Go to the "Upgrade area", right click on the project and select "Preprocess Project" option, then, when the Preprocess ends, you can upgrade the code again.

 

image.png

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Terms of Use