954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

a simple gui

Hello all,
I want to write a qui program which opens and reads a text file when pressed Open File button. So far, when I click the button Open File Dialog works and I can choose the file to read but I do not know how to read it line by line. The code for click event is below. Can you please tell me what is the next step?

#pragma endregion
	private: System::Void open_file_button_Click(System::Object^  sender, System::EventArgs^  e) {
	//we use OpenFileDialog to show a file-open dialog box
      OpenFileDialog ^ openFileDialog1 = gcnew OpenFileDialog();
      openFileDialog1->Filter = "Text Files|*.txt";
      openFileDialog1->Title = "Select the File";

      // Show the Dialog.
      
      if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
      {
      // pop up a message box if user selects a file               System::Windows::Forms::MessageBox::Show(L"deneme",L"test",System::Windows::Forms::MessageBoxButtons::OK);
      }
			 }
esesili
Light Poster
38 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 
Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Thank for the tutorial. I succeeded what I want. However, I have one more question. If I want to see the 3rd line in the file what I have to do? By the way, could you please check the program and give me some feedback?
I appreciate for helps,

#pragma endregion
		
	private: System::Void open_file_button_Click(System::Object^  sender, System::EventArgs^  e)
			 {
	  String ^ file_name;
	  String ^ input;
      OpenFileDialog ^ openFileDialog1 = gcnew OpenFileDialog();
      openFileDialog1->Filter = "Text Files|*.txt";
      openFileDialog1->Title = "Select the File";

      
      if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
      {
		  file_name = System::IO::Path::GetFullPath(openFileDialog1->FileName);
		  StreamReader^ sr = File::OpenText(file_name);
		  double number_file;
		  double initial = 0;
		  double summ;
		  String ^ result;
		  while((input=sr->ReadLine())!=nullptr)
		  {
			  number_file = Convert::ToDouble(input);
			  summ = initial + number_file;
			  initial = summ;
		  }
		  result = Convert::ToString(initial);
		  System::Windows::Forms::MessageBox::Show(result,L"test",System::Windows::Forms::MessageBoxButtons::OK);
		 
	  }
			 }
esesili
Light Poster
38 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

>>If I want to see the 3rd line in the file what I have to do?

You have to read the file sequentially until you get to the line you want.

>>could you please check the program and give me some feedback?
It's not really necessary for anyone else to check your program, you can do it yourself just by running it and see if it works or not.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

I know that anyone does not necessarily has to check my program that's why I start my question with "could you". By the way, I appreciate for your helps.

esesili
Light Poster
38 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: