- Do While Loop needs to exit when my Array hits it's UBound
I receive the Subscript Out of Range error when my loop attempts to be greater than it's size.
arrNo = 1
strScreenList = PbWindow("w_genapp_frame").PbWindow("Application Enquiry Menu").PbList("lb_list").GetContent
arrScreen = Split(strScreenList, VbLf, -1, 1)
Do While arrScreen(arrNo) <> ""
PbWindow("w_genapp_frame").PbWindow("Application Enquiry Menu").PbList("lb_list").Activate arrScreen(arrNo)
strScreenName = arrScreen(arrNo)
sf_EnquireScreens(strScreenName)
arrNo = arrNo+1
Loop
As you can see, strScreenList is split into strings to arrScreen (Which contains 36 values)
Once my loop attempts to step over arrNo(35) (this is the point at which I would like it to step out of my loop) I receive the Subscript Out of Range error
From what I've gathered, I'm receiving the error because my Array is too short for the extra value it's trying to add to it.
Is there a way to gracefully get my script to step out once my array hits it's Ubound?
Do While arrNo <= Ubound(arrScreen). It could be used as you tried, only if you are sure that there are empty strings/elements in the array and need exiting in such a case. But, in that way, without an empty element, the loop will continuously iterate, until the error appears...for ... lbound ... to ubound ...