[VC6.0] two questions - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

[VC6.0] two questions

bdcbdc Posts: 5Member
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

Comments

  • xhimxhim Posts: 108Member
    [red]
    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



  • bdcbdc Posts: 5Member
    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 (delaytime);
    DWORD systemtimer=GetTickCount();
    delay+=systemtimer;
    while(systemtimer<delay)
    systemtimer=GetTickCount();
    }

    is only accurate up to 55ms with win98.
  • stoberstober Posts: 9,765Member ✭✭✭
    [b][red]This message was edited by stober at 2003-3-6 7:27:20[/red][/b][hr]
    : 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 (delaytime);
    : DWORD systemtimer=GetTickCount();
    : delay+=systemtimer;
    : while(systemtimer<delay)
    : systemtimer=GetTickCount();
    : }
    :
    : is only accurate up to 55ms with win98.
    :


    [blue]why not use the Win32 API function Sleep(milliseconds)? But it is not very accurate either -- Windows is [red]NOT[/red] 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.


  • FDracheFDrache Posts: 64Member
    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.


  • dwccgcdwccgc Posts: 576Member
    : [red]
    : 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
    :
    :
    :
    :

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

Sign In or Register to comment.