private void btnExecute_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; try { ClearData(false); InitNetDesigner(); int beginline = 0, endline = 0; MyForm form = new MyForm(); bool formEnd = false; bool inGroupBox = false, inTabControl = false; string s = ""; //object parentObj = new object(); //object priorParentObj = new object(); for (int i = 0; i < rtbVB.Lines.Count(); i++) { mylinenumer = i; // this is used for debugging if (inGroupBox) // solves issue of the first control of the group box being skipped { inGroupBox = false; // reset the flag i--; } else if (inTabControl) { inTabControl = false; // reset the flag i--; } else { s = rtbVB.Lines[i]; } if (s.Contains("Option Explicit")) { for (int j = i; j < rtbVB.Lines.Count(); j++) { codeText = codeText + rtbVB.Lines[j] + "\r\n"; } break; } if (s.Contains("Begin VB.Form")) { beginline = i; do { i++; s = rtbVB.Lines[i]; if (i > beginline && s.Contains("Begin")) { formEnd = true; } }while (!formEnd && i < rtbVB.Lines.Count()); endline = i; form = form.CreateForm(beginline, endline, rtbVB.Lines); if (form == null) { return; // bad parsing, exit } txtFormName.Text = form.General.Name; parentArray.Add((MyForm)form); } if (s.Contains("Begin VB.Frame ")) { beginline = i; do { i++; s = rtbVB.Lines[i]; if (s.Contains("BeginProperty")) { SkipProperties(i, s); } } while (i < rtbVB.Lines.Count() && s.Trim().Length >= 4 && !s.Trim().Substring(0, 4).Equals("End ") && (s.Trim().Length >= 6 && !s.Trim().Substring(0, 6).Equals("Begin "))); //while (!s.Trim().Equals("End") && i < rtbVB.Lines.Count() && controlEnd); endline = i; MyGroupBox o = new MyGroupBox(); o = o.Create(beginline, endline, rtbVB.Lines); output = o.Convert(o, output, controlVariableArray, controlFormArray, controlGBArray, parentArray[parentArray.Count - 1]); parentArray.Add(o); inGroupBox = true; } else if (s.Contains("Begin VB.CommandButton")) { beginline = i; do { i++; s = rtbVB.Lines[i]; if (s.Contains("BeginProperty")) { SkipProperties(i, s); } }while (i < rtbVB.Lines.Count() && s.Trim().Length >= 4 && !s.Trim().Substring(0, 4).Equals("End ")); endline = i; MyButton button = new MyButton(); button = button.CreateButton(beginline, endline, rtbVB.Lines); output = button.ConvertButton(button, output, controlVariableArray, controlFormArray, controlGBArray, parentArray[parentArray.Count - 1]); } else if (s.Contains("Begin VB.CheckBox")) { beginline = i; do { i++; s = rtbVB.Lines[i]; if (s.Contains("BeginProperty")) { SkipProperties(i, s); } } while (i < rtbVB.Lines.Count() && s.Trim().Length >= 4 && !s.Trim().Substring(0, 4).Equals("End ")); endline = i; MyCheckbox c = new MyCheckbox(); c = c.CreateCheckbox(beginline, endline, rtbVB.Lines); output = c.ConvertCheckbox(c, output, controlVariableArray, controlFormArray, controlGBArray, parentArray[parentArray.Count - 1]); } else if (s.Contains("Begin VB.Label")) { beginline = i; do { i++; s = rtbVB.Lines[i]; if (s.Contains("BeginProperty")) { SkipProperties(i, s); } } while (i < rtbVB.Lines.Count() && s.Trim().Length >= 4 && !s.Trim().Substring(0, 4).Equals("End ")); endline = i; MyLabel l = new MyLabel(); l = l.Create(beginline, endline, rtbVB.Lines); output = l.Convert(l, output, controlVariableArray, controlFormArray, controlGBArray, parentArray[parentArray.Count - 1]); } else if (s.Contains("Begin VB.TextBox")) { beginline = i; do { i++; s = rtbVB.Lines[i]; if (s.Contains("BeginProperty")) { SkipProperties(i, s); } }while (i < rtbVB.Lines.Count() && s.Trim().Length >= 4 && !s.Trim().Substring(0, 4).Equals("End ")); endline = i; MyTextbox o = new MyTextbox(); o = o.Create(beginline, endline, rtbVB.Lines); output = o.Convert(o, output, controlVariableArray, controlFormArray, controlGBArray, parentArray[parentArray.Count - 1], datasourceArray); } else if (s.Contains("Begin MSDBCtls.DBCombo")) { beginline = i; do { i++; s = rtbVB.Lines[i]; if (s.Contains("BeginProperty")) { SkipProperties(i, s); } }while (i < rtbVB.Lines.Count() && s.Trim().Length >= 4 && !s.Trim().Substring(0, 4).Equals("End ")); endline = i; MyCombobox o = new MyCombobox(); o = o.Create(beginline, endline, rtbVB.Lines); output = o.Convert(o, output, controlVariableArray, controlFormArray, controlGBArray, parentArray[parentArray.Count - 1], datasourceArray); } else if (s.Contains("Begin VB.ListBox") || s.Contains("Begin MSDBCtls.DBList")) { beginline = i; do { i++; s = rtbVB.Lines[i]; if (s.Contains("BeginProperty")) { SkipProperties(i, s); } }while (i < rtbVB.Lines.Count() && s.Trim().Length >= 4 && !s.Trim().Substring(0, 4).Equals("End ")); endline = i; MyListbox o = new MyListbox(); o = o.Create(beginline, endline, rtbVB.Lines); output = o.Convert(o, output, controlVariableArray, controlFormArray, controlGBArray, parentArray[parentArray.Count - 1]); } else if (s.Contains("Begin TabDlg.SSTab ")) // tab control { beginline = i; do { i++; s = rtbVB.Lines[i]; if (s.Contains("BeginProperty")) { SkipProperties(i, s); } } while (i < rtbVB.Lines.Count() && s.Trim().Length >= 4 && !s.Trim().Substring(0, 4).Equals("End ") && (s.Trim().Length >= 6 && !s.Trim().Substring(0, 6).Equals("Begin "))); endline = i; MyTabControl o = new MyTabControl(); o = o.Create(beginline, endline, rtbVB.Lines); output = o.Convert(o, output, controlVariableArray, controlFormArray, controlGBArray, parentArray[parentArray.Count - 1]); parentArray.Add(o); inTabControl = true; // not sure if we need another variable specifically for tabcontrols. } else if (s.Contains("Begin MSDBGrid.DBGrid")) { beginline = i; do { i++; s = rtbVB.Lines[i]; if (s.Contains("BeginProperty")) { SkipProperties(i, s); } }while (i < rtbVB.Lines.Count() && s.Trim().Length >= 4 && !s.Trim().Substring(0, 4).Equals("End ")); endline = i; MyDatagridview o = new MyDatagridview(); o = o.Create(beginline, endline, rtbVB.Lines); output = o.Convert(o, output, controlVariableArray, controlFormArray, controlGBArray, parentArray[parentArray.Count - 1]); } else if (s.Contains("Begin VB.OptionButton")) { beginline = i; do { i++; s = rtbVB.Lines[i]; if (s.Contains("BeginProperty")) { SkipProperties(i, s); } }while (i < rtbVB.Lines.Count() && s.Trim().Length >= 4 && !s.Trim().Substring(0, 4).Equals("End ")); endline = i; MyRadioButton o = new MyRadioButton(); o = o.Create(beginline, endline, rtbVB.Lines); output = o.Convert(o, output, controlVariableArray, controlFormArray, controlGBArray, parentArray[parentArray.Count - 1]); } else if (s.Contains("Begin ComctlLib.ListView")) { beginline = i; do { i++; s = rtbVB.Lines[i]; if (s.Contains("BeginProperty")) { SkipProperties(i, s); } }while (i < rtbVB.Lines.Count() && s.Trim().Length >= 4 && !s.Trim().Substring(0, 4).Equals("End ")); endline = i; MyDatagridview o = new MyDatagridview("Begin ComctlLib.ListView"); o = o.Create(beginline, endline, rtbVB.Lines); output = o.Convert(o, output, controlVariableArray, controlFormArray, controlGBArray, parentArray[parentArray.Count - 1]); } else if (s.Contains("Begin")) // catches and removes unsupported things. { bool knownControl = false; foreach (string ctrl in controlTypeList) { if (s.Contains(ctrl)) { knownControl = true; } } do { i++; s = rtbVB.Lines[i]; if (s.Contains("BeginProperty")) { SkipProperties(i, s); } } while (!knownControl && i < rtbVB.Lines.Count() && s.Trim().Length >= 4 && !s.Trim().Substring(0, 4).Equals("End ")); } if (s.Trim().Equals("End") && rtbVB.Lines[i - 1].Trim().Equals("End")) // two Ends alone means end of a parent { // end of group box if (parentArray.Count > 0) { parentArray.RemoveAt(parentArray.Count - 1); //pop } foreach (string ctrlstr in controlGBArray) { output += VBtoNET.padding + ctrlstr; } controlGBArray = new List <string>(); } } // set up form output = form.ConvertForm(form, output, controlFormArray); // end the file EndDesigner(); this.Cursor = Cursors.Arrow; Clipboard.SetText(rtbNET.Text); } catch (Exception ex) { this.Cursor = Cursors.Arrow; MessageBox.Show("Exception in VB6 Parsing line: " + this.mylinenumer.ToString() + " " + ex.Message); } }
private void btnExecute_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; //try { rtbNET.Text = ""; InitNetDesigner(); int beginline = 0, endline = 0; MyForm form = new MyForm(); bool formEnd = false; bool inGroupBox = false, inTabControl = false; string s = ""; //object parentObj = new object(); //object priorParentObj = new object(); for (int i = 0; i < rtbVB.Lines.Count(); i++) { if (inGroupBox) // solves issue of the first control of the group box being skipped { inGroupBox = false; // reset the flag i--; } else if (inTabControl) { inTabControl = false; // reset the flag i--; } else { s = rtbVB.Lines[i]; } if (s.Contains("Begin VB.Form")) { beginline = i; do { i++; s = rtbVB.Lines[i]; if (i > beginline && s.Contains("Begin")) { formEnd = true; } }while (!formEnd && i < rtbVB.Lines.Count()); endline = i; form = form.CreateForm(beginline, endline, rtbVB.Lines); if (form.General == null || String.IsNullOrEmpty(form.General.Name)) { MessageBox.Show("Trouble parsing VB form, did you input a VB .frm file?"); return; } txtFormName.Text = form.General.Name; parentArray.Add((MyForm)form); } if (s.Contains("Begin VB.Frame ")) { beginline = i; do { i++; s = rtbVB.Lines[i]; if (s.Contains("BeginProperty")) { SkipProperties(i, s); } } while (i < rtbVB.Lines.Count() && s.Trim().Length >= 4 && !s.Trim().Substring(0, 4).Equals("End ") && (s.Trim().Length >= 6 && !s.Trim().Substring(0, 6).Equals("Begin "))); //while (!s.Trim().Equals("End") && i < rtbVB.Lines.Count() && controlEnd); endline = i; MyGroupBox o = new MyGroupBox(); o = o.Create(beginline, endline, rtbVB.Lines); output = o.Convert(o, output, controlVariableArray, controlFormArray, controlGBArray, parentArray[parentArray.Count - 1]); parentArray.Add(o); inGroupBox = true; } else if (s.Contains("Begin VB.CommandButton")) { beginline = i; do { i++; s = rtbVB.Lines[i]; if (s.Contains("BeginProperty")) { SkipProperties(i, s); } }while (i < rtbVB.Lines.Count() && s.Trim().Length >= 4 && !s.Trim().Substring(0, 4).Equals("End ")); endline = i; MyButton button = new MyButton(); button = button.CreateButton(beginline, endline, rtbVB.Lines); output = button.ConvertButton(button, output, controlVariableArray, controlFormArray, controlGBArray, parentArray[parentArray.Count - 1]); } else if (s.Contains("Begin VB.CheckBox")) { beginline = i; do { i++; s = rtbVB.Lines[i]; if (s.Contains("BeginProperty")) { SkipProperties(i, s); } } while (i < rtbVB.Lines.Count() && s.Trim().Length >= 4 && !s.Trim().Substring(0, 4).Equals("End ")); endline = i; MyCheckbox c = new MyCheckbox(); c = c.CreateCheckbox(beginline, endline, rtbVB.Lines); output = c.ConvertCheckbox(c, output, controlVariableArray, controlFormArray, controlGBArray, parentArray[parentArray.Count - 1]); } else if (s.Contains("Begin VB.Label")) { beginline = i; do { i++; s = rtbVB.Lines[i]; if (s.Contains("BeginProperty")) { SkipProperties(i, s); } } while (i < rtbVB.Lines.Count() && s.Trim().Length >= 4 && !s.Trim().Substring(0, 4).Equals("End ")); endline = i; MyLabel l = new MyLabel(); l = l.Create(beginline, endline, rtbVB.Lines); output = l.Convert(l, output, controlVariableArray, controlFormArray, controlGBArray, parentArray[parentArray.Count - 1]); } else if (s.Contains("Begin VB.TextBox")) { beginline = i; do { i++; s = rtbVB.Lines[i]; if (s.Contains("BeginProperty")) { SkipProperties(i, s); } }while (i < rtbVB.Lines.Count() && s.Trim().Length >= 4 && !s.Trim().Substring(0, 4).Equals("End ")); endline = i; MyTextbox o = new MyTextbox(); o = o.Create(beginline, endline, rtbVB.Lines); output = o.Convert(o, output, controlVariableArray, controlFormArray, controlGBArray, parentArray[parentArray.Count - 1]); } else if (s.Contains("Begin MSDBCtls.DBCombo")) { beginline = i; do { i++; s = rtbVB.Lines[i]; if (s.Contains("BeginProperty")) { SkipProperties(i, s); } }while (i < rtbVB.Lines.Count() && s.Trim().Length >= 4 && !s.Trim().Substring(0, 4).Equals("End ")); endline = i; MyCombobox o = new MyCombobox(); o = o.Create(beginline, endline, rtbVB.Lines); output = o.Convert(o, output, controlVariableArray, controlFormArray, controlGBArray, parentArray[parentArray.Count - 1]); } else if (s.Contains("Begin VB.ListBox") || s.Contains("Begin MSDBCtls.DBList")) { beginline = i; do { i++; s = rtbVB.Lines[i]; if (s.Contains("BeginProperty")) { SkipProperties(i, s); } }while (i < rtbVB.Lines.Count() && s.Trim().Length >= 4 && !s.Trim().Substring(0, 4).Equals("End ")); endline = i; MyListbox o = new MyListbox(); o = o.Create(beginline, endline, rtbVB.Lines); output = o.Convert(o, output, controlVariableArray, controlFormArray, controlGBArray, parentArray[parentArray.Count - 1]); } else if (s.Contains("Begin TabDlg.SSTab ")) // tab control { beginline = i; do { i++; s = rtbVB.Lines[i]; if (s.Contains("BeginProperty")) { SkipProperties(i, s); } } while (i < rtbVB.Lines.Count() && s.Trim().Length >= 4 && !s.Trim().Substring(0, 4).Equals("End ") && (s.Trim().Length >= 6 && !s.Trim().Substring(0, 6).Equals("Begin "))); endline = i; MyTabControl o = new MyTabControl(); o = o.Create(beginline, endline, rtbVB.Lines); output = o.Convert(o, output, controlVariableArray, controlFormArray, controlGBArray, parentArray[parentArray.Count - 1]); parentArray.Add(o); inTabControl = true; // not sure if we need another variable specifically for tabcontrols. } else if (s.Contains("Begin MSDBGrid.DBGrid")) { beginline = i; do { i++; s = rtbVB.Lines[i]; if (s.Contains("BeginProperty")) { SkipProperties(i, s); } }while (i < rtbVB.Lines.Count() && s.Trim().Length >= 4 && !s.Trim().Substring(0, 4).Equals("End ")); endline = i; MyDatagridview o = new MyDatagridview(); o = o.Create(beginline, endline, rtbVB.Lines); output = o.Convert(o, output, controlVariableArray, controlFormArray, controlGBArray, parentArray[parentArray.Count - 1]); } else if (s.Contains("Begin")) // catches and removes unsupported things. { bool knownControl = false; foreach (string ctrl in controlTypeList) { if (s.Contains(ctrl)) { knownControl = true; } } do { i++; s = rtbVB.Lines[i]; if (s.Contains("BeginProperty")) { SkipProperties(i, s); } } while (!knownControl && i < rtbVB.Lines.Count() && s.Trim().Length >= 4 && !s.Trim().Substring(0, 4).Equals("End ")); } if (s.Trim().Equals("End") && rtbVB.Lines[i - 1].Trim().Equals("End")) // two Ends alone means end of a parent { if (i > 1500 || parentArray.Count == 1) { string foo = "bar"; } // end of group box parentArray.RemoveAt(parentArray.Count - 1); //pop foreach (string ctrlstr in controlGBArray) { output += VBtoNET.padding + ctrlstr; } controlGBArray = new List <string>(); } } // set up form output = form.ConvertForm(form, output, controlFormArray); if (String.IsNullOrEmpty(output)) { MessageBox.Show("Trouble parsing VB form, did you input a VB .frm file?"); return; } // end the file EndDesigner(); this.Cursor = Cursors.Arrow; //} catch (Exception ex) { // this.Cursor = Cursors.Arrow; // MessageBox.Show("Exception in VB6 Parsing: " + ex.Message); //} }