Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieveing data from Dalog box

Status
Not open for further replies.

Larree

Programmer
Dec 31, 2002
20
SG
Dear all,

I m trying to retrieve a value Timing1 from a dialog box named CTimeDlg to my CMainFrame. The code that I use is as follows:

CTimeDlg Timedlg;
CTime STime = Timedlg.Timing1;
CTime Now = CTime::GetCurentTime();

CTimeSpan Interval = Now - STime;
CString Timing = Interval.Format("%H:%M:%S");

The value of Timing is obtained but is not the expected value. I found that the value of Timedlg.Timing1 is not the expected value that I intended to retrieve. It has taken on some other value though I have no idea where the value is gotten from. Compilation generates no error. Is there something wrong with the way I retrieve my ata? Please advise......thanks
 
Has there even been an OnInitDialog() run or something like that? I don't think that only creating a dialog object will initialize your member variables the way you would expect them.
Greetings,
Rick
 
>> I don't think that only creating a dialog object will
>> initialize your member variables the way you would
>> expect them.

That may in fact be true, but it should not be the case.

CTimeDlg Timedlg; does of course execute the constructor and therefore the Timing1 member variable will contain the value that it was initialized to in the constructor.

-pete
 
Hi Rick,

I am actually trying to retrieve a value Timing1 from a dialog box named CTimeDlg. The dialog is ok. It is just that I want to import this value to do calculation in a function in CMainFrame. However using the above code, I cannot get the desired value. In the CTimeDlg, the correct value has already been set to the variable Timing1......Please advice.....Thanks
 
Exactly, palbano. That's actually what I meant. You would have to explicitly set the value there, which, in the case of dialogs, is not the most common place......

Larree, where do you set the value you want to retrieve?
Greetings,
Rick
 
Hi,

I am not too sure if I am answering what u r asking Rick. So please correct me if I m wrong. The value that I want to retrieve is the value of the time when the "OK" button is clicked in the CTimeDlg dialog box. On "OK" the CTime Timing1 variable is assigned the current time in the system clock. This is the value that I want to retrieve to another function in CMainFrame. But this retrieval of the value in Timing1 will occur some time later when the function is triggered. Do I need to use GetDlgItem? Or is the method that I described above correct? Thanks.....
 
CTimeDlg Timedlg;
Timedlg.DoModal();
CTime STime = Timedlg.Timing1;
CTime Now = CTime::GetCurentTime();

Your posted code differs from your english discription of what you are doing as noted above.

-pete
 
Hi Pete,

I have no intention of opening the dialog box. If I m not wrong, using DoModal() will open the dialog box on the screen right? I only wish to retrieve a value from the CTimeDlg dialog and not open the entire dialog. So is the code you have shown above still workable?
 
The value that I want to retrieve is the value of the time when the "OK" button is clicked in the CTimeDlg dialog box.

Larree, don't take offense to this but your posts are very confusing. The one i quoted in bold says you use the dialog box's "OK" button. Then you say this:

I have no intention of opening the dialog box.

How do you click the "OK" button with out first opening the dialog box? [bugeyed]

-pete
 
Sorry for being so confusing pete.......The dialog box is originally open. By clicking the "OK" button I actually start a timer. I record the start time as Timing1. The timer continues running all the while. Then a sort of tag is supposed to be read and it triggers another function in the CMainFrame. This is the function in which I want to retrieve the value of Timing1 to coz I want to calculate the span of time between the start time and the time the tag is read. Hope that makes the picture clearer. In teh function I have a CTime::GetCurrentTime() function to record the time the tag is read. So now I need to get teh start time which is in CTimeDlg......
 
After the dialog has been dismissed, start the timer in the calling code. It doesn't seem like the dialog needs to be involved at all.
 
hehe, yes i agree with apatterno, in fact you could just use a menu item/toolbar button as the command handler to start the timer and remove the dialog altogether.

-pete
 
Pete and apatterno,

I agree with you both.

Larree, Just for the record:
the right way to retrieve data from a dialog box is through the DoDataExchange(pDx) function, (it has to be in your CDialog definition),

Regards,

Ricardo
 
Hi all,

Thanks for the advice......I think I have gotten it :)

Cheers
Larree
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top