Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • Last Modified:

data sharing between dialog boxes

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.
      cout<<m_billtime;
      
      //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

}

0
troy11
Asked:
troy11
  • 2
1 Solution
 
trestanCommented:
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.

0
 
arun_taCommented:
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.

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

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

0
 
troy11Author Commented:
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-

0
 
troy11Author Commented:
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;
 
      cout<<m_billtime;
...      
}
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now