I have a multi dimensional array of textboxes, arrTxtBx(37, 3), and data populated in a datatable, dtResult. For each row in datatable if 1st column is DbNull it'll return "0" for the 1st set of 3 textboxes, if 1st column in not Dbnull it'll return columns 3, 4, 5 as text for the 3 textboxes.
I've gotten the above to work with Select...Case statement. However, I would need to code 38 cases for the 38 elements in the textbox arrays, when the code within the case is exactly the same.
I'm sure this could be coded without the 38 case statement, but just can't seem to see it right now. Could anyone help on this. Thanks
Here's the code:
Dim arrTxtBx(37, 3) As TextBox
Sub DispResult()
Dim arrTxtBx(,) As TextBox =
{{txtHrFoundry, txtTpFoundry, txtSlFoundry}, _
{txtHrMold, txtTpMold, txtSlMold}, _
{txtHrMach, txtTpMach, txtSlMach}, _
{txtHrMachQC, txtTpMachQC, txtSlMachQC}, _
{txtHrMachQC, txtTpMachQC, txtSlMachQC}, _
{txtHrDie, txtTpDie, txtSlDie}, _
{txtHrCrib, txtTpCrib, txtSlCrib}, _
{txtHrShot, txtTpShot, txtSlShot}, _
{txtHrPaint, txtTpPaint, txtSlPaint}, _
{txtHrLeak, txtTpLeak, txtSlLeak}, _
{txtHrFinal, txtTpFinal, txtSlFinal}, _
{txtHrMat, txtTpMat, txtSlMat}, _
{txtHrMain, txtTpMain, txtSlMain}, _
{txtHrQual, txtTpQual, txtSlQual}, _
{txtHrProc, txtTpProc, txtSlProc}, _
{txtHrJan, txtTpJan, txtSlJan}, _
{txtHrMfgEng, txtTpMfgEng, txtSlMfgEng}, _
{txtHrFac, txtTpFac, txtSlFac}, _
{txtHrHr, txtTpHr, txtSlHr}, _
{txtHrSaf, txtTpSaf, txtSlSaf}, _
{txtHrSec, txtTpSec, txtSlSec}, _
{txtHrPurch, txtTpPurch, txtSlPurch}, _
{txtHrRecv, txtTpRecv, txtSlRecv}, _
{txtHrOEM, txtTpOEM, txtSlOEM}, _
{txtHrAcct, txtTpAcct, txtSlAcct}, _
{txtHrIS, txtTpIS, txtSlIS}, _
{txtHrAssHS, txtTpAssHS, txtSlAssHS}, _
{txtHrFinHS, txtTpFinHS, txtSlFinHS}, _
{txtHrForgHS, txtTpForgHS, txtSlForgHS}, _
{txtHrCustCHI, txtTpCustCHI, txtSlCustCHI}, _
{txtHrCoppCHR, txtTpCoppCHR, txtSlCoppCHR}, _
{txtHrPlatCHR, txtTpPlatCHR, txtSlPlatCHR}, _
{txtHrSolCHR, txtTpSolCHR, txtSlSolCHR}, _
{txtHrBrightCHR, txtTpBrightCHR, txtSlBrightCHR}, _
{txtHrLabCHR, txtTpLabCHR, txtSlLabCHR}, _
{txtHrLabCHR, txtTpLabCHR, txtSlLabCHR}, _
{txtHrWasteCHR, txtTpWasteCHR, txtSlWasteCHR}, _
{txtHrPolishCHR, txtTpPolishCHR, txtSlPolishCHR}, _
{txtHrFlowVN, txtTpFlowVN, txtSlFlowVN}}
Dim strMonth As String = Request.QueryString("Month")
Dim strYear As String = Request.QueryString("Year")
Dim strPlant As String = Request.QueryString("Plant")
Dim dtResult As DataTable = dtFunctionData(strPlant, _
strYear, strMonth)
Dim i As Integer
For i = 0 To dtResult.Rows.Count - 1
Select Case CInt(dtResult.Rows(i)(1).ToString)
Case 1
If dtResult.Rows(i)(0) Is DBNull.Value Then
arrTxtBx(i, 0).Text = "0"
arrTxtBx(i, 1).Text = "0"
arrTxtBx(i, 2).Text = "0"
Else
arrTxtBx(i, 0).Text = dtResult.Rows(i)(2).ToString
arrTxtBx(i, 1).Text = dtResult.Rows(i)(3).ToString
arrTxtBx(i, 2).Text = dtResult.Rows(i)(4).ToString
End If
Case 2
If dtResult.Rows(i)(0) Is DBNull.Value Then
arrTxtBx(i, 0).Text = "0"
arrTxtBx(i, 1).Text = "0"
arrTxtBx(i, 2).Text = "0"
Else
arrTxtBx(i, 0).Text = dtResult.Rows(i)(2).ToString
arrTxtBx(i, 1).Text = dtResult.Rows(i)(3).ToString
arrTxtBx(i, 2).Text = dtResult.Rows(i)(4).ToString
End If
Case ....38
End Select
Next
End Sub
I've gotten the above to work with Select...Case statement. However, I would need to code 38 cases for the 38 elements in the textbox arrays, when the code within the case is exactly the same.
I'm sure this could be coded without the 38 case statement, but just can't seem to see it right now. Could anyone help on this. Thanks
Here's the code:
Dim arrTxtBx(37, 3) As TextBox
Sub DispResult()
Dim arrTxtBx(,) As TextBox =
{{txtHrFoundry, txtTpFoundry, txtSlFoundry}, _
{txtHrMold, txtTpMold, txtSlMold}, _
{txtHrMach, txtTpMach, txtSlMach}, _
{txtHrMachQC, txtTpMachQC, txtSlMachQC}, _
{txtHrMachQC, txtTpMachQC, txtSlMachQC}, _
{txtHrDie, txtTpDie, txtSlDie}, _
{txtHrCrib, txtTpCrib, txtSlCrib}, _
{txtHrShot, txtTpShot, txtSlShot}, _
{txtHrPaint, txtTpPaint, txtSlPaint}, _
{txtHrLeak, txtTpLeak, txtSlLeak}, _
{txtHrFinal, txtTpFinal, txtSlFinal}, _
{txtHrMat, txtTpMat, txtSlMat}, _
{txtHrMain, txtTpMain, txtSlMain}, _
{txtHrQual, txtTpQual, txtSlQual}, _
{txtHrProc, txtTpProc, txtSlProc}, _
{txtHrJan, txtTpJan, txtSlJan}, _
{txtHrMfgEng, txtTpMfgEng, txtSlMfgEng}, _
{txtHrFac, txtTpFac, txtSlFac}, _
{txtHrHr, txtTpHr, txtSlHr}, _
{txtHrSaf, txtTpSaf, txtSlSaf}, _
{txtHrSec, txtTpSec, txtSlSec}, _
{txtHrPurch, txtTpPurch, txtSlPurch}, _
{txtHrRecv, txtTpRecv, txtSlRecv}, _
{txtHrOEM, txtTpOEM, txtSlOEM}, _
{txtHrAcct, txtTpAcct, txtSlAcct}, _
{txtHrIS, txtTpIS, txtSlIS}, _
{txtHrAssHS, txtTpAssHS, txtSlAssHS}, _
{txtHrFinHS, txtTpFinHS, txtSlFinHS}, _
{txtHrForgHS, txtTpForgHS, txtSlForgHS}, _
{txtHrCustCHI, txtTpCustCHI, txtSlCustCHI}, _
{txtHrCoppCHR, txtTpCoppCHR, txtSlCoppCHR}, _
{txtHrPlatCHR, txtTpPlatCHR, txtSlPlatCHR}, _
{txtHrSolCHR, txtTpSolCHR, txtSlSolCHR}, _
{txtHrBrightCHR, txtTpBrightCHR, txtSlBrightCHR}, _
{txtHrLabCHR, txtTpLabCHR, txtSlLabCHR}, _
{txtHrLabCHR, txtTpLabCHR, txtSlLabCHR}, _
{txtHrWasteCHR, txtTpWasteCHR, txtSlWasteCHR}, _
{txtHrPolishCHR, txtTpPolishCHR, txtSlPolishCHR}, _
{txtHrFlowVN, txtTpFlowVN, txtSlFlowVN}}
Dim strMonth As String = Request.QueryString("Month")
Dim strYear As String = Request.QueryString("Year")
Dim strPlant As String = Request.QueryString("Plant")
Dim dtResult As DataTable = dtFunctionData(strPlant, _
strYear, strMonth)
Dim i As Integer
For i = 0 To dtResult.Rows.Count - 1
Select Case CInt(dtResult.Rows(i)(1).ToString)
Case 1
If dtResult.Rows(i)(0) Is DBNull.Value Then
arrTxtBx(i, 0).Text = "0"
arrTxtBx(i, 1).Text = "0"
arrTxtBx(i, 2).Text = "0"
Else
arrTxtBx(i, 0).Text = dtResult.Rows(i)(2).ToString
arrTxtBx(i, 1).Text = dtResult.Rows(i)(3).ToString
arrTxtBx(i, 2).Text = dtResult.Rows(i)(4).ToString
End If
Case 2
If dtResult.Rows(i)(0) Is DBNull.Value Then
arrTxtBx(i, 0).Text = "0"
arrTxtBx(i, 1).Text = "0"
arrTxtBx(i, 2).Text = "0"
Else
arrTxtBx(i, 0).Text = dtResult.Rows(i)(2).ToString
arrTxtBx(i, 1).Text = dtResult.Rows(i)(3).ToString
arrTxtBx(i, 2).Text = dtResult.Rows(i)(4).ToString
End If
Case ....38
End Select
Next
End Sub