Commit c9a606fa authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

vbscript: Add Asc implementation.

parent 6cc7b0e8
......@@ -1371,8 +1371,32 @@ static HRESULT Global_ChrB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARI
static HRESULT Global_Asc(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
{
FIXME("\n");
return E_NOTIMPL;
BSTR conv_str = NULL, str;
HRESULT hres = S_OK;
TRACE("(%s)\n", debugstr_variant(arg));
switch(V_VT(arg)) {
case VT_NULL:
return MAKE_VBSERROR(VBSE_ILLEGAL_NULL_USE);
case VT_EMPTY:
return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL);
case VT_BSTR:
str = V_BSTR(arg);
break;
default:
hres = to_string(arg, &conv_str);
if(FAILED(hres))
return hres;
str = conv_str;
}
if(!SysStringLen(str) || *str >= 0x100)
hres = MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL);
else if(res)
hres = return_short(res, *str);
SysFreeString(conv_str);
return hres;
}
/* The function supports only single-byte and double-byte character sets. It
......
......@@ -1453,4 +1453,40 @@ Call testRGBError(&h4d&, -2, &h2f&, 5)
Call ok(getVT(Timer) = "VT_R4", "getVT(Timer) = " & getVT(Timer))
sub testAsc(arg, expected)
dim x
x = Asc(arg)
call ok(x = expected, "x = " & x & " expected " & expected)
call ok(getVT(x) = "VT_I2*", "getVT = " & getVT(x))
end sub
sub testAscError()
on error resume next
call Err.clear()
call Asc(null)
Call ok(Err.number = 94, "Err.number = " & Err.number)
call Err.clear()
call Asc(empty)
Call ok(Err.number = 5, "Err.number = " & Err.number)
call Err.clear()
call Asc()
Call ok(Err.number = 450, "Err.number = " & Err.number)
call Err.clear()
call Asc(Chr(260))
Call ok(Err.number = 5, "Err.number = " & Err.number)
call Err.clear()
call Asc("")
Call ok(Err.number = 5, "Err.number = " & Err.number)
end sub
call testAsc("T", 84)
call testAsc("test", 116)
call testAsc("3", 51)
call testAsc(3, 51)
call testAsc(" ", 32)
call testAsc(Chr(255), 255)
call testAsc(Chr(0), 0)
if isEnglishLang then testAsc true, 84
call testAscError()
Call reportSuccess()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment