messages
listlengths
2
2
category
stringclasses
40 values
vb6
stringlengths
58
803
cs
stringlengths
86
1.14k
[ { "role": "user", "content": "Migrate this VB6 code to C# preserving functionality:\n\n```vb6\nPrivate Sub ConvertValues()\n Dim v As Variant\n Dim s As String\n Dim i As Integer\n Dim d As Double\n Dim dt As Date\n Dim l As Long\n Dim b As Boolean\n v = \"42\"\n s = CStr(v)\n ...
conversions
Private Sub ConvertValues() Dim v As Variant Dim s As String Dim i As Integer Dim d As Double Dim dt As Date Dim l As Long Dim b As Boolean v = "42" s = CStr(v) i = CInt(v) d = CDbl(v) l = CLng(v) b = CBool(v) dt = CDate("2024-01-01") End Sub
private void ConvertValues() { object v = "42"; string s = v.ToString(); int i = Convert.ToInt32(v); double d = Convert.ToDouble(v); long l = Convert.ToInt64(v); bool b = Convert.ToBoolean(v); DateTime dt = Convert.ToDateTime("2024-01-01"); }
[ { "role": "user", "content": "Translate this VB6 code to C# with identical functionality:\n\n```vb6\nPrivate Sub ProcessString()\n Dim text As String\n Dim upperText As String\n Dim trimmedText As String\n Dim length As Integer\n text = \" Hello World \"\n upperText = UCase(text)\n tr...
strings
Private Sub ProcessString() Dim text As String Dim upperText As String Dim trimmedText As String Dim length As Integer text = " Hello World " upperText = UCase(text) trimmedText = Trim(text) length = Len(text) MsgBox "Upper: " & upperText & vbCrLf & "Trimmed: " & trimmedText & vbCr...
private void ProcessString() { string text = " Hello World "; string upperText = text.ToUpper(); string trimmedText = text.Trim(); int length = text.Length; MessageBox.Show("Upper: " + upperText + " Trimmed: " + trimmedText + " Length: " + length); }
[ { "role": "user", "content": "Convert the following VB6 code to equivalent C#:\n\n```vb6\nPrivate Sub ConfigureForm()\n With Me\n .Caption = \"My Application\"\n .Width = 8000\n .Height = 6000\n .BackColor = RGB(255, 255, 255)\n End With\n With txtInput\n .Text = ...
statements
Private Sub ConfigureForm() With Me .Caption = "My Application" .Width = 8000 .Height = 6000 .BackColor = RGB(255, 255, 255) End With With txtInput .Text = "Default" .MaxLength = 50 .Enabled = True End With End Sub
private void ConfigureForm() { this.Text = "My Application"; this.Width = 800; this.Height = 600; this.BackColor = Color.White; txtInput.Text = "Default"; txtInput.MaxLength = 50; txtInput.Enabled = true; }
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nPrivate Sub ProcessData()\n Dim i As Integer\n i = 0\nRetry:\n i = i + 1\n If i < 5 Then\n GoTo Retry\n End If\n MsgBox \"Done: \" & i\nEnd Sub\n```\n" }, { "role": "assistant", "content": "...
control_flow
Private Sub ProcessData() Dim i As Integer i = 0 Retry: i = i + 1 If i < 5 Then GoTo Retry End If MsgBox "Done: " & i End Sub
private void ProcessData() { int i = 0; while (i < 5) { i++; } MessageBox.Show("Done: " + i); }
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nPrivate Sub SetScale()\n Me.ScaleMode = vbPixels\n shpBox.Left = 100\n shpBox.Top = 100\n shpBox.Width = 200\n shpBox.Height = 150\nEnd Sub\n```\n" }, { "role": "assistant", "content": "```csharp\npri...
gui_controls
Private Sub SetScale() Me.ScaleMode = vbPixels shpBox.Left = 100 shpBox.Top = 100 shpBox.Width = 200 shpBox.Height = 150 End Sub
private void SetScale() { this.AutoScaleMode = AutoScaleMode.None; shpBox.Left = 100; shpBox.Top = 100; shpBox.Width = 200; shpBox.Height = 150; }
[ { "role": "user", "content": "Convert the following VB6 code to equivalent C#:\n\n```vb6\nPrivate Sub ReadFile()\n Dim fileNum As Integer\n Dim filePath As String\n Dim line As String\n filePath = \"C:\\data\\test.txt\"\n fileNum = FreeFile\n Open filePath For Input As #fileNum\n Do Whi...
file_io
Private Sub ReadFile() Dim fileNum As Integer Dim filePath As String Dim line As String filePath = "C:\data\test.txt" fileNum = FreeFile Open filePath For Input As #fileNum Do While Not EOF(fileNum) Line Input #fileNum, line Debug.Print line Loop Close #fileNum End Su...
private void ReadFile() { string filePath = @"C:\data est.txt"; using (StreamReader reader = new StreamReader(filePath)) { string line; while ((line = reader.ReadLine()) != null) { Console.WriteLine(line); } } }
[ { "role": "user", "content": "Port this VB6 subroutine to C# maintaining the same behavior:\n\n```vb6\nPrivate Sub LoadData()\n Dim conn As New ADODB.Connection\n Dim rs As New ADODB.Recordset\n Dim connStr As String\n connStr = \"Provider=SQLOLEDB;Data Source=server;Initial Catalog=db;User ID=u...
database
Private Sub LoadData() Dim conn As New ADODB.Connection Dim rs As New ADODB.Recordset Dim connStr As String connStr = "Provider=SQLOLEDB;Data Source=server;Initial Catalog=db;User ID=user;Password=pass;" conn.Open connStr rs.Open "SELECT * FROM Customers", conn, adOpenStatic, adLockReadOnly ...
private void LoadData() { string connStr = "Server=server;Database=db;User Id=user;Password=pass;"; using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); using (SqlCommand cmd = new SqlCommand("SELECT * FROM Customers", conn)) { using (SqlDataReader reade...
[ { "role": "user", "content": "Migrate this VB6 code to C# preserving functionality:\n\n```vb6\nPrivate Sub SaveDocument()\n With dlgSave\n .Filter = \"Text Files|*.txt|All Files|*.*\"\n .FileName = \"document.txt\"\n .ShowSave\n If .FileName <> \"\" Then\n Open .Fil...
dialogs
Private Sub SaveDocument() With dlgSave .Filter = "Text Files|*.txt|All Files|*.*" .FileName = "document.txt" .ShowSave If .FileName <> "" Then Open .FileName For Output As #1 Print #1, txtContent.Text Close #1 End If End With End Sub
private void SaveDocument() { using (SaveFileDialog dlgSave = new SaveFileDialog()) { dlgSave.Filter = "Text Files|*.txt|All Files|*.*"; dlgSave.FileName = "document.txt"; if (dlgSave.ShowDialog() == DialogResult.OK) { File.WriteAllText(dlgSave.FileName, txtContent.Te...
[ { "role": "user", "content": "Translate this VB6 code to C# with identical functionality:\n\n```vb6\nPrivate Sub MatrixExample()\n Dim matrix(1 To 3, 1 To 3) As Integer\n Dim i As Integer, j As Integer\n For i = 1 To 3\n For j = 1 To 3\n matrix(i, j) = i * j\n Next j\n N...
arrays
Private Sub MatrixExample() Dim matrix(1 To 3, 1 To 3) As Integer Dim i As Integer, j As Integer For i = 1 To 3 For j = 1 To 3 matrix(i, j) = i * j Next j Next i Debug.Print matrix(2, 3) End Sub
private void MatrixExample() { int[,] matrix = new int[3, 3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { matrix[i, j] = (i + 1) * (j + 1); } } Console.WriteLine(matrix[1, 2]); }
[ { "role": "user", "content": "Migrate this VB6 code to C# preserving functionality:\n\n```vb6\nPrivate Sub CleanText()\n Dim text As String\n text = \"Hello World World\"\n text = Replace(text, \"World\", \"Universe\")\n Debug.Print text\nEnd Sub\n```\n" }, { "role": "assistant", "co...
strings
Private Sub CleanText() Dim text As String text = "Hello World World" text = Replace(text, "World", "Universe") Debug.Print text End Sub
private void CleanText() { string text = "Hello World World"; text = text.Replace("World", "Universe"); Console.WriteLine(text); }
[ { "role": "user", "content": "Convert the following VB6 code to equivalent C#:\n\n```vb6\nPrivate Sub CreateWordDoc()\n Dim wordApp As Object\n Set wordApp = CreateObject(\"Word.Application\")\n wordApp.Visible = True\n wordApp.Documents.Add\n wordApp.ActiveDocument.Content.Text = \"Hello fro...
com_interop
Private Sub CreateWordDoc() Dim wordApp As Object Set wordApp = CreateObject("Word.Application") wordApp.Visible = True wordApp.Documents.Add wordApp.ActiveDocument.Content.Text = "Hello from VB6" End Sub
private void CreateWordDoc() { dynamic wordApp = Activator.CreateInstance(Type.GetTypeFromProgID("Word.Application")); wordApp.Visible = true; wordApp.Documents.Add(); wordApp.ActiveDocument.Content.Text = "Hello from VB6"; }
[ { "role": "user", "content": "Port this VB6 subroutine to C# maintaining the same behavior:\n\n```vb6\nPrivate Sub DelayOperation()\n Dim startTime As Double\n startTime = Timer\n Do While Timer < startTime + 2\n DoEvents\n Loop\n Debug.Print \"2 seconds elapsed\"\nEnd Sub\n```\n" },...
async
Private Sub DelayOperation() Dim startTime As Double startTime = Timer Do While Timer < startTime + 2 DoEvents Loop Debug.Print "2 seconds elapsed" End Sub
private async void DelayOperation() { await Task.Delay(2000); Console.WriteLine("2 seconds elapsed"); }
[ { "role": "user", "content": "Convert the following VB6 code to equivalent C#:\n\n```vb6\nPrivate Sub StringSlice()\n Dim text As String\n text = \"Hello World\"\n Debug.Print Left(text, 5)\n Debug.Print Right(text, 5)\n Debug.Print Mid(text, 7, 5)\n Debug.Print InStr(text, \"World\")\n ...
strings
Private Sub StringSlice() Dim text As String text = "Hello World" Debug.Print Left(text, 5) Debug.Print Right(text, 5) Debug.Print Mid(text, 7, 5) Debug.Print InStr(text, "World") Debug.Print Len(text) End Sub
private void StringSlice() { string text = "Hello World"; Console.WriteLine(text.Substring(0, 5)); Console.WriteLine(text.Substring(text.Length - 5)); Console.WriteLine(text.Substring(6, 5)); Console.WriteLine(text.IndexOf("World") + 1); Console.WriteLine(text.Length); }
[ { "role": "user", "content": "Port this VB6 subroutine to C# maintaining the same behavior:\n\n```vb6\nPrivate Sub Form_Load()\n Dim userName As String\n Dim userAge As Integer\n Dim salary As Double\n Dim isActive As Boolean\n Dim birthDate As Date\n userName = \"John Doe\"\n userAge =...
variables
Private Sub Form_Load() Dim userName As String Dim userAge As Integer Dim salary As Double Dim isActive As Boolean Dim birthDate As Date userName = "John Doe" userAge = 30 salary = 55000.50 isActive = True birthDate = #1/15/1990# End Sub
private void Form_Load(object sender, EventArgs e) { string userName; int userAge; double salary; bool isActive; DateTime birthDate; userName = "John Doe"; userAge = 30; salary = 55000.50; isActive = true; birthDate = new DateTime(1990, 1, 15); }
[ { "role": "user", "content": "Translate this VB6 code to C# with identical functionality:\n\n```vb6\nPrivate Sub Form_Load()\n Dim userName As String\n Dim userAge As Integer\n Dim salary As Double\n Dim isActive As Boolean\n Dim birthDate As Date\n userName = \"John Doe\"\n userAge = 3...
variables
Private Sub Form_Load() Dim userName As String Dim userAge As Integer Dim salary As Double Dim isActive As Boolean Dim birthDate As Date userName = "John Doe" userAge = 30 salary = 55000.50 isActive = True birthDate = #1/15/1990# End Sub
private void Form_Load(object sender, EventArgs e) { string userName; int userAge; double salary; bool isActive; DateTime birthDate; userName = "John Doe"; userAge = 30; salary = 55000.50; isActive = true; birthDate = new DateTime(1990, 1, 15); }
[ { "role": "user", "content": "Convert the following VB6 code to equivalent C#:\n\n```vb6\nPrivate Sub SafeAccess(obj As Object)\n If obj Is Nothing Then\n Debug.Print \"Object is nothing\"\n Exit Sub\n End If\n If IsNull(obj.Value) Then\n Debug.Print \"Value is null\"\n Else...
null_checks
Private Sub SafeAccess(obj As Object) If obj Is Nothing Then Debug.Print "Object is nothing" Exit Sub End If If IsNull(obj.Value) Then Debug.Print "Value is null" Else Debug.Print obj.Value End If End Sub
private void SafeAccess(object obj) { if (obj == null) { Console.WriteLine("Object is null"); return; } if (obj == DBNull.Value) { Console.WriteLine("Value is null"); } else { Console.WriteLine(obj.ToString()); } }
[ { "role": "user", "content": "Convert the following VB6 code to equivalent C#:\n\n```vb6\nPublic Event ValueChanged(ByVal newValue As String)\nPrivate mValue As String\nPublic Property Let Value(v As String)\n If mValue <> v Then\n mValue = v\n RaiseEvent ValueChanged(v)\n End If\nEnd Pr...
events
Public Event ValueChanged(ByVal newValue As String) Private mValue As String Public Property Let Value(v As String) If mValue <> v Then mValue = v RaiseEvent ValueChanged(v) End If End Property
public event EventHandler<string> ValueChanged; private string mValue; public string Value { set { if (mValue != value) { mValue = value; ValueChanged?.Invoke(this, value); } } }
[ { "role": "user", "content": "Port this VB6 subroutine to C# maintaining the same behavior:\n\n```vb6\nPrivate Sub ManageItems()\n Dim items As New Collection\n items.Add \"Apple\", \"1\"\n items.Add \"Banana\", \"2\"\n items.Add \"Cherry\", \"3\"\n Debug.Print items.Count\n Debug.Print it...
collections
Private Sub ManageItems() Dim items As New Collection items.Add "Apple", "1" items.Add "Banana", "2" items.Add "Cherry", "3" Debug.Print items.Count Debug.Print items.Item("2") items.Remove "1" Dim item As Variant For Each item In items Debug.Print item Next item End Sub
private void ManageItems() { Dictionary<string, string> items = new Dictionary<string, string>(); items.Add("1", "Apple"); items.Add("2", "Banana"); items.Add("3", "Cherry"); Console.WriteLine(items.Count); Console.WriteLine(items["2"]); items.Remove("1"); foreach (var item in items) ...
[ { "role": "user", "content": "Convert the following VB6 code to equivalent C#:\n\n```vb6\nPrivate Sub CleanText()\n Dim text As String\n text = \"Hello World World\"\n text = Replace(text, \"World\", \"Universe\")\n Debug.Print text\nEnd Sub\n```\n" }, { "role": "assistant", "content...
strings
Private Sub CleanText() Dim text As String text = "Hello World World" text = Replace(text, "World", "Universe") Debug.Print text End Sub
private void CleanText() { string text = "Hello World World"; text = text.Replace("World", "Universe"); Console.WriteLine(text); }
[ { "role": "user", "content": "Migrate this VB6 code to C# preserving functionality:\n\n```vb6\nPublic Enum StatusCode\n Pending = 0\n Approved = 1\n Rejected = 2\n Cancelled = 3\nEnd Enum\nPrivate Sub CheckStatus(code As StatusCode)\n Select Case code\n Case Pending\n Debug....
enums
Public Enum StatusCode Pending = 0 Approved = 1 Rejected = 2 Cancelled = 3 End Enum Private Sub CheckStatus(code As StatusCode) Select Case code Case Pending Debug.Print "Waiting..." Case Approved Debug.Print "Approved!" Case Rejected Debug...
public enum StatusCode { Pending = 0, Approved = 1, Rejected = 2, Cancelled = 3 } private void CheckStatus(StatusCode code) { switch (code) { case StatusCode.Pending: Console.WriteLine("Waiting..."); break; case StatusCode.Approved: Console.Wri...
[ { "role": "user", "content": "Convert the following VB6 code to equivalent C#:\n\n```vb6\nPrivate Sub FormatCurrency()\n Dim price As Currency\n price = 1234.5678\n Debug.Print Format(price, \"$#,##0.00\")\n Debug.Print FormatNumber(price, 2)\n Debug.Print FormatPercent(0.85, 2)\nEnd Sub\n```...
formatting
Private Sub FormatCurrency() Dim price As Currency price = 1234.5678 Debug.Print Format(price, "$#,##0.00") Debug.Print FormatNumber(price, 2) Debug.Print FormatPercent(0.85, 2) End Sub
private void FormatCurrency() { decimal price = 1234.5678m; Console.WriteLine(price.ToString("C2")); Console.WriteLine(price.ToString("N2")); Console.WriteLine((0.85).ToString("P2")); }
[ { "role": "user", "content": "Migrate this VB6 code to C# preserving functionality:\n\n```vb6\nPublic gAppVersion As String\nPublic gIsDebugMode As Boolean\nSub InitGlobals()\n gAppVersion = \"1.0.0\"\n gIsDebugMode = False\nEnd Sub\n```\n" }, { "role": "assistant", "content": "```csharp\n...
modules
Public gAppVersion As String Public gIsDebugMode As Boolean Sub InitGlobals() gAppVersion = "1.0.0" gIsDebugMode = False End Sub
public static class Globals { public static string gAppVersion; public static bool gIsDebugMode; public static void InitGlobals() { gAppVersion = "1.0.0"; gIsDebugMode = false; } }
[ { "role": "user", "content": "Translate this VB6 code to C# with identical functionality:\n\n```vb6\nPrivate Sub WriteFile()\n Dim fileNum As Integer\n Dim filePath As String\n filePath = \"C:\\data\\output.txt\"\n fileNum = FreeFile\n Open filePath For Output As #fileNum\n Print #fileNum,...
file_io
Private Sub WriteFile() Dim fileNum As Integer Dim filePath As String filePath = "C:\data\output.txt" fileNum = FreeFile Open filePath For Output As #fileNum Print #fileNum, "Hello, World!" Print #fileNum, "Line 2" Close #fileNum End Sub
private void WriteFile() { string filePath = @"C:\data\output.txt"; using (StreamWriter writer = new StreamWriter(filePath)) { writer.WriteLine("Hello, World!"); writer.WriteLine("Line 2"); } }
[ { "role": "user", "content": "Translate this VB6 code to C# with identical functionality:\n\n```vb6\nPrivate Declare Function MessageBox Lib \"user32\" Alias \"MessageBoxA\" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal uType As Long) As Long\nPrivate Sub ShowMessage()\n D...
api_calls
Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal uType As Long) As Long Private Sub ShowMessage() Dim result As Long result = MessageBox(0, "Hello from API", "Title", 0) End Sub
using System.Runtime.InteropServices; public class ApiMethods { [DllImport("user32.dll", CharSet = CharSet.Ansi)] public static extern int MessageBox(IntPtr hwnd, string lpText, string lpCaption, uint uType); public void ShowMessage() { int result = MessageBox(IntPtr.Zero, "Hello from API", "Tit...
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nPrivate Declare Function MessageBox Lib \"user32\" Alias \"MessageBoxA\" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal uType As Long) As Long\nPrivate Sub ShowMessage()\n Dim result As Long\n ...
api_calls
Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal uType As Long) As Long Private Sub ShowMessage() Dim result As Long result = MessageBox(0, "Hello from API", "Title", 0) End Sub
using System.Runtime.InteropServices; public class ApiMethods { [DllImport("user32.dll", CharSet = CharSet.Ansi)] public static extern int MessageBox(IntPtr hwnd, string lpText, string lpCaption, uint uType); public void ShowMessage() { int result = MessageBox(IntPtr.Zero, "Hello from API", "Tit...
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nPrivate Sub CheckGrade(score As Integer)\n If score >= 90 Then\n MsgBox \"Grade: A\"\n ElseIf score >= 80 Then\n MsgBox \"Grade: B\"\n ElseIf score >= 70 Then\n MsgBox \"Grade: C\"\n ElseIf scor...
control_flow
Private Sub CheckGrade(score As Integer) If score >= 90 Then MsgBox "Grade: A" ElseIf score >= 80 Then MsgBox "Grade: B" ElseIf score >= 70 Then MsgBox "Grade: C" ElseIf score >= 60 Then MsgBox "Grade: D" Else MsgBox "Grade: F" End If End Sub
private void CheckGrade(int score) { if (score >= 90) { MessageBox.Show("Grade: A"); } else if (score >= 80) { MessageBox.Show("Grade: B"); } else if (score >= 70) { MessageBox.Show("Grade: C"); } else if (score >= 60) { MessageBox.Show("Grade:...
[ { "role": "user", "content": "Port this VB6 subroutine to C# maintaining the same behavior:\n\n```vb6\nPrivate Sub LongRunningTask()\n Dim i As Long\n For i = 1 To 1000000\n If i Mod 1000 = 0 Then\n DoEvents\n End If\n Next i\n MsgBox \"Task complete!\"\nEnd Sub\n```\n" ...
async
Private Sub LongRunningTask() Dim i As Long For i = 1 To 1000000 If i Mod 1000 = 0 Then DoEvents End If Next i MsgBox "Task complete!" End Sub
private async void LongRunningTask() { await Task.Run(() => { for (long i = 1; i <= 1000000; i++) { if (i % 1000 == 0) { Application.DoEvents(); } } }); MessageBox.Show("Task complete!"); }
[ { "role": "user", "content": "Convert the following VB6 code to equivalent C#:\n\n```vb6\nPrivate Sub ProcessString()\n Dim text As String\n Dim upperText As String\n Dim trimmedText As String\n Dim length As Integer\n text = \" Hello World \"\n upperText = UCase(text)\n trimmedText =...
strings
Private Sub ProcessString() Dim text As String Dim upperText As String Dim trimmedText As String Dim length As Integer text = " Hello World " upperText = UCase(text) trimmedText = Trim(text) length = Len(text) MsgBox "Upper: " & upperText & vbCrLf & "Trimmed: " & trimmedText & vbCr...
private void ProcessString() { string text = " Hello World "; string upperText = text.ToUpper(); string trimmedText = text.Trim(); int length = text.Length; MessageBox.Show("Upper: " + upperText + " Trimmed: " + trimmedText + " Length: " + length); }
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nSub Main()\n Dim frm As New frmMain\n frm.Show\nEnd Sub\n```\n" }, { "role": "assistant", "content": "```csharp\n[STAThread]\nstatic void Main()\n{\n Application.EnableVisualStyles();\n Application.SetCo...
entry_point
Sub Main() Dim frm As New frmMain frm.Show End Sub
[STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frmMain()); }
[ { "role": "user", "content": "Translate this VB6 code to C# with identical functionality:\n\n```vb6\nPrivate Sub LoadImage()\n imgLogo.Picture = LoadPicture(\"C:\\logo.bmp\")\n SavePicture imgLogo.Picture, \"C:\\logo_copy.bmp\"\nEnd Sub\n```\n" }, { "role": "assistant", "content": "```csha...
graphics
Private Sub LoadImage() imgLogo.Picture = LoadPicture("C:\logo.bmp") SavePicture imgLogo.Picture, "C:\logo_copy.bmp" End Sub
private void LoadImage() { imgLogo.Image = Image.FromFile(@"C:\logo.bmp"); imgLogo.Image.Save(@"C:\logo_copy.bmp"); }
[ { "role": "user", "content": "Migrate this VB6 code to C# preserving functionality:\n\n```vb6\nPrivate Sub SafeDivide(a As Double, b As Double)\n On Error GoTo ErrorHandler\n Dim result As Double\n result = a / b\n MsgBox \"Result: \" & result\n Exit Sub\nErrorHandler:\n MsgBox \"Error: \"...
error_handling
Private Sub SafeDivide(a As Double, b As Double) On Error GoTo ErrorHandler Dim result As Double result = a / b MsgBox "Result: " & result Exit Sub ErrorHandler: MsgBox "Error: " & Err.Description Resume Next End Sub
private void SafeDivide(double a, double b) { try { double result = a / b; MessageBox.Show("Result: " + result); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } }
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nPrivate Sub CountUp()\n Dim i As Integer\n i = 1\n While i <= 10\n Debug.Print i\n i = i + 1\n Wend\nEnd Sub\n```\n" }, { "role": "assistant", "content": "```csharp\nprivate void CountUp()\...
loops
Private Sub CountUp() Dim i As Integer i = 1 While i <= 10 Debug.Print i i = i + 1 Wend End Sub
private void CountUp() { int i = 1; while (i <= 10) { Console.WriteLine(i); i++; } }
[ { "role": "user", "content": "Translate this VB6 code to C# with identical functionality:\n\n```vb6\nPrivate Sub ConfigureUI()\n With frmMain\n .Caption = \"Application\"\n With .cmdSubmit\n .Caption = \"Save\"\n .Enabled = False\n End With\n With .txtInp...
statements
Private Sub ConfigureUI() With frmMain .Caption = "Application" With .cmdSubmit .Caption = "Save" .Enabled = False End With With .txtInput .Text = "" .MaxLength = 100 End With End With End Sub
private void ConfigureUI() { frmMain.Text = "Application"; frmMain.cmdSubmit.Text = "Save"; frmMain.cmdSubmit.Enabled = false; frmMain.txtInput.Text = ""; frmMain.txtInput.MaxLength = 100; }
[ { "role": "user", "content": "Translate this VB6 code to C# with identical functionality:\n\n```vb6\nPrivate Sub BringToFront()\n cmdSubmit.ZOrder 0\n lblTitle.ZOrder 1\nEnd Sub\n```\n" }, { "role": "assistant", "content": "```csharp\nprivate void BringToFront()\n{\n cmdSubmit.BringToFr...
gui_controls
Private Sub BringToFront() cmdSubmit.ZOrder 0 lblTitle.ZOrder 1 End Sub
private void BringToFront() { cmdSubmit.BringToFront(); lblTitle.SendToBack(); }
[ { "role": "user", "content": "Port this VB6 subroutine to C# maintaining the same behavior:\n\n```vb6\nPrivate Sub txtInput_KeyPress(KeyAscii As Integer)\n If KeyAscii = 13 Then\n cmdSubmit_Click\n KeyAscii = 0\n End If\nEnd Sub\n```\n" }, { "role": "assistant", "content": "`...
gui_events
Private Sub txtInput_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then cmdSubmit_Click KeyAscii = 0 End If End Sub
private void txtInput_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)13) { cmdSubmit_Click(sender, e); e.Handled = true; } }
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nPrivate Sub FindFirstMatch()\n Dim arr(1 To 5) As String\n Dim i As Integer\n arr(1) = \"A\"\n arr(2) = \"B\"\n arr(3) = \"C\"\n arr(4) = \"D\"\n arr(5) = \"E\"\n For i = 1 To 5\n If arr(i) = \"C\...
loops
Private Sub FindFirstMatch() Dim arr(1 To 5) As String Dim i As Integer arr(1) = "A" arr(2) = "B" arr(3) = "C" arr(4) = "D" arr(5) = "E" For i = 1 To 5 If arr(i) = "C" Then Debug.Print "Found at " & i Exit For End If Next i End Sub
private void FindFirstMatch() { string[] arr = { "A", "B", "C", "D", "E" }; for (int i = 0; i < arr.Length; i++) { if (arr[i] == "C") { Console.WriteLine("Found at " + (i + 1)); break; } } }
[ { "role": "user", "content": "Port this VB6 subroutine to C# maintaining the same behavior:\n\n```vb6\nPrivate Sub ProcessCSV()\n Dim data As String\n Dim parts() As String\n data = \"Apple,Banana,Cherry\"\n parts = Split(data, \",\")\n Debug.Print parts(0)\n Debug.Print Join(parts, \";\")...
strings
Private Sub ProcessCSV() Dim data As String Dim parts() As String data = "Apple,Banana,Cherry" parts = Split(data, ",") Debug.Print parts(0) Debug.Print Join(parts, ";") End Sub
private void ProcessCSV() { string data = "Apple,Banana,Cherry"; string[] parts = data.Split(','); Console.WriteLine(parts[0]); Console.WriteLine(string.Join(";", parts)); }
[ { "role": "user", "content": "Convert the following VB6 code to equivalent C#:\n\n```vb6\nPrivate mName As String\nPrivate mAge As Integer\nPublic Property Get Name() As String\n Name = mName\nEnd Property\nPublic Property Let Name(value As String)\n mName = value\nEnd Property\nPublic Property Get Ag...
classes
Private mName As String Private mAge As Integer Public Property Get Name() As String Name = mName End Property Public Property Let Name(value As String) mName = value End Property Public Property Get Age() As Integer Age = mAge End Property Public Property Let Age(value As Integer) mAge = value End Prop...
public class Person { private string mName; private int mAge; public string Name { get { return mName; } set { mName = value; } } public int Age { get { return mAge; } set { mAge = value; } } public void Greet() { MessageBox.Show("Hello, my...
[ { "role": "user", "content": "Migrate this VB6 code to C# preserving functionality:\n\n```vb6\nPrivate Sub FindFirstMatch()\n Dim arr(1 To 5) As String\n Dim i As Integer\n arr(1) = \"A\"\n arr(2) = \"B\"\n arr(3) = \"C\"\n arr(4) = \"D\"\n arr(5) = \"E\"\n For i = 1 To 5\n If...
loops
Private Sub FindFirstMatch() Dim arr(1 To 5) As String Dim i As Integer arr(1) = "A" arr(2) = "B" arr(3) = "C" arr(4) = "D" arr(5) = "E" For i = 1 To 5 If arr(i) = "C" Then Debug.Print "Found at " & i Exit For End If Next i End Sub
private void FindFirstMatch() { string[] arr = { "A", "B", "C", "D", "E" }; for (int i = 0; i < arr.Length; i++) { if (arr[i] == "C") { Console.WriteLine("Found at " + (i + 1)); break; } } }
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nPrivate Sub CleanText()\n Dim text As String\n text = \"Hello World World\"\n text = Replace(text, \"World\", \"Universe\")\n Debug.Print text\nEnd Sub\n```\n" }, { "role": "assistant", "content": "```cs...
strings
Private Sub CleanText() Dim text As String text = "Hello World World" text = Replace(text, "World", "Universe") Debug.Print text End Sub
private void CleanText() { string text = "Hello World World"; text = text.Replace("World", "Universe"); Console.WriteLine(text); }
[ { "role": "user", "content": "Migrate this VB6 code to C# preserving functionality:\n\n```vb6\nPrivate Sub ProcessFile(filePath As String)\n On Error GoTo Handler\n Dim fileNum As Integer\n fileNum = FreeFile\n Open filePath For Input As #fileNum\n Dim line As String\n Line Input #fileNum,...
error_handling
Private Sub ProcessFile(filePath As String) On Error GoTo Handler Dim fileNum As Integer fileNum = FreeFile Open filePath For Input As #fileNum Dim line As String Line Input #fileNum, line Close #fileNum Debug.Print line Exit Sub Handler: Select Case Err.Number Case 53 ...
private void ProcessFile(string filePath) { try { string line = File.ReadLines(filePath).FirstOrDefault(); Console.WriteLine(line); } catch (FileNotFoundException) { MessageBox.Show("File not found"); } catch (DirectoryNotFoundException) { MessageBox.Show(...
[ { "role": "user", "content": "Migrate this VB6 code to C# preserving functionality:\n\n```vb6\nPrivate Sub CharOperations()\n Dim charCode As Integer\n Dim character As String\n character = Chr(65)\n charCode = Asc(\"A\")\n Debug.Print \"Char 65 = \" & character\n Debug.Print \"Asc A = \" ...
strings
Private Sub CharOperations() Dim charCode As Integer Dim character As String character = Chr(65) charCode = Asc("A") Debug.Print "Char 65 = " & character Debug.Print "Asc A = " & charCode End Sub
private void CharOperations() { char character = (char)65; int charCode = (int)'A'; Console.WriteLine("Char 65 = " + character); Console.WriteLine("Asc A = " + charCode); }
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nPrivate Sub GetUserInput()\n Dim name As String\n Dim age As String\n name = InputBox(\"Enter your name:\", \"Name Input\", \"Guest\")\n age = InputBox(\"Enter your age:\", \"Age Input\")\n If name <> \"\" Then\n...
dialogs
Private Sub GetUserInput() Dim name As String Dim age As String name = InputBox("Enter your name:", "Name Input", "Guest") age = InputBox("Enter your age:", "Age Input") If name <> "" Then MsgBox "Hello " & name & ", you are " & age & " years old.", vbInformation, "Welcome" End If End Su...
private void GetUserInput() { string name = Microsoft.VisualBasic.Interaction.InputBox("Enter your name:", "Name Input", "Guest"); string age = Microsoft.VisualBasic.Interaction.InputBox("Enter your age:", "Age Input"); if (!string.IsNullOrEmpty(name)) { MessageBox.Show("Hello " + name + ", you ...
[ { "role": "user", "content": "Convert the following VB6 code to equivalent C#:\n\n```vb6\nSub Main()\n Dim frm As New frmMain\n frm.Show\nEnd Sub\n```\n" }, { "role": "assistant", "content": "```csharp\n[STAThread]\nstatic void Main()\n{\n Application.EnableVisualStyles();\n Applicat...
entry_point
Sub Main() Dim frm As New frmMain frm.Show End Sub
[STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frmMain()); }
[ { "role": "user", "content": "Migrate this VB6 code to C# preserving functionality:\n\n```vb6\nPrivate Sub StringSlice()\n Dim text As String\n text = \"Hello World\"\n Debug.Print Left(text, 5)\n Debug.Print Right(text, 5)\n Debug.Print Mid(text, 7, 5)\n Debug.Print InStr(text, \"World\")...
strings
Private Sub StringSlice() Dim text As String text = "Hello World" Debug.Print Left(text, 5) Debug.Print Right(text, 5) Debug.Print Mid(text, 7, 5) Debug.Print InStr(text, "World") Debug.Print Len(text) End Sub
private void StringSlice() { string text = "Hello World"; Console.WriteLine(text.Substring(0, 5)); Console.WriteLine(text.Substring(text.Length - 5)); Console.WriteLine(text.Substring(6, 5)); Console.WriteLine(text.IndexOf("World") + 1); Console.WriteLine(text.Length); }
[ { "role": "user", "content": "Port this VB6 subroutine to C# maintaining the same behavior:\n\n```vb6\nPrivate Declare Function MessageBox Lib \"user32\" Alias \"MessageBoxA\" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal uType As Long) As Long\nPrivate Sub ShowMessage()\n ...
api_calls
Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal uType As Long) As Long Private Sub ShowMessage() Dim result As Long result = MessageBox(0, "Hello from API", "Title", 0) End Sub
using System.Runtime.InteropServices; public class ApiMethods { [DllImport("user32.dll", CharSet = CharSet.Ansi)] public static extern int MessageBox(IntPtr hwnd, string lpText, string lpCaption, uint uType); public void ShowMessage() { int result = MessageBox(IntPtr.Zero, "Hello from API", "Tit...
[ { "role": "user", "content": "Translate this VB6 code to C# with identical functionality:\n\n```vb6\nPrivate Sub CleanText()\n Dim text As String\n text = \"Hello World World\"\n text = Replace(text, \"World\", \"Universe\")\n Debug.Print text\nEnd Sub\n```\n" }, { "role": "assistant", ...
strings
Private Sub CleanText() Dim text As String text = "Hello World World" text = Replace(text, "World", "Universe") Debug.Print text End Sub
private void CleanText() { string text = "Hello World World"; text = text.Replace("World", "Universe"); Console.WriteLine(text); }
[ { "role": "user", "content": "Translate this VB6 code to C# with identical functionality:\n\n```vb6\nPrivate Sub FindFirstMatch()\n Dim arr(1 To 5) As String\n Dim i As Integer\n arr(1) = \"A\"\n arr(2) = \"B\"\n arr(3) = \"C\"\n arr(4) = \"D\"\n arr(5) = \"E\"\n For i = 1 To 5\n ...
loops
Private Sub FindFirstMatch() Dim arr(1 To 5) As String Dim i As Integer arr(1) = "A" arr(2) = "B" arr(3) = "C" arr(4) = "D" arr(5) = "E" For i = 1 To 5 If arr(i) = "C" Then Debug.Print "Found at " & i Exit For End If Next i End Sub
private void FindFirstMatch() { string[] arr = { "A", "B", "C", "D", "E" }; for (int i = 0; i < arr.Length; i++) { if (arr[i] == "C") { Console.WriteLine("Found at " + (i + 1)); break; } } }
[ { "role": "user", "content": "Convert the following VB6 code to equivalent C#:\n\n```vb6\nPrivate Sub DrawDivider()\n With shpDivider\n .Left = 100\n .Top = 500\n .Width = 4000\n .Height = 50\n .BackColor = RGB(128, 128, 128)\n .BorderStyle = 0\n End With\nEnd...
gui_controls
Private Sub DrawDivider() With shpDivider .Left = 100 .Top = 500 .Width = 4000 .Height = 50 .BackColor = RGB(128, 128, 128) .BorderStyle = 0 End With End Sub
private void DrawDivider() { Panel shpDivider = new Panel(); shpDivider.Left = 10; shpDivider.Top = 50; shpDivider.Width = 400; shpDivider.Height = 5; shpDivider.BackColor = Color.Gray; shpDivider.BorderStyle = BorderStyle.None; this.Controls.Add(shpDivider); }
[ { "role": "user", "content": "Convert the following VB6 code to equivalent C#:\n\n```vb6\nPrivate Sub ValidatePattern()\n Dim text As String\n text = \"ABC123\"\n If text Like \"[A-Z][A-Z][A-Z]###\" Then\n Debug.Print \"Valid format\"\n Else\n Debug.Print \"Invalid format\"\n En...
regex
Private Sub ValidatePattern() Dim text As String text = "ABC123" If text Like "[A-Z][A-Z][A-Z]###" Then Debug.Print "Valid format" Else Debug.Print "Invalid format" End If End Sub
private void ValidatePattern() { string text = "ABC123"; System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"^[A-Z]{3}\d{3}$"); if (regex.IsMatch(text)) { Console.WriteLine("Valid format"); } else { Console.WriteLine("Invalid format"); ...
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nPrivate Sub DrawDivider()\n With shpDivider\n .Left = 100\n .Top = 500\n .Width = 4000\n .Height = 50\n .BackColor = RGB(128, 128, 128)\n .BorderStyle = 0\n End With\nEnd Sub\n```...
gui_controls
Private Sub DrawDivider() With shpDivider .Left = 100 .Top = 500 .Width = 4000 .Height = 50 .BackColor = RGB(128, 128, 128) .BorderStyle = 0 End With End Sub
private void DrawDivider() { Panel shpDivider = new Panel(); shpDivider.Left = 10; shpDivider.Top = 50; shpDivider.Width = 400; shpDivider.Height = 5; shpDivider.BackColor = Color.Gray; shpDivider.BorderStyle = BorderStyle.None; this.Controls.Add(shpDivider); }
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nPrivate Sub CheckStatus()\n Dim score As Integer\n Dim result As String\n score = 75\n result = IIf(score >= 60, \"Pass\", \"Fail\")\n Debug.Print result\nEnd Sub\n```\n" }, { "role": "assistant", "co...
operators
Private Sub CheckStatus() Dim score As Integer Dim result As String score = 75 result = IIf(score >= 60, "Pass", "Fail") Debug.Print result End Sub
private void CheckStatus() { int score = 75; string result = score >= 60 ? "Pass" : "Fail"; Console.WriteLine(result); }
[ { "role": "user", "content": "Migrate this VB6 code to C# preserving functionality:\n\n```vb6\nPrivate Sub CountDown()\n Dim count As Integer\n count = 10\n Do While count > 0\n Debug.Print count\n count = count - 1\n Loop\n Debug.Print \"Blast off!\"\nEnd Sub\n```\n" }, { ...
loops
Private Sub CountDown() Dim count As Integer count = 10 Do While count > 0 Debug.Print count count = count - 1 Loop Debug.Print "Blast off!" End Sub
private void CountDown() { int count = 10; while (count > 0) { Console.WriteLine(count); count--; } Console.WriteLine("Blast off!"); }
[ { "role": "user", "content": "Migrate this VB6 code to C# preserving functionality:\n\n```vb6\nPrivate Sub ProcessData()\n Dim i As Integer\n i = 0\nRetry:\n i = i + 1\n If i < 5 Then\n GoTo Retry\n End If\n MsgBox \"Done: \" & i\nEnd Sub\n```\n" }, { "role": "assistant", ...
control_flow
Private Sub ProcessData() Dim i As Integer i = 0 Retry: i = i + 1 If i < 5 Then GoTo Retry End If MsgBox "Done: " & i End Sub
private void ProcessData() { int i = 0; while (i < 5) { i++; } MessageBox.Show("Done: " + i); }
[ { "role": "user", "content": "Convert the following VB6 code to equivalent C#:\n\n```vb6\nPrivate Sub picCanvas_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)\n If Button = vbLeftButton Then\n Debug.Print \"Left click at (\" & X & \", \" & Y & \")\"\n ElseIf Button = v...
gui_events
Private Sub picCanvas_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then Debug.Print "Left click at (" & X & ", " & Y & ")" ElseIf Button = vbRightButton Then PopupMenu mnuContext End If End Sub
private void picCanvas_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { Console.WriteLine("Left click at (" + e.X + ", " + e.Y + ")"); } else if (e.Button == MouseButtons.Right) { mnuContext.Show(picCanvas, new Point(e.X, e.Y)); } }
[ { "role": "user", "content": "Port this VB6 subroutine to C# maintaining the same behavior:\n\n```vb6\nPrivate Sub CleanText()\n Dim text As String\n text = \"Hello World World\"\n text = Replace(text, \"World\", \"Universe\")\n Debug.Print text\nEnd Sub\n```\n" }, { "role": "assistant",...
strings
Private Sub CleanText() Dim text As String text = "Hello World World" text = Replace(text, "World", "Universe") Debug.Print text End Sub
private void CleanText() { string text = "Hello World World"; text = text.Replace("World", "Universe"); Console.WriteLine(text); }
[ { "role": "user", "content": "Translate this VB6 code to C# with identical functionality:\n\n```vb6\nPrivate Sub CheckFile()\n Dim attrs As Integer\n attrs = GetAttr(\"C:\\test.txt\")\n If attrs And vbReadOnly Then\n SetAttr \"C:\\test.txt\", vbNormal\n End If\nEnd Sub\n```\n" }, { ...
file_io
Private Sub CheckFile() Dim attrs As Integer attrs = GetAttr("C:\test.txt") If attrs And vbReadOnly Then SetAttr "C:\test.txt", vbNormal End If End Sub
private void CheckFile() { FileAttributes attrs = File.GetAttributes(@"C: est.txt"); if ((attrs & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { File.SetAttributes(@"C: est.txt", FileAttributes.Normal); } }
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nPrivate Sub cmdSubmit_Click()\n Dim name As String\n name = txtName.Text\n If name = \"\" Then\n MsgBox \"Please enter a name\"\n txtName.SetFocus\n Else\n lblResult.Caption = \"Hello, \" & name...
gui_events
Private Sub cmdSubmit_Click() Dim name As String name = txtName.Text If name = "" Then MsgBox "Please enter a name" txtName.SetFocus Else lblResult.Caption = "Hello, " & name End If End Sub
private void cmdSubmit_Click(object sender, EventArgs e) { string name = txtName.Text; if (string.IsNullOrEmpty(name)) { MessageBox.Show("Please enter a name"); txtName.Focus(); } else { lblResult.Text = "Hello, " + name; } }
[ { "role": "user", "content": "Convert the following VB6 code to equivalent C#:\n\n```vb6\nPrivate Sub DelayOperation()\n Dim startTime As Double\n startTime = Timer\n Do While Timer < startTime + 2\n DoEvents\n Loop\n Debug.Print \"2 seconds elapsed\"\nEnd Sub\n```\n" }, { "rol...
async
Private Sub DelayOperation() Dim startTime As Double startTime = Timer Do While Timer < startTime + 2 DoEvents Loop Debug.Print "2 seconds elapsed" End Sub
private async void DelayOperation() { await Task.Delay(2000); Console.WriteLine("2 seconds elapsed"); }
[ { "role": "user", "content": "Translate this VB6 code to C# with identical functionality:\n\n```vb6\nPrivate Sub LongRunningTask()\n Dim i As Long\n For i = 1 To 1000000\n If i Mod 1000 = 0 Then\n DoEvents\n End If\n Next i\n MsgBox \"Task complete!\"\nEnd Sub\n```\n" ...
async
Private Sub LongRunningTask() Dim i As Long For i = 1 To 1000000 If i Mod 1000 = 0 Then DoEvents End If Next i MsgBox "Task complete!" End Sub
private async void LongRunningTask() { await Task.Run(() => { for (long i = 1; i <= 1000000; i++) { if (i % 1000 == 0) { Application.DoEvents(); } } }); MessageBox.Show("Task complete!"); }
[ { "role": "user", "content": "Convert the following VB6 code to equivalent C#:\n\n```vb6\nPrivate Sub WriteFile()\n Dim fileNum As Integer\n Dim filePath As String\n filePath = \"C:\\data\\output.txt\"\n fileNum = FreeFile\n Open filePath For Output As #fileNum\n Print #fileNum, \"Hello, W...
file_io
Private Sub WriteFile() Dim fileNum As Integer Dim filePath As String filePath = "C:\data\output.txt" fileNum = FreeFile Open filePath For Output As #fileNum Print #fileNum, "Hello, World!" Print #fileNum, "Line 2" Close #fileNum End Sub
private void WriteFile() { string filePath = @"C:\data\output.txt"; using (StreamWriter writer = new StreamWriter(filePath)) { writer.WriteLine("Hello, World!"); writer.WriteLine("Line 2"); } }
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nPrivate Sub StringSlice()\n Dim text As String\n text = \"Hello World\"\n Debug.Print Left(text, 5)\n Debug.Print Right(text, 5)\n Debug.Print Mid(text, 7, 5)\n Debug.Print InStr(text, \"World\")\n Debug.Pr...
strings
Private Sub StringSlice() Dim text As String text = "Hello World" Debug.Print Left(text, 5) Debug.Print Right(text, 5) Debug.Print Mid(text, 7, 5) Debug.Print InStr(text, "World") Debug.Print Len(text) End Sub
private void StringSlice() { string text = "Hello World"; Console.WriteLine(text.Substring(0, 5)); Console.WriteLine(text.Substring(text.Length - 5)); Console.WriteLine(text.Substring(6, 5)); Console.WriteLine(text.IndexOf("World") + 1); Console.WriteLine(text.Length); }
[ { "role": "user", "content": "Convert the following VB6 code to equivalent C#:\n\n```vb6\nPrivate Sub LoadGrid()\n Dim i As Integer\n With gridData\n .Rows = 10\n .Cols = 3\n .FixedRows = 1\n .FixedCols = 0\n .TextMatrix(0, 0) = \"Name\"\n .TextMatrix(0, 1) = ...
gui_controls
Private Sub LoadGrid() Dim i As Integer With gridData .Rows = 10 .Cols = 3 .FixedRows = 1 .FixedCols = 0 .TextMatrix(0, 0) = "Name" .TextMatrix(0, 1) = "Age" .TextMatrix(0, 2) = "City" For i = 1 To 9 .TextMatrix(i, 0) = "Person " & i ...
private void LoadGrid() { dgvData.Rows.Clear(); dgvData.Columns.Clear(); dgvData.Columns.Add("Name", "Name"); dgvData.Columns.Add("Age", "Age"); dgvData.Columns.Add("City", "City"); dgvData.Rows.Add("Name", "Age", "City"); for (int i = 1; i <= 9; i++) { dgvData.Rows.Add("Person "...
[ { "role": "user", "content": "Convert the following VB6 code to equivalent C#:\n\n```vb6\nPrivate Sub ConfigureUI()\n With frmMain\n .Caption = \"Application\"\n With .cmdSubmit\n .Caption = \"Save\"\n .Enabled = False\n End With\n With .txtInput\n ...
statements
Private Sub ConfigureUI() With frmMain .Caption = "Application" With .cmdSubmit .Caption = "Save" .Enabled = False End With With .txtInput .Text = "" .MaxLength = 100 End With End With End Sub
private void ConfigureUI() { frmMain.Text = "Application"; frmMain.cmdSubmit.Text = "Save"; frmMain.cmdSubmit.Enabled = false; frmMain.txtInput.Text = ""; frmMain.txtInput.MaxLength = 100; }
[ { "role": "user", "content": "Migrate this VB6 code to C# preserving functionality:\n\n```vb6\nPrivate Sub ListEmployees()\n Dim emp As Variant\n Dim employees As Collection\n Set employees = New Collection\n employees.Add \"Alice\"\n employees.Add \"Bob\"\n employees.Add \"Charlie\"\n ...
loops
Private Sub ListEmployees() Dim emp As Variant Dim employees As Collection Set employees = New Collection employees.Add "Alice" employees.Add "Bob" employees.Add "Charlie" For Each emp In employees Debug.Print emp Next emp End Sub
private void ListEmployees() { List<string> employees = new List<string>(); employees.Add("Alice"); employees.Add("Bob"); employees.Add("Charlie"); foreach (string emp in employees) { Console.WriteLine(emp); } }
[ { "role": "user", "content": "Translate this VB6 code to C# with identical functionality:\n\n```vb6\nPrivate Sub CreateWordDoc()\n Dim wordApp As Object\n Set wordApp = CreateObject(\"Word.Application\")\n wordApp.Visible = True\n wordApp.Documents.Add\n wordApp.ActiveDocument.Content.Text = ...
com_interop
Private Sub CreateWordDoc() Dim wordApp As Object Set wordApp = CreateObject("Word.Application") wordApp.Visible = True wordApp.Documents.Add wordApp.ActiveDocument.Content.Text = "Hello from VB6" End Sub
private void CreateWordDoc() { dynamic wordApp = Activator.CreateInstance(Type.GetTypeFromProgID("Word.Application")); wordApp.Visible = true; wordApp.Documents.Add(); wordApp.ActiveDocument.Content.Text = "Hello from VB6"; }
[ { "role": "user", "content": "Migrate this VB6 code to C# preserving functionality:\n\n```vb6\nPrivate Sub DateOperations()\n Dim today As Date\n Dim future As Date\n Dim diff As Long\n today = Now\n future = DateAdd(\"d\", 30, today)\n diff = DateDiff(\"d\", today, future)\n Debug.Prin...
datetime
Private Sub DateOperations() Dim today As Date Dim future As Date Dim diff As Long today = Now future = DateAdd("d", 30, today) diff = DateDiff("d", today, future) Debug.Print "Today: " & Format(today, "yyyy-mm-dd") Debug.Print "Future: " & Format(future, "yyyy-mm-dd") Debug.Print "D...
private void DateOperations() { DateTime today = DateTime.Now; DateTime future = today.AddDays(30); TimeSpan diff = future - today; Console.WriteLine("Today: " + today.ToString("yyyy-MM-dd")); Console.WriteLine("Future: " + future.ToString("yyyy-MM-dd")); Console.WriteLine("Days: " + diff.Days);...
[ { "role": "user", "content": "Port this VB6 subroutine to C# maintaining the same behavior:\n\n```vb6\nPrivate Sub mnuFileExit_Click()\n If MsgBox(\"Are you sure?\", vbYesNo + vbQuestion) = vbYes Then\n Unload Me\n End If\nEnd Sub\nPrivate Sub mnuEditCut_Click()\n Clipboard.SetText txtInput....
gui_events
Private Sub mnuFileExit_Click() If MsgBox("Are you sure?", vbYesNo + vbQuestion) = vbYes Then Unload Me End If End Sub Private Sub mnuEditCut_Click() Clipboard.SetText txtInput.SelText txtInput.SelText = "" End Sub Private Sub mnuEditPaste_Click() txtInput.SelText = Clipboard.GetText End Sub
private void mnuFileExit_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { this.Close(); } } private void mnuEditCut_Click(object sender, EventArgs e) { Clipboard.SetText(txtInput.SelectedT...
[ { "role": "user", "content": "Translate this VB6 code to C# with identical functionality:\n\n```vb6\nPrivate Sub GenerateRandom()\n Dim randomNum As Integer\n Randomize\n randomNum = Int((100 * Rnd) + 1)\n Debug.Print randomNum\nEnd Sub\n```\n" }, { "role": "assistant", "content": "`...
math
Private Sub GenerateRandom() Dim randomNum As Integer Randomize randomNum = Int((100 * Rnd) + 1) Debug.Print randomNum End Sub
private void GenerateRandom() { Random random = new Random(); int randomNum = random.Next(1, 101); Console.WriteLine(randomNum); }
[ { "role": "user", "content": "Convert the following VB6 code to equivalent C#:\n\n```vb6\nPrivate Sub CharOperations()\n Dim charCode As Integer\n Dim character As String\n character = Chr(65)\n charCode = Asc(\"A\")\n Debug.Print \"Char 65 = \" & character\n Debug.Print \"Asc A = \" & cha...
strings
Private Sub CharOperations() Dim charCode As Integer Dim character As String character = Chr(65) charCode = Asc("A") Debug.Print "Char 65 = " & character Debug.Print "Asc A = " & charCode End Sub
private void CharOperations() { char character = (char)65; int charCode = (int)'A'; Console.WriteLine("Char 65 = " + character); Console.WriteLine("Asc A = " + charCode); }
[ { "role": "user", "content": "Translate this VB6 code to C# with identical functionality:\n\n```vb6\nPrivate Sub PrintReport()\n Printer.FontName = \"Arial\"\n Printer.FontSize = 12\n Printer.Print \"Report Title\"\n Printer.Print \"Line 1: Some data\"\n Printer.Print \"Line 2: More data\"\n ...
printing
Private Sub PrintReport() Printer.FontName = "Arial" Printer.FontSize = 12 Printer.Print "Report Title" Printer.Print "Line 1: Some data" Printer.Print "Line 2: More data" Printer.EndDoc End Sub
private void PrintReport() { PrintDocument pd = new PrintDocument(); pd.PrintPage += (sender, e) => { using (Font font = new Font("Arial", 12)) { e.Graphics.DrawString("Report Title", font, Brushes.Black, 100, 100); e.Graphics.DrawString("Line 1: Some data", font, Bru...
[ { "role": "user", "content": "Convert the following VB6 code to equivalent C#:\n\n```vb6\nPrivate Sub txtInput_KeyPress(KeyAscii As Integer)\n If KeyAscii = 13 Then\n cmdSubmit_Click\n KeyAscii = 0\n End If\nEnd Sub\n```\n" }, { "role": "assistant", "content": "```csharp\npri...
gui_events
Private Sub txtInput_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then cmdSubmit_Click KeyAscii = 0 End If End Sub
private void txtInput_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)13) { cmdSubmit_Click(sender, e); e.Handled = true; } }
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nPrivate Sub Form_Load()\n cboColors.AddItem \"Red\"\n cboColors.AddItem \"Green\"\n cboColors.AddItem \"Blue\"\n cboColors.ListIndex = 0\n lstItems.AddItem \"Item 1\"\n lstItems.AddItem \"Item 2\"\n lstItem...
gui_controls
Private Sub Form_Load() cboColors.AddItem "Red" cboColors.AddItem "Green" cboColors.AddItem "Blue" cboColors.ListIndex = 0 lstItems.AddItem "Item 1" lstItems.AddItem "Item 2" lstItems.AddItem "Item 3" End Sub
private void Form_Load(object sender, EventArgs e) { cboColors.Items.Add("Red"); cboColors.Items.Add("Green"); cboColors.Items.Add("Blue"); cboColors.SelectedIndex = 0; lstItems.Items.Add("Item 1"); lstItems.Items.Add("Item 2"); lstItems.Items.Add("Item 3"); }
[ { "role": "user", "content": "Translate this VB6 code to C# with identical functionality:\n\n```vb6\nPrivate Sub SaveDocument()\n With dlgSave\n .Filter = \"Text Files|*.txt|All Files|*.*\"\n .FileName = \"document.txt\"\n .ShowSave\n If .FileName <> \"\" Then\n Ope...
dialogs
Private Sub SaveDocument() With dlgSave .Filter = "Text Files|*.txt|All Files|*.*" .FileName = "document.txt" .ShowSave If .FileName <> "" Then Open .FileName For Output As #1 Print #1, txtContent.Text Close #1 End If End With End Sub
private void SaveDocument() { using (SaveFileDialog dlgSave = new SaveFileDialog()) { dlgSave.Filter = "Text Files|*.txt|All Files|*.*"; dlgSave.FileName = "document.txt"; if (dlgSave.ShowDialog() == DialogResult.OK) { File.WriteAllText(dlgSave.FileName, txtContent.Te...
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nPrivate Sub Form_Load()\n Dim userName As String\n Dim userAge As Integer\n Dim salary As Double\n Dim isActive As Boolean\n Dim birthDate As Date\n userName = \"John Doe\"\n userAge = 30\n salary = 5500...
variables
Private Sub Form_Load() Dim userName As String Dim userAge As Integer Dim salary As Double Dim isActive As Boolean Dim birthDate As Date userName = "John Doe" userAge = 30 salary = 55000.50 isActive = True birthDate = #1/15/1990# End Sub
private void Form_Load(object sender, EventArgs e) { string userName; int userAge; double salary; bool isActive; DateTime birthDate; userName = "John Doe"; userAge = 30; salary = 55000.50; isActive = true; birthDate = new DateTime(1990, 1, 15); }
[ { "role": "user", "content": "Translate this VB6 code to C# with identical functionality:\n\n```vb6\nPrivate Sub ConvertValues()\n Dim v As Variant\n Dim s As String\n Dim i As Integer\n Dim d As Double\n Dim dt As Date\n Dim l As Long\n Dim b As Boolean\n v = \"42\"\n s = CStr(v)...
conversions
Private Sub ConvertValues() Dim v As Variant Dim s As String Dim i As Integer Dim d As Double Dim dt As Date Dim l As Long Dim b As Boolean v = "42" s = CStr(v) i = CInt(v) d = CDbl(v) l = CLng(v) b = CBool(v) dt = CDate("2024-01-01") End Sub
private void ConvertValues() { object v = "42"; string s = v.ToString(); int i = Convert.ToInt32(v); double d = Convert.ToDouble(v); long l = Convert.ToInt64(v); bool b = Convert.ToBoolean(v); DateTime dt = Convert.ToDateTime("2024-01-01"); }
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nPrivate Sub CenterForm()\n Me.Left = (Screen.Width - Me.Width) / 2\n Me.Top = (Screen.Height - Me.Height) / 2\nEnd Sub\n```\n" }, { "role": "assistant", "content": "```csharp\nprivate void CenterForm()\n{\n ...
gui_forms
Private Sub CenterForm() Me.Left = (Screen.Width - Me.Width) / 2 Me.Top = (Screen.Height - Me.Height) / 2 End Sub
private void CenterForm() { this.StartPosition = FormStartPosition.CenterScreen; }
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nPrivate Sub ShowAppInfo()\n Debug.Print \"Path: \" & App.Path\n Debug.Print \"Exe: \" & App.ExeName\n Debug.Print \"Version: \" & App.Major & \".\" & App.Minor & \".\" & App.Revision\nEnd Sub\n```\n" }, { "role...
application
Private Sub ShowAppInfo() Debug.Print "Path: " & App.Path Debug.Print "Exe: " & App.ExeName Debug.Print "Version: " & App.Major & "." & App.Minor & "." & App.Revision End Sub
private void ShowAppInfo() { string exePath = Application.ExecutablePath; string exeName = Path.GetFileNameWithoutExtension(exePath); Version version = Assembly.GetExecutingAssembly().GetName().Version; Console.WriteLine("Path: " + Path.GetDirectoryName(exePath)); Console.WriteLine("Exe: " + exeName...
[ { "role": "user", "content": "Translate this VB6 code to C# with identical functionality:\n\n```vb6\nPrivate Sub LoadGrid()\n Dim i As Integer\n With gridData\n .Rows = 10\n .Cols = 3\n .FixedRows = 1\n .FixedCols = 0\n .TextMatrix(0, 0) = \"Name\"\n .TextMatr...
gui_controls
Private Sub LoadGrid() Dim i As Integer With gridData .Rows = 10 .Cols = 3 .FixedRows = 1 .FixedCols = 0 .TextMatrix(0, 0) = "Name" .TextMatrix(0, 1) = "Age" .TextMatrix(0, 2) = "City" For i = 1 To 9 .TextMatrix(i, 0) = "Person " & i ...
private void LoadGrid() { dgvData.Rows.Clear(); dgvData.Columns.Clear(); dgvData.Columns.Add("Name", "Name"); dgvData.Columns.Add("Age", "Age"); dgvData.Columns.Add("City", "City"); dgvData.Rows.Add("Name", "Age", "City"); for (int i = 1; i <= 9; i++) { dgvData.Rows.Add("Person "...
[ { "role": "user", "content": "Migrate this VB6 code to C# preserving functionality:\n\n```vb6\nPrivate Sub CheckFile()\n Dim attrs As Integer\n attrs = GetAttr(\"C:\\test.txt\")\n If attrs And vbReadOnly Then\n SetAttr \"C:\\test.txt\", vbNormal\n End If\nEnd Sub\n```\n" }, { "rol...
file_io
Private Sub CheckFile() Dim attrs As Integer attrs = GetAttr("C:\test.txt") If attrs And vbReadOnly Then SetAttr "C:\test.txt", vbNormal End If End Sub
private void CheckFile() { FileAttributes attrs = File.GetAttributes(@"C: est.txt"); if ((attrs & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { File.SetAttributes(@"C: est.txt", FileAttributes.Normal); } }
[ { "role": "user", "content": "Port this VB6 subroutine to C# maintaining the same behavior:\n\n```vb6\nPrivate Sub ListFiles()\n Dim file As String\n file = Dir(\"C:\\temp\\*.*\")\n Do While file <> \"\"\n Debug.Print file\n file = Dir()\n Loop\nEnd Sub\n```\n" }, { "role":...
file_io
Private Sub ListFiles() Dim file As String file = Dir("C:\temp\*.*") Do While file <> "" Debug.Print file file = Dir() Loop End Sub
private void ListFiles() { foreach (string file in Directory.GetFiles(@"C: emp", "*.*")) { Console.WriteLine(Path.GetFileName(file)); } }
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nPrivate Sub ProcessCSV()\n Dim data As String\n Dim parts() As String\n data = \"Apple,Banana,Cherry\"\n parts = Split(data, \",\")\n Debug.Print parts(0)\n Debug.Print Join(parts, \";\")\nEnd Sub\n```\n" },...
strings
Private Sub ProcessCSV() Dim data As String Dim parts() As String data = "Apple,Banana,Cherry" parts = Split(data, ",") Debug.Print parts(0) Debug.Print Join(parts, ";") End Sub
private void ProcessCSV() { string data = "Apple,Banana,Cherry"; string[] parts = data.Split(','); Console.WriteLine(parts[0]); Console.WriteLine(string.Join(";", parts)); }
[ { "role": "user", "content": "Port this VB6 subroutine to C# maintaining the same behavior:\n\n```vb6\nOption Explicit\nPrivate mCounter As Integer\nPublic Const MAX_SIZE As Integer = 100\nPrivate Sub IncrementCounter()\n mCounter = mCounter + 1\n If mCounter > MAX_SIZE Then\n mCounter = 0\n ...
modules
Option Explicit Private mCounter As Integer Public Const MAX_SIZE As Integer = 100 Private Sub IncrementCounter() mCounter = mCounter + 1 If mCounter > MAX_SIZE Then mCounter = 0 End If End Sub
public class ModuleName { private int mCounter = 0; public const int MAX_SIZE = 100; private void IncrementCounter() { mCounter++; if (mCounter > MAX_SIZE) { mCounter = 0; } } }
[ { "role": "user", "content": "Translate this VB6 code to C# with identical functionality:\n\n```vb6\nPrivate Sub ProcessData()\n Dim i As Integer\n i = 0\nRetry:\n i = i + 1\n If i < 5 Then\n GoTo Retry\n End If\n MsgBox \"Done: \" & i\nEnd Sub\n```\n" }, { "role": "assistan...
control_flow
Private Sub ProcessData() Dim i As Integer i = 0 Retry: i = i + 1 If i < 5 Then GoTo Retry End If MsgBox "Done: " & i End Sub
private void ProcessData() { int i = 0; while (i < 5) { i++; } MessageBox.Show("Done: " + i); }
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nPrivate Sub GenerateRandom()\n Dim randomNum As Integer\n Randomize\n randomNum = Int((100 * Rnd) + 1)\n Debug.Print randomNum\nEnd Sub\n```\n" }, { "role": "assistant", "content": "```csharp\nprivate vo...
math
Private Sub GenerateRandom() Dim randomNum As Integer Randomize randomNum = Int((100 * Rnd) + 1) Debug.Print randomNum End Sub
private void GenerateRandom() { Random random = new Random(); int randomNum = random.Next(1, 101); Console.WriteLine(randomNum); }
[ { "role": "user", "content": "Translate this VB6 code to C# with identical functionality:\n\n```vb6\nPrivate Sub ListFiles()\n Dim file As String\n file = Dir(\"C:\\temp\\*.*\")\n Do While file <> \"\"\n Debug.Print file\n file = Dir()\n Loop\nEnd Sub\n```\n" }, { "role": "...
file_io
Private Sub ListFiles() Dim file As String file = Dir("C:\temp\*.*") Do While file <> "" Debug.Print file file = Dir() Loop End Sub
private void ListFiles() { foreach (string file in Directory.GetFiles(@"C: emp", "*.*")) { Console.WriteLine(Path.GetFileName(file)); } }
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nPrivate Sub SaveDocument()\n With dlgSave\n .Filter = \"Text Files|*.txt|All Files|*.*\"\n .FileName = \"document.txt\"\n .ShowSave\n If .FileName <> \"\" Then\n Open .FileName For Outp...
dialogs
Private Sub SaveDocument() With dlgSave .Filter = "Text Files|*.txt|All Files|*.*" .FileName = "document.txt" .ShowSave If .FileName <> "" Then Open .FileName For Output As #1 Print #1, txtContent.Text Close #1 End If End With End Sub
private void SaveDocument() { using (SaveFileDialog dlgSave = new SaveFileDialog()) { dlgSave.Filter = "Text Files|*.txt|All Files|*.*"; dlgSave.FileName = "document.txt"; if (dlgSave.ShowDialog() == DialogResult.OK) { File.WriteAllText(dlgSave.FileName, txtContent.Te...
[ { "role": "user", "content": "Convert the following VB6 code to equivalent C#:\n\n```vb6\nPrivate Sub CountUp()\n Dim i As Integer\n i = 1\n While i <= 10\n Debug.Print i\n i = i + 1\n Wend\nEnd Sub\n```\n" }, { "role": "assistant", "content": "```csharp\nprivate void C...
loops
Private Sub CountUp() Dim i As Integer i = 1 While i <= 10 Debug.Print i i = i + 1 Wend End Sub
private void CountUp() { int i = 1; while (i <= 10) { Console.WriteLine(i); i++; } }
[ { "role": "user", "content": "Convert the following VB6 code to equivalent C#:\n\n```vb6\nImplements IComparable\nPrivate Function IComparable_CompareTo(other As Variant) As Integer\n IComparable_CompareTo = 0\nEnd Function\n```\n" }, { "role": "assistant", "content": "```csharp\npublic class...
interfaces
Implements IComparable Private Function IComparable_CompareTo(other As Variant) As Integer IComparable_CompareTo = 0 End Function
public class MyClass : IComparable { public int CompareTo(object other) { return 0; } }
[ { "role": "user", "content": "Port this VB6 subroutine to C# maintaining the same behavior:\n\n```vb6\nPrivate Sub ProcessString()\n Dim text As String\n Dim upperText As String\n Dim trimmedText As String\n Dim length As Integer\n text = \" Hello World \"\n upperText = UCase(text)\n ...
strings
Private Sub ProcessString() Dim text As String Dim upperText As String Dim trimmedText As String Dim length As Integer text = " Hello World " upperText = UCase(text) trimmedText = Trim(text) length = Len(text) MsgBox "Upper: " & upperText & vbCrLf & "Trimmed: " & trimmedText & vbCr...
private void ProcessString() { string text = " Hello World "; string upperText = text.ToUpper(); string trimmedText = text.Trim(); int length = text.Length; MessageBox.Show("Upper: " + upperText + " Trimmed: " + trimmedText + " Length: " + length); }
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nPrivate Sub FormatCurrency()\n Dim price As Currency\n price = 1234.5678\n Debug.Print Format(price, \"$#,##0.00\")\n Debug.Print FormatNumber(price, 2)\n Debug.Print FormatPercent(0.85, 2)\nEnd Sub\n```\n" }, ...
formatting
Private Sub FormatCurrency() Dim price As Currency price = 1234.5678 Debug.Print Format(price, "$#,##0.00") Debug.Print FormatNumber(price, 2) Debug.Print FormatPercent(0.85, 2) End Sub
private void FormatCurrency() { decimal price = 1234.5678m; Console.WriteLine(price.ToString("C2")); Console.WriteLine(price.ToString("N2")); Console.WriteLine((0.85).ToString("P2")); }
[ { "role": "user", "content": "Port this VB6 subroutine to C# maintaining the same behavior:\n\n```vb6\nPrivate Sub OpenSettings()\n frmSettings.Show vbModal\nEnd Sub\nPrivate Sub OpenAbout()\n frmAbout.Show vbModeless\nEnd Sub\nPrivate Sub CloseForm()\n Unload Me\nEnd Sub\n```\n" }, { "role...
gui_forms
Private Sub OpenSettings() frmSettings.Show vbModal End Sub Private Sub OpenAbout() frmAbout.Show vbModeless End Sub Private Sub CloseForm() Unload Me End Sub
private void OpenSettings() { frmSettings.ShowDialog(); } private void OpenAbout() { frmAbout.Show(); } private void CloseForm() { this.Close(); }
[ { "role": "user", "content": "Port this VB6 subroutine to C# maintaining the same behavior:\n\n```vb6\nPrivate Sub GetDayName(dayNum As Integer)\n Dim dayName As String\n Select Case dayNum\n Case 1\n dayName = \"Monday\"\n Case 2\n dayName = \"Tuesday\"\n Ca...
control_flow
Private Sub GetDayName(dayNum As Integer) Dim dayName As String Select Case dayNum Case 1 dayName = "Monday" Case 2 dayName = "Tuesday" Case 3 dayName = "Wednesday" Case 4 dayName = "Thursday" Case 5 dayName = "F...
private void GetDayName(int dayNum) { string dayName; switch (dayNum) { case 1: dayName = "Monday"; break; case 2: dayName = "Tuesday"; break; case 3: dayName = "Wednesday"; break; case 4: day...
[ { "role": "user", "content": "Migrate this VB6 code to C# preserving functionality:\n\n```vb6\nPrivate Sub CenterForm()\n Me.Left = (Screen.Width - Me.Width) / 2\n Me.Top = (Screen.Height - Me.Height) / 2\nEnd Sub\n```\n" }, { "role": "assistant", "content": "```csharp\nprivate void Center...
gui_forms
Private Sub CenterForm() Me.Left = (Screen.Width - Me.Width) / 2 Me.Top = (Screen.Height - Me.Height) / 2 End Sub
private void CenterForm() { this.StartPosition = FormStartPosition.CenterScreen; }
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nPrivate Sub SafeAccess(obj As Object)\n If obj Is Nothing Then\n Debug.Print \"Object is nothing\"\n Exit Sub\n End If\n If IsNull(obj.Value) Then\n Debug.Print \"Value is null\"\n Else\n ...
null_checks
Private Sub SafeAccess(obj As Object) If obj Is Nothing Then Debug.Print "Object is nothing" Exit Sub End If If IsNull(obj.Value) Then Debug.Print "Value is null" Else Debug.Print obj.Value End If End Sub
private void SafeAccess(object obj) { if (obj == null) { Console.WriteLine("Object is null"); return; } if (obj == DBNull.Value) { Console.WriteLine("Value is null"); } else { Console.WriteLine(obj.ToString()); } }
[ { "role": "user", "content": "Migrate this VB6 code to C# preserving functionality:\n\n```vb6\nPrivate Sub mnuFileExit_Click()\n If MsgBox(\"Are you sure?\", vbYesNo + vbQuestion) = vbYes Then\n Unload Me\n End If\nEnd Sub\nPrivate Sub mnuEditCut_Click()\n Clipboard.SetText txtInput.SelText\...
gui_events
Private Sub mnuFileExit_Click() If MsgBox("Are you sure?", vbYesNo + vbQuestion) = vbYes Then Unload Me End If End Sub Private Sub mnuEditCut_Click() Clipboard.SetText txtInput.SelText txtInput.SelText = "" End Sub Private Sub mnuEditPaste_Click() txtInput.SelText = Clipboard.GetText End Sub
private void mnuFileExit_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { this.Close(); } } private void mnuEditCut_Click(object sender, EventArgs e) { Clipboard.SetText(txtInput.SelectedT...
[ { "role": "user", "content": "Port this VB6 subroutine to C# maintaining the same behavior:\n\n```vb6\nPrivate Sub BringToFront()\n cmdSubmit.ZOrder 0\n lblTitle.ZOrder 1\nEnd Sub\n```\n" }, { "role": "assistant", "content": "```csharp\nprivate void BringToFront()\n{\n cmdSubmit.BringTo...
gui_controls
Private Sub BringToFront() cmdSubmit.ZOrder 0 lblTitle.ZOrder 1 End Sub
private void BringToFront() { cmdSubmit.BringToFront(); lblTitle.SendToBack(); }
[ { "role": "user", "content": "Port this VB6 subroutine to C# maintaining the same behavior:\n\n```vb6\nPrivate Sub CheckStatus()\n Dim score As Integer\n Dim result As String\n score = 75\n result = IIf(score >= 60, \"Pass\", \"Fail\")\n Debug.Print result\nEnd Sub\n```\n" }, { "role"...
operators
Private Sub CheckStatus() Dim score As Integer Dim result As String score = 75 result = IIf(score >= 60, "Pass", "Fail") Debug.Print result End Sub
private void CheckStatus() { int score = 75; string result = score >= 60 ? "Pass" : "Fail"; Console.WriteLine(result); }
[ { "role": "user", "content": "Translate this VB6 code to C# with identical functionality:\n\n```vb6\nPublic Type Point3D\n X As Double\n Y As Double\n Z As Double\nEnd Type\nPrivate Sub CalculateDistance()\n Dim p1 As Point3D\n Dim p2 As Point3D\n p1.X = 0: p1.Y = 0: p1.Z = 0\n p2.X = 3...
structs
Public Type Point3D X As Double Y As Double Z As Double End Type Private Sub CalculateDistance() Dim p1 As Point3D Dim p2 As Point3D p1.X = 0: p1.Y = 0: p1.Z = 0 p2.X = 3: p2.Y = 4: p2.Z = 0 Dim dist As Double dist = Sqr((p2.X - p1.X) ^ 2 + (p2.Y - p1.Y) ^ 2 + (p2.Z - p1.Z) ^ 2) ...
public struct Point3D { public double X; public double Y; public double Z; } private void CalculateDistance() { Point3D p1 = new Point3D { X = 0, Y = 0, Z = 0 }; Point3D p2 = new Point3D { X = 3, Y = 4, Z = 0 }; double dist = Math.Sqrt(Math.Pow(p2.X - p1.X, 2) + Math.Pow(p2.Y - p1.Y, 2) + Math.P...
[ { "role": "user", "content": "Rewrite this Visual Basic 6 code as C#:\n\n```vb6\nPrivate Sub picCanvas_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)\n If Button = vbLeftButton Then\n Debug.Print \"Left click at (\" & X & \", \" & Y & \")\"\n ElseIf Button = vbRightBut...
gui_events
Private Sub picCanvas_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then Debug.Print "Left click at (" & X & ", " & Y & ")" ElseIf Button = vbRightButton Then PopupMenu mnuContext End If End Sub
private void picCanvas_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { Console.WriteLine("Left click at (" + e.X + ", " + e.Y + ")"); } else if (e.Button == MouseButtons.Right) { mnuContext.Show(picCanvas, new Point(e.X, e.Y)); } }