C++ MFC

Moderators: Lundin
Number of threads: 3337
Number of posts: 9005

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
[VC6.0] two questions Posted by bdc on 4 Mar 2003 at 1:43 PM
Hello,
I'm not used to program in VC6.0 so this (probably) won't be difficult questions.

1) How do I build a delay that can time seconds and/or milliseconds
(Now i use a self-written routine that checks the system time, but
that doesn't work for milliseconds and isn't that accurate.

2) How do i convert a double to a CString.
(I can convert an int to ascii with itoa but ftoa(float to ascii)
doesn't exist in my help files.
does anybody knows a routine for this?

THX.
BDC

Report
Re: [VC6.0] two questions Posted by xhim on 4 Mar 2003 at 10:16 PM

hi,
use this functon to convert double to cstring..
CString CStrFromDouble(const double dblValue);
CString CStrFromDouble(const double dblValue)
{
char szTemp[MAX_PATH];

memset(szTemp, 0, MAX_PATH);
sprintf(szTemp, "%f", dblValue);

return CString(szTemp);
}
hope this works fine for you..
cheers
Himanshu



Report
Re: [VC6.0] two questions Posted by bdc on 5 Mar 2003 at 11:41 AM
thx.
That will do.

I've also written an delay routine now.
(for other interested people):

void sdelay(double seconden)
{
double delaytime=seconden*1000;
DWORD delay=static_cast <DWORD> (delaytime);
DWORD systemtimer=GetTickCount();
delay+=systemtimer;
while(systemtimer<delay)
systemtimer=GetTickCount();
}

is only accurate up to 55ms with win98.
Report
Re: [VC6.0] two questions Posted by stober on 6 Mar 2003 at 7:26 AM
This message was edited by stober at 2003-3-6 7:27:20

: thx.
: That will do.
:
: I've also written an delay routine now.
: (for other interested people):
:
: void sdelay(double seconden)
: {
: double delaytime=seconden*1000;
: DWORD delay=static_cast <DWORD> (delaytime);
: DWORD systemtimer=GetTickCount();
: delay+=systemtimer;
: while(systemtimer<delay)
: systemtimer=GetTickCount();
: }
:
: is only accurate up to 55ms with win98.
:


why not use the Win32 API function Sleep(milliseconds)? But it is not very accurate either -- Windows is NOT a real-time operating system so it is impossible to get anything more accurate than about 55ms or so. If you want or need more accuracy you better look at other operating systems -- and unix is not the one to use either.


Report
Re: [VC6.0] two questions Posted by dwccgc on 14 Mar 2003 at 7:23 AM
:
: hi,
: use this functon to convert double to cstring..
: CString CStrFromDouble(const double dblValue);
: CString CStrFromDouble(const double dblValue)
: {
: char szTemp[MAX_PATH];
:
: memset(szTemp, 0, MAX_PATH);
: sprintf(szTemp, "%f", dblValue);
:
: return CString(szTemp);
: }
: hope this works fine for you..
: cheers
: Himanshu
:
:
:
:

You could also try this
  double dValue = 1234.0
  CString strDouble;
  strDouble.Format("%f", dValue);


Report
Re: [VC6.0] two questions Posted by FDrache on 14 Mar 2003 at 2:35 AM
Hello, BDC,

1) Like stober, I would do a simple delay with the Sleep() procedure, in ms. It's actually a minimum delay, because Windows has processes with higher priority.

2) double to CString, with more sophisticated formatting, just an example:
CString FloatOut;
FloatOut.Format("Here is the result: %.3f", MyFloat);
You could append a unit. The formatting is the same as for the sprintf function, see help.





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.