Is there a macro somewhere to convert a string to an integer?
Val("123") (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1202) does it, but there must be something in \masm32\macros\macros.asm, too.
For bigger integers, I recommend MovVal:
include \masm32\MasmBasic\MasmBasic.inc ; download (http://masm32.com/board/index.php?topic=94.0)
Init
MovVal xmm0, "1234567890123456789"
Inkey Str$("xmm0=%i", xmm0)
EndOfCode
;)
.data?
MyTempString db 4 dup(?)
startpos dd ?
endpos dd ?
.code
invoke GetDlgItemText,hWnd,IDC_EDIT_START,ADDR MyTempString,4
mov startpos,val(MyTempString)
invoke GetDlgItemText,hWnd,IDC_EDIT_END,ADDR MyTempString,4
mov endpos,val(MyTempString)
This code gives me the "error A2039: line too long" error on the lines containing val. They're shorter than the GetDlgItemText lines so I don't understand why it is saying that ? :S
BTW: GetDlgItemInt() gives integer too ;)
I've been searching through the masm macro's and Ive found that uval and sval should do the trick.
Quote from: TWell on January 15, 2016, 12:17:33 AM
BTW: GetDlgItemInt() gives integer too ;)
Wow hahaha, I didn't know of it's existence. makes my life easier, thanks! :)
crt_atoi (unsigned)
crt_atol (signed)
Quote from: gelatine1 on January 15, 2016, 12:11:07 AMThis code gives me the "error A2039: line too long" error on the lines containing val.
Interesting :t
include \masm32\include\masm32rt.inc
.code
tx123 db "123", 0
start:
mov eax, val(offset tx123)
print str$(eax), 13, 10
print str$(val("123")), 13, 10
print str$(val(offset tx123))
exit
end start
Bug confirmed, but try again with JWasm, AsmC, Masm 8 or higher 8)
Hello
Shlwapi
Quote
Converts a string that represents a decimal value to an integer. The StrToLong macro is identical to this function.
Syntax
C++
int StrToInt(
_In_ PCTSTR pszSrc
);
or
Quote
StrToIntEx function
Converts a string representing a decimal or hexadecimal number to an integer.
https://msdn.microsoft.com/en-us/library/windows/desktop/bb773451%28v=vs.85%29.aspx
For those who find Val() (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1202) too complicated:
include \masm32\include\masm32rt.inc
txt2dw MACRO sz$
invoke atodw, reparg(sz$) ; good ol' Masm32
EXITM <eax>
ENDM
.code
tx123 db "123", 0
start:
print str$(txt2dw(addr tx123)), 9, "tx123", 13, 10
print str$(txt2dw("456")), 9, "456", 13, 10
print str$(txt2dw(chr$("789"))), 9, "chr$(789)", 13, 10
inkey "that was easy, right?"
exit
end start