Search code examples
windowsassemblymasm

assembly masm how do you subtract 2 textboxes


I have 2 text boxes with numbers in them. how do I subtract them and put the result in a third text box.

I tried this

.data

gettext1            DB 100 DUP(?)
gettext2           DB 100 DUP(?)
gettext3            DB 100 DUP(?)

.code

LOCAL pmem1  :DWORD

        invoke GetDlgItemText,hWin,MeasuredlengthXtextbox,esi,100

    invoke GetDlgItemText,hWin,MeasuredlengthYtextbox,edi,100

    sub esi,edi 

    mov pmem1,esi   

    invoke lstrcpy,addr gettext1,pmem1

    invoke SetDlgItemText,hWin,ResultlengthXtextbox,addr gettext3

when I try this code it shows up nothing in the textbox

thanks


Solution

  • First, the third parameter to GetDlgItemText is a pointer to a buffer to hold the string. A register will not work. You need to load esi and edi with the addresses of buffers, say gettext1 and gettext2.

    Second, you cannot add strings. The number 1 you see on the screen is not really a number, but an ASCII version of the number.

    You need to get the text, convert to a number, subtract, then convert back to a string to use with SetDlgItemText.

    To make your life easier, just use GetDlgItemInt which will convert the number string to a number and return in eax, then use SetDlgItemInt