Beispiel #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(DestinationEditor.Text))
                {
                    MessageBox.Show("There's no source code to save !", "VB Converter", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    saveFileDestination.Filter = "C# Files (*.cs)|*.cs|Text Files (*.txt)|*.frm|All files (*.*)|*.*";
                    DialogResult result = saveFileDestination.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        File.WriteAllText(saveFileDestination.FileName, DestinationEditor.Text);
                        MessageBox.Show(string.Format("Conversion saved !\n\nCaminho: {0}", saveFileDestination.FileName), "VB Converter", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }

                DestinationEditor.Focus();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                MessageBox.Show("It's not possible to save! \n\nDetails: " + ex.Message, "VB Converter", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #2
0
        private void cboLanguage_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                DestinationEditor.Clear();

                if (cboLanguage.Text == "VB .NET")
                {
                    SyntaxHandler.SetVisualBasic(SourceEditor);
                }
                else
                {
                    SyntaxHandler.SetCSharp(SourceEditor);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                MessageBox.Show("It's not possible to select the destination language. \n\nDetails: " + ex.Message, "VB Converter", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #3
0
        private void btnConvert_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(SourceEditor.Text))
                {
                    MessageBox.Show("There's no source code to convert !", "VB Converter", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    SourceEditor.Focus();
                }
                else
                {
                    this.Cursor = Cursors.WaitCursor;

                    string          source = SourceEditor.Text;
                    ConverterEngine engine = new ConverterEngine(LanguageVersion.VB6, source);
                    if (cboLanguage.Text == "VB .NET")
                    {
                        engine.ResultType = DestinationLanguage.VisualBasic;
                    }
                    bool   success = engine.Convert();
                    string result  = success ? engine.Result : engine.GetErrors();
                    DestinationEditor.Text = result;
                    DestinationEditor.Focus();

                    if (engine.Errors.Count > 0)
                    {
                        MessageBox.Show("It's not possible to convert the the source code due to compile errors!\n\nCheck the sintax.", "VB Converter", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                MessageBox.Show("It's not possible to convert the source code. \n\nDetails: " + ex.Message, "VB Converter", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }