Solved

data sharing between dialog boxes

Posted on 1998-08-13
4
202 Views
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.
      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
Comment
Question by:troy11
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
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.

0
 
LVL 1

Expert Comment

by:arun_ta
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.

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
 

Author Comment

by:troy11
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-

0
 

Author Comment

by:troy11
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;
 
      cout<<m_billtime;
...      
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

937 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now