The ubound (name of array) function is mainly used. This function is used to find the upper boundary of the array. A dynamic array a, if you have used the redim statement to set the size, then use ubound(a) afterwards to get its upper bound.
If you do not use the redim statement to set the size for it and use the ubound(a) function directly, an error will be reported during runtime and the execution of the program will be interrupted. We just use this to know that this array does not have any elements. At the same time, we do not want the program to interrupt execution, so we can add a sentence before the execution of the ubound(a) function
Copy the code code as follows:
on error resume next
Write this function as a function function get_element_count_of_one_aray(name_of_aray)
Copy the code code as follows:
on error resume next
upper_bound_of_aray=ubound(name_of_aray)
if err then
get_element_count_of_one_aray=0
else
get_element_count_of_one_aray=uper_bound_of_aray+1
end if
end function