Answered by:
How to eliminate warning: array used before being assigned a value

Question
-
User646364117 posted
I am getting this warning re vCellArray in next to last line of function
Public Function ExtractCells(ByRef OrigFormula As String) As Object(,) Dim vCellArray(,) As Object 'Irrelevant Code deleted ValidCellCount = ValidCellCount + 1 ReDim Preserve vCellArray(3, ValidCellCount) vCellArray(0, 0) = ValidCellCount vCellArray(1, ValidCellCount) = tempStr vCellArray(2, ValidCellCount) = PossibleStartPosition vCellArray(3, ValidCellCount) = PossibleEndingPosition End If ValidCell = False Next 'Candidate End If If ValidCellCount = 0 Then ReDim Preserve vCellArray(3, ValidCellCount + 1) vCellArray(0, 0) = 0 End If ExtractCells = vCellArray Return ExtractCells End Function
Monday, October 3, 2016 1:27 PM
Answers
-
User-1716253493 posted
Try this
Dim vCellArray(,) As Object = Nothing
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, October 4, 2016 7:10 AM
All replies
-
User36583972 posted
Hi sg48asp,
As far as I know, The warning lets you know that there is no Array object associated with the variable, if you run it you will get an exception as there is no Array object so it can't assign a value to an element.
So, please debug your code step by step to find which code causes the warning. You could also share us more relevant code to help us reproduce the problem.
Best Regards,
Yohann Lu
Tuesday, October 4, 2016 6:52 AM -
User-1716253493 posted
Try this
Dim vCellArray(,) As Object = Nothing
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, October 4, 2016 7:10 AM -
User646364117 posted
If I run it, there is no error. This is just a warning at before running.
Tuesday, October 4, 2016 10:53 AM -
User646364117 posted
Thanks-That worked.
I also tried Dim vCellArray(3,100) which also worked. It gets redimensioned later.
Tuesday, October 4, 2016 11:01 AM