Hey fellows, i have a simple problem this time :) i'm just coding around to get some routine and practice, so i decided to make a simple calculator, but i can't figure out how i save a value vor my adding after i got it from the editbox here's what i got i set the two input strings to 0 .data input1 dd "0" input2 dd "0" when u click calculate: .ELSEIF ax==IDC_CALC invoke GetDlgItemText,hDlg,IDC_EDIT1,addr buffer,512 mov input1,buffer invoke GetDlgItemText,hDlg,IDC_EDIT2,addr buffer,512 mov input2,buffer add input1,input2 invoke SetDlgItemText,hDlg,IDC_RESULT,addr input1 I think the problem is that i can't store the value from the buffer into a variable, is there a way to define two buffers and add them up after ? Regards Typhoon
Theres a couple of problems here. First
you can't do a memory to memory move in assembly. You have to do something like the following
Although this won't work in this case as buffer is a string, not a number. Perhaps the best thing I can do here is show you how to convert the string to number, then you can add it.
mov eax, buffer mov input1, eax
This isn't too hard once you get used to it. Also remember that this only works integers, if you want to use floating point values then read the tutorial I've just finished. You'll find the link in a thread call FPU tutorials.
.model flat, stdcall option casemap :none ; case sensitive include \masm32\include\windows.inc include \masm32\include\user32.inc include \masm32\include\kernel32.inc include \masm32\include\gdi32.inc include \masm32\include\masm32.inc includelib \masm32\lib\user32.lib includelib \masm32\lib\kernel32.lib includelib \masm32\lib\gdi32.lib includelib \masm32\lib\masm32.lib .data buffer db 512 dup(?) input1 dword ? input2 dword ? ; note dword not db .code invoke GetDlgItemText,hDlg,IDC_EDIT1,addr buffer,512 invoke atodw, addr buffer ; convert the string to a dword mov input1, eax ; the number is returned in eax, as in most ; procedures invoke GetDlgItemText,hDlg,IDC_EDIT2,addr buffer,512 invoke atodw, addr buffer ; convert the string to a dword add eax, input1 ; note that seen as the second value is in ; eax we can just add input1 to it. ; Now before we can output the value it must be converted ; into a string invoke dwtoa, eax, addr buffer invoke SetDlgItemText,hDlg,IDC_RESULT,addr buffer
In your case, since the input will always be numeric, you can call GetDlgItemInt instead. That is, if the numbers are integers.
cool thanks guys, that works just fine i tried both ideas and i'm making efforts every minute regards