vbscript: Add UBound implementation.

Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Piotr Caban 2017-11-06 16:53:08 +01:00 committed by Alexandre Julliard
parent f962bb0039
commit e95492bc83
2 changed files with 45 additions and 3 deletions

View file

@ -822,8 +822,40 @@ static HRESULT Global_LBound(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VA
static HRESULT Global_UBound(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
{
FIXME("\n");
return E_NOTIMPL;
SAFEARRAY *sa;
HRESULT hres;
LONG ubound;
int dim;
assert(args_cnt == 1 || args_cnt == 2);
TRACE("%s %s\n", debugstr_variant(arg), args_cnt == 2 ? debugstr_variant(arg + 1) : "1");
switch(V_VT(arg)) {
case VT_VARIANT|VT_ARRAY:
sa = V_ARRAY(arg);
break;
case VT_VARIANT|VT_ARRAY|VT_BYREF:
sa = *V_ARRAYREF(arg);
break;
default:
FIXME("arg %s not supported\n", debugstr_variant(arg));
return E_NOTIMPL;
}
if(args_cnt == 2) {
hres = to_int(arg + 1, &dim);
if(FAILED(hres))
return hres;
}else {
dim = 1;
}
hres = SafeArrayGetUBound(sa, dim, &ubound);
if(FAILED(hres))
return hres;
return return_int(res, ubound);
}
static HRESULT Global_RGB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
@ -2256,7 +2288,7 @@ static const builtin_prop_t global_props[] = {
{DISPID_GLOBAL_RND, Global_Rnd, 0, 1},
{DISPID_GLOBAL_TIMER, Global_Timer, 0, 0},
{DISPID_GLOBAL_LBOUND, Global_LBound, 0, 1},
{DISPID_GLOBAL_UBOUND, Global_UBound, 0, 1},
{DISPID_GLOBAL_UBOUND, Global_UBound, 0, 1, 2},
{DISPID_GLOBAL_RGB, Global_RGB, 0, 3},
{DISPID_GLOBAL_LEN, Global_Len, 0, 1},
{DISPID_GLOBAL_LENB, Global_LenB, 0, 1},

View file

@ -227,6 +227,16 @@ new_array = x
x(0) = "new value"
Call ok(new_array(0) = "a1", "new_array(0) = " & new_array(0))
Call ok(getVT(UBound(x)) = "VT_I4", "getVT(UBound(x)) = " & getVT(UBound(x)))
Call ok(UBound(x) = 2, "UBound(x) = " & UBound(x))
Call ok(getVT(UBound(x, 1)) = "VT_I4", "getVT(UBound(x, 1)) = " & getVT(UBound(x, 1)))
Call ok(UBound(x, 1) = 2, "UBound(x) = " & UBound(x, 1))
Dim arr2(2, 4)
Call ok(UBound(arr2) = 2, "UBound(x) = " & UBound(x))
Call ok(UBound(arr2, 1) = 2, "UBound(x) = " & UBound(x))
Call ok(UBound(arr2, 2) = 4, "UBound(x) = " & UBound(x))
Dim newObject
Set newObject = New ValClass
newObject.myval = 1