예제 #1
0
 private void btnLoad_Click(object sender, EventArgs e)
 {
     try
     {
         openFileSource.Filter = "Basic Files (*.bas)|*.bas|Class Files (*.cls)|*.cls|Form Files (*.frm)|*.frm|All files (*.*)|*.*";
         DialogResult result = openFileSource.ShowDialog();
         if (result == DialogResult.OK)
         {
             string source = File.ReadAllText(openFileSource.FileName, Encoding.Default);
             SourceEditor.Text = ConverterEngine.FilterSource(source);
         }
         SourceEditor.Focus();
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.ToString());
         MessageBox.Show("It's not possible to open the dialog. \n\nDetails: " + ex.Message, "VB Converter", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #2
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;
            }
        }