data sharing between dialog boxes

Posted on 1998-08-13
Last Modified: 2013-11-20
I have several dialog boxes in my project and I need to take amounts from one screen to another, will someone please tell me how to share the data between them. I have already create variables for the edit boxes which I am trying to share data between. The data I am trying to get is in CService2Dialog and I am trying to place it in CServiceDialog.  The variables are m_billtime(CServiceDialog) & and want it to come from m_totlab(CService2Dialog). These variables are double. When the user hits the "Calculate" button on page 1 the amount should appear in the corresponding edit box.  If this can be done without hitting the button it does not matter but I figured it might be easier. Please tell me exactly where to put the statements because I do not understand Visual C++ 5.0 completley at this point.
Also if it is not to much trouble show me how to get zeros at the end of the number.  eg. if the data is 1, I want it to show 1.00(dollar figures).

Thank You for the much need help!      
I apologize for enter this question the second time but the first answer didn't work because I am only new to programming in Visual C++ 5.0 and I could not figure it out after hours of struggling.

//This is the Calculate button on page 1.  
void CServiceDialog::OnCalcButton()
      // TODO: Add your control notification handler code here
      UpdateData(TRUE); // get data from controls
      //Here is where I want to recieve data from page 2 and place it here to calculate the data on page 1.
      //output the new data recieved.
      //ignore this it is only other calculations.
      m_tottravel.Format("%.2f", atof(m_billtravel)*atof(m_ratetravel));  //calculate total labour
      m_totlabour.Format("%.2f", atof(m_billtime)*atof(m_ratelabour));
      m_totinv.Format("%.2f", atof(m_totparts)+atof(m_tottravel)+atof(m_totlabour)); //calc total invoice
       UpdateData(FALSE); // send data to controls


Question by:troy11
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

trestan earned 100 total points
ID: 1320736
There are several ways available to do it.
The first, you can save your data in a data file using fstream of CFile. Then read the data from this file in another dialog.
The second, I think you create the dialogs in your view, right? So you can exchange data between each dialogs' data memebers. E.g. ServiceDialog.m_billtime = Service2Dialog.m_totlab, where the ServiceDialog and Service2Dialog are the instances of the corresponding classes in your View. Pls contact with me if any futher questions.


Expert Comment

ID: 1320737
In the class given n ur Qn, add a member variable which is a pointer to CServiec1Dialog (or any other required dlg). Using that pointer, u can do an UpdateData(TRUE) on it and then get value.

void CServiceDialog::OnCalcButton()
   UpdateData(TRUE); // get data from controls

   //a pointer to CService1Dlg is to be declared in    
   pCService1Dlg->UpdateData(TRUE); //prepare to get data from            
                                    //other dlg
  // similarly to send data to controls...


Author Comment

ID: 1320738
When I place this code in my calculate button

CServiceDialog.m_billtime = CService2Dialog.m_totlab;

it gives me these error messages

C:\visualc++5\menu\ServiceDialog.cpp(87) : error C2143: syntax error : missing ';' before '.'
C:\visualc++5\menu\ServiceDialog.cpp(87) : error C2143: syntax error : missing ';' before '.'

can anyone help me?

what do you mean by - n ur Qn-


Author Comment

ID: 1320739
This code is in calculate button and I am trying to access data from CService2Dialog and place it in CServiceDialog.  Ther is an Exit button and a Page 1 button on page 2 (CService2Dialog).  The exit uses OnOK() and the page 1 use DoModal. Is this causing me a problem when I try to access my data on page 1 because I have to press either to get to page 1 or is it the cout<<m_billtime

void CServiceDialog::OnCalcButton()
      // TODO: Add your control notification handler code here
      UpdateData(TRUE); // get data from controls
      CService2Dialog m_SrvDlg2;
      CServiceDialog m_SrvDlg;
      m_SrvDlg.m_billtime = m_SrvDlg2.m_totlab;

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 110
countEvens challenge 2 117
has22 challenge 11 111
has77  challenge 9 107
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question