AdvancedHMI Software

General Category => Open Discussion => Topic started by: bachphi on December 27, 2019, 02:47:56 PM

Title: Translating C#
Post by: bachphi on December 27, 2019, 02:47:56 PM
How'd you translate these C# codes to VB? Thanks.
Code: [Select]
private static Settings _instance;
public static Settings Instance
        {
            get { return _instance ?? (_instance = new Settings()); }
        }

Code: [Select]
Private Shared _instance As Settings   
Public Shared ReadOnly Property Instance As Settings
        Get
            If (_instance Is Nothing) Then
                _instance = New Settings
            End If
           
            Return _instance
        End Get
End Property
Title: Re: Translating C#
Post by: Godra on December 27, 2019, 03:08:16 PM
Your 2nd code is a translated 1st code.
Title: Re: Translating C#
Post by: bachphi on December 27, 2019, 04:05:20 PM
Your 2nd code is a translated 1st code.
Thank you for verifying that! I wasn't so sure.
Title: Re: Translating C#
Post by: Godra on December 27, 2019, 06:40:53 PM
Your translation is elegant unlike what online converters offer as a translation for that C# code.
Title: MJ101: Event translation
Post by: bachphi on December 28, 2019, 10:20:57 AM
This is one I keep forgetting:
Code: [Select]
//Add event handlers
                txtSQLServerName.TextChanged += BuildConnectionString;

Code: [Select]
AddHandler txtSQLServerName.TextChanged,  AddressOf BuildConnectionString
Title: MJ102: Form events order
Post by: bachphi on December 28, 2019, 10:36:44 AM
In C# application, any statement/ sub routines that put right after InitializeComponent() will get execute BEFORE form_move and form_load events.

in VB, select view code, select middle drop down Form , select right side drop down New.
Code: [Select]
Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()
        DoEventFirst()

        ' Add any initialization after the InitializeComponent() call.
End Sub