News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Simple question about adding vars

Started by sayain_code, December 28, 2009, 02:36:50 AM

Previous topic - Next topic

sayain_code

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?



         

sinsi

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'  ::)
Light travels faster than sound, that's why some people seem bright until you hear them.

jj2007

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

sinsi

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.
Light travels faster than sound, that's why some people seem bright until you hear them.