I have a couple arrays of textboxes at the form class level. When I attempt to loop through these arrays with a for each loop, my loop variables value is 'Nothing'. Here is my form level arrays:
Public Class frmTDSNew
' Form level arrays to hold text boxes to fill and validate
Dim decimalBoxes() As TextBox = New TextBox() {txtLenPerDrum, txtWeightPerDrum, txtEnamThick, txtEnamTolPos, txtEnamTolNeg,
txtEpoxyThick, txtEpoxTolPos, txtEpoxTolNeg, txtNomDimH, txtNomDimHPos, txtNomDimHNeg,
txtNomDimW, txtNomDimWPos, txtNomDimHNeg, txtTensileStrength, txtElongation, txtYieldStghMin,
txtYieldStghMax, txtBulging, txtInsThick1, txtInsThick2, txtInsThick3, txtProThick, txtEdgeProThick,
txtInterColThick}
Dim integerBoxes() As TextBox = New TextBox() {txtPONbr, txtNbrWire, txtNbrDrum, txtDrumSets, txtWindInnerDia, txtPitch}
And here is one of the places I am trying to loop through the arrays:
Private Function IsValidData() As Boolean
For Each box As TextBox In decimalBoxes
If Not IsDecimal(box) Then
Return False
End If
Next
For Each box As TextBox In integerBoxes
If Not IsInt32(box) Then
Return False
End If
Next
Return True
End Function
In the loops, 'box' is set to nothing, even though when I set a breakpoint while in debug mode I can see that everything in my arrays are definitely textboxes. Everything works fine when I move the arrays to within the functions I am calling them, but this defeats the purpose of declaring them at the class level. I want to use these arrays in several places on my form. Any idea on what I am doing wrong here?
IsDecimal(box)should probably beIsDecimal(box.Text)since you want to test the TB contents