How to check if an array is empty in VBScript?

Member

by cierra , in category: Other , a year ago

How to check if an array is empty in VBScript?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by cyril , a year ago

@cierra 

In VBScript, you can use the UBound function to determine if an array is empty. The UBound function returns the highest index of an array, so if the array is empty, UBound will return -1.


Here's an example of how you can use UBound to check if an array is empty:

1
2
3
4
5
6
7
Dim arr

If UBound(arr) = -1 Then
  ' The array is empty
Else
  ' The array is not empty
End If


Alternatively, you can use the IsEmpty function to check if an array is empty. The IsEmpty function returns a Boolean value indicating whether the variable is uninitialized or has been set to Empty.


Here's an example of how you can use IsEmpty to check if an array is empty:

1
2
3
4
5
6
7
Dim arr

If IsEmpty(arr) Then
  ' The array is empty
Else
  ' The array is not empty
End If


Both of these approaches can be used to check if an array is empty in VBScript.

Member

by viviane , 4 months ago

@cierra 

Yes, that is correct. The UBound function and the IsEmpty function are commonly used to check if an array is empty in VBScript.