1 Replies - 1165 Views - Last Post: 24 March 2010 - 07:52 PM Rate Topic: -----

#1 ozzWANTED  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 24-March 10

Text File parser in Forms Application

Posted 24 March 2010 - 05:42 PM

In NetBeans, when I been coding with Java, I hadn't no troble to do this.

I just go to design form tab, and by 'grab and drop' just put the [__________][Browse...] Object. So user via browse just selects the file from hist computer, and after he clicks button in the bottom of the window form, the java parses the file by my requirements(it was similar to assember code parser).

But how to make the same in C#.

I'm using Visual Studio 2008, and in toolbox i don't see the "[_______] [Browse...]" object. It's only openFileDialog exist, but I can't to drag and drop it to form window design area same as I can do with "button" object.

The openFileDialog, somewhy takes his place at the bottom of the window.

Also if it's posible, can anyone provide a code snippet example, how to assign the file selected via [browse] pointer, to the following function parameter "file"( the code bellow).

I got the function for reading first line:
public static string ReadFileLineAtATime(string file)
{
          /   /create a string variable to hold the file contents
                 string fileContents = string.Empty;
                 //create a new TextReader then open the file
                 TextReader reader = new StreamReader(file)
                  //loop through the entire file
                  while (reader.Peek() != -1)
                  {
                                //add each line to the fileContents variable
                                fileContents += reader.ReadLine().ToString();
                  }
                  reader.Close()
                  //return the results
                  return fileContents;
}



I know I need to add actionListener, but I even not able to put the browse box to form application table.
At the bottom of the form, I have object-button called "Button1".
The program should submit the 'file' to my function(code abobe) parameter 'file' just after user clicks the button with name 'Button1'.

------------
The second question, is how to slow-down the parser speed. I mean, that I can set the speed of how much chars of file would be read per second. And after reading one line, how to insert 500ms delay before starting to read the next one.

----

Thanks for the answers.

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Text File parser in Forms Application

#2 lesPaul456  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 173
  • View blog
  • Posts: 729
  • Joined: 16-April 09

Re: Text File parser in Forms Application

Posted 24 March 2010 - 07:52 PM

View PostozzWANTED, on 24 March 2010 - 06:42 PM, said:

In NetBeans, when I been coding with Java, I hadn't no troble to do this.

I just go to design form tab, and by 'grab and drop' just put the [__________][Browse...] Object. So user via browse just selects the file from hist computer, and after he clicks button in the bottom of the window form, the java parses the file by my requirements(it was similar to assember code parser).

But how to make the same in C#.

I'm using Visual Studio 2008, and in toolbox i don't see the "[_______] [Browse...]" object. It's only openFileDialog exist, but I can't to drag and drop it to form window design area same as I can do with "button" object.

The openFileDialog, somewhy takes his place at the bottom of the window.

Also if it's posible, can anyone provide a code snippet example, how to assign the file selected via [browse] pointer, to the following function parameter "file"( the code bellow).

I got the function for reading first line:
public static string ReadFileLineAtATime(string file)
{
          /   /create a string variable to hold the file contents
                 string fileContents = string.Empty;
                 //create a new TextReader then open the file
                 TextReader reader = new StreamReader(file)
                  //loop through the entire file
                  while (reader.Peek() != -1)
                  {
                                //add each line to the fileContents variable
                                fileContents += reader.ReadLine().ToString();
                  }
                  reader.Close()
                  //return the results
                  return fileContents;
}



I know I need to add actionListener, but I even not able to put the browse box to form application table.
At the bottom of the form, I have object-button called "Button1".
The program should submit the 'file' to my function(code abobe) parameter 'file' just after user clicks the button with name 'Button1'.

------------
The second question, is how to slow-down the parser speed. I mean, that I can set the speed of how much chars of file would be read per second. And after reading one line, how to insert 500ms delay before starting to read the next one.

----

Thanks for the answers.


There is no "Browse..." control. You have to create you're own, using a text box and button. Then, drag a OpenFileDialog onto the form. It won't show up on the form, it's not that kind of control.

Then, create a click event handler for the button. Then, you would add something like this to the event handler:

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
    string fileContents = ReadFileLineAtATime(openFileDialog1.FileName);
}



To pause after each line, you can add something like this to the ReadFileLineAtATime method:

public static string ReadFileLineAtATime(string file)
{
    //create a string variable to hold the file contents
    string fileContents = string.Empty;

    //create a new TextReader then open the file
    TextReader reader = new StreamReader(file)
    
    //loop through the entire file
    while (reader.Peek() != -1)
    {
        //add each line to the fileContents variable
        fileContents += reader.ReadLine().ToString();

        // Pause thread for 500ms.
        System.Threading.Thread.Sleep(500);
    }

    reader.Close()
    //return the results
    return fileContents;
}


This post has been edited by lesPaul456: 24 March 2010 - 07:53 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1