Click here to Skip to main content
16,007,858 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Imports System.IO
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Id As String
        Dim Name As String
        Dim Gender As String
        Dim Address As String

        Try

            Dim sr As StreamReader
            Dim fs As FileStream
            fs = New FileStream(("C:\temp\a.txt"), FileMode.OpenOrCreate)
            sr = New StreamReader(fs)
            Dim itm As Object
            itm = sr.ReadLine
            While Not itm = Nothing
                Dim split As String() = itm.Split(New [Char]() {" "})
                Id = split(0)
                Name = split(1)
                Gender = split(2)
                Address = split(3)
                ListView1.Items.Add(Id)
                ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(Name)
                ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(Gender)
                ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(Address)
                itm = sr.ReadLine
            End While

            sr.Close()
            fs.Close()
            ListView1.Columns.Add("Id", 70, HorizontalAlignment.Center)
            ListView1.Columns.Add("Name", 70, HorizontalAlignment.Center)
            ListView1.Columns.Add("Gender", 70, HorizontalAlignment.Center)
            ListView1.Columns.Add("Address", 70, HorizontalAlignment.Center)
            ListView1.View = View.Details
            ListView1.GridLines = True
            ListView1.BackColor = Color.Aqua
            ListView1.ForeColor = Color.Blue
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message, "Load Tool Data Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
End Class

Thanks
Posted
Comments
phanny 2011 10-Jan-12 20:47pm    
Can all of you help me to convert this code to C#.net?

Thanks

1 solution

I used a website http://www.developerfusion.com/tools/convert/vb-to-csharp/[^] to convert. I am not sure it is correct or not, at least it is formatted already ;)
c#.net
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
public class Form1
{

  private void Form1_Load(System.Object sender, System.EventArgs e)
  {
    string Id = null;
    string Name = null;
    string Gender = null;
    string Address = null;
    try {
      StreamReader sr = null;
      FileStream fs = null;
      fs = new FileStream(("C:\\temp\\a.txt"), FileMode.OpenOrCreate);
      sr = new StreamReader(fs);
      object itm = null;
      itm = sr.ReadLine();
      while (!(itm == null)) {
        string[] split = itm.Split(new Char[] { " " });
        Id = Strings.Split(0);
        Name = Strings.Split(1);
        Gender = Strings.Split(2);
        Address = Strings.Split(3);
        ListView1.Items.Add(Id);
        ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(Name);
        ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(Gender);
        ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(Address);
        itm = sr.ReadLine();
      }
      sr.Close();
      fs.Close();
      ListView1.Columns.Add("Id", 70, HorizontalAlignment.Center);
      ListView1.Columns.Add("Name", 70, HorizontalAlignment.Center);
      ListView1.Columns.Add("Gender", 70, HorizontalAlignment.Center);
      ListView1.Columns.Add("Address", 70, HorizontalAlignment.Center);
      ListView1.View = View.Details;
      ListView1.GridLines = true;
      ListView1.BackColor = Color.Aqua;
      ListView1.ForeColor = Color.Blue;
    } catch (System.Exception ex) {
      System.Windows.Forms.MessageBox.Show(ex.Message, "Load Tool Data Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
  }
  public Form1()
  {
    Load += Form1_Load;
  }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900