Howdy, Stranger!

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

Categories

Trying to Input decimals using EditBox

Hi ,
I have worked out how to store my input into My EDIT box via a Global int,and recall it using GetDlgItemInt(), and I can display the result using wsprintf and SetWindowText().
My problem is, I wish to be able to input decimals eg 2.7, and then be able to display decimals to 2 decimal places.
I have tried using float and double, but EDIT dose not seem to recognise it.
hInput = CreateWindowEx(0,
"EDIT",
"",
ES_AUTOVSCROLL | ES_LEFT | ES_WANTRETURN | WS_CHILD | WS_VISIBLE ,
10,180,100,26,
hWnd,
(HMENU)ID_INPUT,
GetModuleHandle(NULL),
NULL );

if(!hInput)
{
MessageBox(hWnd,"Failed to Create PassBox","ERROR!",MB_OK);

}
Below is my input
float MyInput; //Global int this comes from top of my code

case ID_FTM:
if(Glob<200000)// Just a temp Global int
{

MyInput=GetDlgItemInt(hWnd, ID_INPUT,NULL,TRUE);

if(MyInput==2.5){MessageBox(hWnd,"2.5","Input=",MB_OK);}
//The above MessageBox is used only to test the input.
//It works with non decimal inputs, but code wont recognise
//decimals.
}

break;

Could any one please point me in the right Direction,I am using Borland Bcc5.5 No MFC
Thanks



Comments

  • pingpongpingpong Member Posts: 937
    Use something like this:

    char buffer[800];
    GetDlgItemText(hWnd, ID_INPUT, buffer, sizeof(buffer));
    MyInput = (float)atof(buffer);

  • OldfellaOldfella Member Posts: 6
    [b][red]This message was edited by Oldfella at 2002-10-5 20:34:41[/red][/b][hr]
    : Use something like this:
    :
    : char buffer[800];
    : GetDlgItemText(hWnd, ID_INPUT, buffer, sizeof(buffer));
    : MyInput = (float)atof(buffer);
    :
    :
    pingpong,
    Works great,Thanks mate.
    One last Question,My display Box bellow
    hDisp = CreateWindowEx(0,
    "STATIC",
    "",
    //WS_CHILD | SS_CENTER,
    WS_CHILD | WS_VISIBLE ,
    150,180,120,26,
    hWnd,
    (HMENU)ID_DISP,
    GetModuleHandle(NULL),
    NULL );
    What would be the best way to display my result,I guess I now have to turn my float result back into a string. I have been playing with

    case ID_FTM:
    //other code in here
    {
    char Globs [100]; //Buffer external of this Block(Global)
    wsprintf(Globs, "%d Metres",MyInput);
    SetWindowText (hDisp, Globs) ;
    }
    break;

    I have looked at fcvt()and gcvt(), I just can't Quite work it out,
    I'm Trying to display to 2 decimal Places.
    Sorry for the addon, I meant this to be included with the original Question.
    Take Care.
    Oldfella


  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : [b][red]This message was edited by Oldfella at 2002-10-5 20:34:41[/red][/b][hr]
    : : Use something like this:
    : :
    : : char buffer[800];
    : : GetDlgItemText(hWnd, ID_INPUT, buffer, sizeof(buffer));
    : : MyInput = (float)atof(buffer);
    : :
    : :
    : pingpong,
    : Works great,Thanks mate.
    : One last Question,My display Box bellow
    : hDisp = CreateWindowEx(0,
    : "STATIC",
    : "",
    : //WS_CHILD | SS_CENTER,
    : WS_CHILD | WS_VISIBLE ,
    : 150,180,120,26,
    : hWnd,
    : (HMENU)ID_DISP,
    : GetModuleHandle(NULL),
    : NULL );
    : What would be the best way to display my result,I guess I now have to turn my float result back into a string. I have been playing with
    :
    : case ID_FTM:
    : //other code in here
    : {
    : char Globs [100]; //Buffer external of this Block(Global)
    : wsprintf(Globs, "%d Metres",MyInput);
    : SetWindowText (hDisp, Globs) ;
    : }
    : break;
    :
    : I have looked at fcvt()and gcvt(), I just can't Quite work it out,
    : I'm Trying to display to 2 decimal Places.
    : Sorry for the addon, I meant this to be included with the original Question.
    : Take Care.
    : Oldfella
    :
    :
    :
    [blue][b]%d[/b] is for integers, use [b]%f[/b] for decimals. Also, see more formatting options for [b]wsprintf()[/b] in MSDN.[/blue]
  • Justin BibJustin Bib USAMember Posts: 0

    ______ || http://forcoder.org || free ebooks and video tutorials about / Swift, Assembly, JavaScript, Python, C++, Ruby, Objective-C, Scratch, Visual Basic, C, PL/SQL, Visual Basic .NET, MATLAB, R, C#, Perl, PHP, Go, Delphi, Java Fortran, Logo, Bash, ABAP, Alice, ML, Clojure, Awk, SAS, Prolog, COBOL, Rust, F#, Crystal, Dart, Erlang, VBScript, Scheme, Transact-SQL, Ada, Scala, Lua, Lisp, FoxPro, LabVIEW, D, Apex, Julia, Kotlin, Hack / _

Sign In or Register to comment.