The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: sayain_code on December 28, 2009, 02:36:50 AM

Title: Simple question about adding vars
Post by: sayain_code on December 28, 2009, 02:36:50 AM
What i want to do is get the value from 2 different edit box and add them together for a total.

;Get Value 0
invoke GetDlgItemInt,hWin,IDC_EDT1,addr Value0,0

;Get Value 1
invoke GetDlgItemInt,hWin,IDC_EDT2,addr Value1,0
      
;Add them together   
mov eax,Value0
add eax,Value1
mov Total,eax
         
invoke SetDlgItemInt,hWin,IDC_STC1,Total,0

This doesnt work correctly. what am i doing wrong?



         
Title: Re: Simple question about adding vars
Post by: sinsi on December 28, 2009, 03:02:02 AM
Value0 and Value1 only get filled with true or false, the returned number is in EAX.

invoke GetDlgItemInt,hWin,IDC_EDT1,0,0
mov Value0,eax
invoke GetDlgItemInt,hWin,IDC_EDT2,0,0
add eax,Value0
invoke SetDlgItemInt,hWin,IDC_STC1,eax,0

If you need to check for a valid return, use

invoke GetDlgItemInt,hWin,IDC_EDT1,addr IsCorrect,0
cmp IsCorrect,FALSE
jz not_a_number


edit:changed 'rax' to 'eax'  ::)
Title: Re: Simple question about adding vars
Post by: jj2007 on December 28, 2009, 08:39:28 AM
Read the documentation carefully:
QuoteHWND hDlg,   // handle to dialog box
    int nIDDlgItem,   // control identifier
    BOOL *lpTranslated,   // points to variable to receive success/failure indicator
    BOOL bSigned    // specifies whether value is signed or unsigned

What you need is
Quoteinvoke GetDlgItemInt, hWin, IDC_EDT1, addr MyBool, 0
mov Value0, eax
etc
Title: Re: Simple question about adding vars
Post by: sinsi on December 28, 2009, 08:17:20 PM
You only need the true/false variable if you want to know whether the conversion succeeded/failed.
Quote
lpTranslated
[out] Pointer to a variable that receives a success or failure value (TRUE indicates success, FALSE indicates failure).
If this parameter is NULL, the function returns no information about success or failure.