Can you spot my error?
I'm pretty new at VB.net, so I'm sure it's something obvious... I've read all the references to VB.net nullreferenceexception here on StackOverflow and am still confused.
Here's the code:
For Each oSlide In oPres.Slides.Range
strDisplayVerse = oSlide.Shapes.Title.TextFrame.TextRange.Characters.Text
If (IsNumeric(strDisplayVerse.Substring(0, 1)) = True And strDisplayVerse.Substring(2, 1) = "1") Then
arrVersesChorusOther(intVCO) = "Verse " & strDisplayVerse.Substring(0, 1)
strDisplayVerse = "Verse " & strDisplayVerse.Substring(0, 1) &
", slide " & strDisplayVerse.Substring(2, 1)
intVCO = intVCO + 1
End If
Next
'-----------
For Each oSlide In oPres.Slides.Range
strDisplayVerse = oSlide.Shapes.Title.TextFrame.TextRange.Characters.Text
If strDisplayVerse.Substring(0, 1) = "C" Then
strDisplayVerse = "Chorus, slide " & strDisplayVerse.Substring(2, 1)
Else
If IsNumeric(strDisplayVerse.Substring(0, 1)) Then
strDisplayVerse = "Verse " & strDisplayVerse.Substring(0, 1) &
", slide " & strDisplayVerse.Substring(2, 1)
End If
End If
TxtBxVerses.Text = TxtBxVerses.Text & strDisplayVerse & Environment.NewLine
Next
the fifth line is failing:
strDisplayVerse = "Verse " & strDisplayVerse.Substring(0, 1) &
", slide " & strDisplayVerse.Substring(2, 1)
The second loop is code that works. I swapped the line above this code to see if maybe the array setting was causing the problem - I received the error on the same code line. I then swapped the code with:
TxtBxVerses.Text = TxtBxVerses.Text & strDisplayVerse & Environment.NewLine
which also works in the second loop - same error on this line of code.
I can see that strDisplayVerse is equal to "1-1 blah blah blah", so this variable has data and is not null. arrVersesChorusOther is just an undefined size string array defined with PUBLIC just after the Public Class Form1 statement. intVCO is a PUBLIC integer set just below arrVersesChorusOther. TxtBxVerses is a textbox on the form.