Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to read data from text file using CMFCEditBrowseCtrl vc++

How to read data from text file using CMFCEditBrowseCtrl vc++

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
6 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lolici
    wrote on last edited by
    #1

    Hello everyone! I am trying to use a CMFCEditBrowseCtrl button (in CFeaturesDialog class) to read numbers (integer) from a text file and then pass those numbers in separate text files (in CDataDialog class), each file for every number. So I wrote:

    void CFeaturesDialog::OnEnChangeMfceditbrowse1()
    {
    CString str;
    m_browser.GetWindowTextW(str); //CMFCEditBrowseCtrl m_browser;

    }

    void CDataDialog::OnBnClickedOk()
    {
    CStdioFile file(L"over1.txt", CFile::modeCreate |
    CFile::modeWrite);
    }

    e.g. if there 2 numbers in text file I open with CMFCEditBrowseCtrl I want to create over1.txt which will include the first number and over2.txt which will include the second number. How could I do that? Thank you in advance!

    D L 2 Replies Last reply
    0
    • L lolici

      Hello everyone! I am trying to use a CMFCEditBrowseCtrl button (in CFeaturesDialog class) to read numbers (integer) from a text file and then pass those numbers in separate text files (in CDataDialog class), each file for every number. So I wrote:

      void CFeaturesDialog::OnEnChangeMfceditbrowse1()
      {
      CString str;
      m_browser.GetWindowTextW(str); //CMFCEditBrowseCtrl m_browser;

      }

      void CDataDialog::OnBnClickedOk()
      {
      CStdioFile file(L"over1.txt", CFile::modeCreate |
      CFile::modeWrite);
      }

      e.g. if there 2 numbers in text file I open with CMFCEditBrowseCtrl I want to create over1.txt which will include the first number and over2.txt which will include the second number. How could I do that? Thank you in advance!

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      lolici wrote:

      I am trying to use a CMFCEditBrowseCtrl button (in CFeaturesDialog class) to read numbers... e.g. if there 2 numbers in text file I open with CMFCEditBrowseCtrl...

      The CMFCEditBrowseCtrl class does not open files. That class is simply an editable text box that optionally contains a browse button. Are the numbers in the source file (comma) delimited, or one per line? Since I do not know the answer to either of this, I will error on the side of the latter, something like:

      CStdioFile fileSource("source.txt", CFile::modeRead);
      CStdioFile fileDest;
      CString strLine;
      CString strFile;
      int num = 1;

      while (file.ReadString(strLine))
      {
      strFile.Format("over%d.txt", num++);
      fileDest.Open(strFile, CFile::modeWrite);
      fileDest.WriteString(strLine);
      fileDest.Close();
      }

      fileSource.Close();

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

      L 1 Reply Last reply
      0
      • L lolici

        Hello everyone! I am trying to use a CMFCEditBrowseCtrl button (in CFeaturesDialog class) to read numbers (integer) from a text file and then pass those numbers in separate text files (in CDataDialog class), each file for every number. So I wrote:

        void CFeaturesDialog::OnEnChangeMfceditbrowse1()
        {
        CString str;
        m_browser.GetWindowTextW(str); //CMFCEditBrowseCtrl m_browser;

        }

        void CDataDialog::OnBnClickedOk()
        {
        CStdioFile file(L"over1.txt", CFile::modeCreate |
        CFile::modeWrite);
        }

        e.g. if there 2 numbers in text file I open with CMFCEditBrowseCtrl I want to create over1.txt which will include the first number and over2.txt which will include the second number. How could I do that? Thank you in advance!

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Where is the code to read the original file, and where do you store the two numbers? Once you have the numbers then writing them to their separate files is quite straightforward. It would be better if you generate the output file names dynamically, rather than hard coding them. It is also better to not use the W suffixes on Windows API calls; let the compiler generate the correct names based on your project settings.

        1 Reply Last reply
        0
        • D David Crow

          lolici wrote:

          I am trying to use a CMFCEditBrowseCtrl button (in CFeaturesDialog class) to read numbers... e.g. if there 2 numbers in text file I open with CMFCEditBrowseCtrl...

          The CMFCEditBrowseCtrl class does not open files. That class is simply an editable text box that optionally contains a browse button. Are the numbers in the source file (comma) delimited, or one per line? Since I do not know the answer to either of this, I will error on the side of the latter, something like:

          CStdioFile fileSource("source.txt", CFile::modeRead);
          CStdioFile fileDest;
          CString strLine;
          CString strFile;
          int num = 1;

          while (file.ReadString(strLine))
          {
          strFile.Format("over%d.txt", num++);
          fileDest.Open(strFile, CFile::modeWrite);
          fileDest.WriteString(strLine);
          fileDest.Close();
          }

          fileSource.Close();

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          L Offline
          L Offline
          lolici
          wrote on last edited by
          #4

          Do I have to include the text file (source.txt) in project?? Cause I got the message "source.txt file not found". The content of the file can change any time by any user is that a problem??

          D 1 Reply Last reply
          0
          • L lolici

            Do I have to include the text file (source.txt) in project?? Cause I got the message "source.txt file not found". The content of the file can change any time by any user is that a problem??

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            lolici wrote:

            Do I have to include the text file (source.txt) in project??

            That's the name of the file you would retrieve from CMFCEditBrowseCtrl.

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

            L 1 Reply Last reply
            0
            • D David Crow

              lolici wrote:

              Do I have to include the text file (source.txt) in project??

              That's the name of the file you would retrieve from CMFCEditBrowseCtrl.

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              L Offline
              L Offline
              lolici
              wrote on last edited by
              #6

              The code you wrote above must be written in class void CDataDialog::OnBnClickedOk() ?Cause I have declare this class in a different dialog. I'm sorry for asking again, I got a little bit confused.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups