2 Replies - 553 Views - Last Post: 12 January 2012 - 04:28 PM Rate Topic: -----

Topic Sponsor:

#1 norman1312  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 57
  • Joined: 08-September 11

Dialog box not reading data

Posted 12 January 2012 - 05:58 AM

I am running a program created using Visual C++ 2010 Express.
I have several dialog boxes to read input data.
One works perfectly, but a second one simply does not read any data at all, and I cannot figure out why.
The problem dialog is defined as
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG6 DIALOG 0, 0, 227, 105
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Date for Chart"
FONT 8, "Ms Shell Dlg"
{
    DEFPUSHBUTTON   "OK", IDOK, 166, 5, 50, 14
    PUSHBUTTON      "Cancel", IDCANCEL, 166, 26, 50, 14
    EDITTEXT        IDC_EDIT7, 14, 20, 71, 16, ES_AUTOHSCROLL
    EDITTEXT        IDC_EDIT8, 95, 20, 44, 16, ES_AUTOHSCROLL
    AUTORADIOBUTTON "Monthly", ID_CHECKBOXM, 20, 50, 41, 8,  WS_GROUP | WS_CHILD | WS_VISIBLE | WS_TABSTOP
    AUTORADIOBUTTON "Quarterly", ID_CHECKBOXQ, 20, 65, 44, 8,  WS_CHILD | WS_VISIBLE 
    AUTORADIOBUTTON "Six Months", ID_CHECKBOX6, 20, 80, 51, 8, WS_CHILD | WS_VISIBLE 
}


and is read using
	GetDlgItemTextA(hDlg, IDC_EDIT7, mx, SMALL);
	GetDlgItemTextA(hDlg, IDC_EDIT8, yx, SMALL);
	
	FindMonth(mx, &mxx); // convert from character name to numeric month
	sscanf_s(yx, "%d", &yxx); // string to numeric year
        dd2 = DateOfEnd(mxx, yxx); // Get last day of month
	Number2 = DayNumber(yxx, mxx, dd2);
	MyDates->day2   = dd2;
	MyDates->month2 = mxx;
	MyDates->year2  = yxx;
	MyDates->DayNumber2 = Number2;

        /* Check if Quarterly or Monthly */
        if (IsDlgButtonChecked(hDlg, ID_CHECKBOXM) == BST_CHECKED)
        {
            LastOption = value;
            value = MONTHLY;
            CheckOne = ID_CHECKBOXM;
        }
        else if (IsDlgButtonChecked(hDlg, ID_CHECKBOXQ) == BST_CHECKED)
        {
            LastOption = value;
            value = QUARTERLY;
            CheckOne = ID_CHECKBOXQ;
        }
        else
        {
            LastOption = value;
            value = SIXMONTHS;
            CheckOne = ID_CHECKBOX6;
        }


Investigation shows mx and yx both are null strings, and value is always SIXMONTHS.
As I said I have a different dialog box that only uses six Get's and that works perfectly. As far as I can see I have coded this correctly.
What am I doing wrong?

Is This A Good Question/Topic? 0
  • +

Replies To: Dialog box not reading data

#2 JackOfAllTrades  Icon User is online

  • No Sugar Coding Here!
  • member icon

Reputation: 4679
  • View blog
  • Posts: 20,356
  • Joined: 23-August 08

Re: Dialog box not reading data

Posted 12 January 2012 - 03:14 PM

Assuming that the GetDlgItemText call(s) are the problem (that seems to be how you're populating mx and my, which you state results in NULLs), I refer you to the manual for GetDlgItemText:

Quote

Return value

Type: UINT

If the function succeeds, the return value specifies the number of characters copied to the buffer, not including the terminating null character.

If the function fails, the return value is zero. To get extended error information, call GetLastError.


You are not checking the return values for these functions. That's the next step in your debugging process.
Was This Post Helpful? 0
  • +
  • -

#3 GunnerInc  Icon User is online

  • "Hurry up and wait"
  • member icon

Reputation: 313
  • View blog
  • Posts: 898
  • Joined: 28-March 11

Re: Dialog box not reading data

Posted 12 January 2012 - 04:28 PM

What is SMALL? What is mx defined as? You need to pass a pointer to a buffer where GetDlgItemText will store the text, and you must pass the length of the buffer.

If all you want is a number, then try using GetDlgItemInt, that will convert the text into a number and return it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1