Correct me if I am wrong.
In this part of your code
If bDone Then
'----------
'this works
'----------
Dim rs As ResumableSub = MakeMenuArray
Wait For (rs) Complete (dDoneMenuArray As Boolean)
'-----------------
'this doesn't work
'-----------------
' MakeMenuArray
For i = iButtonStartIndex To arrMenuButtons.Length - 1 'overflow button has no bitmap
arrMenuButtons(i).SetBitmap(arrMenu(i).bmpIconBitMap1) '<<<<< java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
Next
End If
after the MakeMenuArray you have a For cycle that need
arrMenu(i).bmpIconBitMap1
to be ready. This is done by MakeMenuArray.
Calling MakeMenuArray as a normal Sub seems not to leave enough time to the Sub to complete its job before the next operations.
This is why using it as a Resumable Sub solve the problem.
As a confirmation, if you put a Sleep to let it complete
If bDone Then
'----------
'this works
'----------
' Dim rs As ResumableSub = MakeMenuArray
' Wait For (rs) Complete (dDoneMenuArray As Boolean)
'-----------------
'this doesn't work
'-----------------
MakeMenuArray
Sleep(1000) 'Let us give time to MakeMenuArray to complete (exagerated value)
For i = iButtonStartIndex To arrMenuButtons.Length - 1 'overflow button has no bitmap
arrMenuButtons(i).SetBitmap(arrMenu(i).bmpIconBitMap1) '<<<<< java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
Next
End If
then you can have your Sub like this
Sub MakeMenuArray
'Do things
'More things
'Yet more things
End Sub
But honestly I would prefer a Resumable Sub that just wait for the exact time needed by the Sub to complete.