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
  • 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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
Perl Awk Need Help 3 129
countEvens challenge 2 112
scoreUp challenge 14 64
wordappend challenge 8 202
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

828 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