i need some help. i have edit boxes and i use GetDlgItemText to get the text in the two edit boxes and i place them into variables i declared as:
Var1 db 20 dup(?)
Var2 db 20 dup(?)
;compare code
invoke GetDlgItemText,hWnd,FEILD_ONE,Var1,20 ;get first feild
invoke GetDlgItemText,hWnd,FEILD_TWO,Var2,20 ;get second feild
invoke lstrcmp,addr Var1,addr Var2
.IF ax==0
invoke SetDlgItemText,hWnd,FEILD_COMP,addr Yes ;yes they are
this code seems to crash my prog any help on comparing the two variables would be greatly appreciated.
thanx
-brad
The first level of simple debug you can do is to comment out portions of code where you think the bug may lie.
Then recompile, run and see. If the bug is gone, let code come back in small dribbles to see which line is actually causing the fault.
Message boxes can also emit useful info. Ultimately, you can build up a nice file of things to debug with and just include it in your project's early stages.
Glaring errors
Var1 db 20 dup(?)
Var2 db 20 dup(?)
.......
invoke GetDlgItemText,hWnd,FEILD_ONE,Var1,20 ;get first feild
invoke GetDlgItemText,hWnd,FEILD_TWO,Var2,20 ;get second feild
invoke lstrcmp,addr Var1,addr Var2
Should be:
invoke GetDlgItemText,hWnd,FEILD_ONE,addr Var1,20 ;get first feild
invoke GetDlgItemText,hWnd,FEILD_TWO,addr Var2,20 ;get second feild
Var1 db 20 dup(?)
Var2 db 20 dup(?)
.......
invoke GetDlgItemText,hWnd,FEILD_ONE,addr Var1,20
invoke GetDlgItemText,hWnd,FEILD_TWO,addr Var2,20
mov esi, offset Var1
mov edi, offset Var2
mov ecx, 20
cld
repe cmpsb
jne @@ne ;here jump where not equal
;here we get if equal
isumenko
your comparison routine has a flaw. It will work correctly IF both strings are exactly 20 bytes in size. If the strings are less than 20 bytes, the result may be wrong even if the strings are identical. This is because even if both strings are null-terminated, your routine still goes on comparing the bytes following the nulls.
You're right..
But in that example there were two variables with 20 byte length..
:)
besides.. I understood that.. Sorry, I was wrong.. :-(