rodchar said:
I'm trying to see if there's a way to streamline the following:
Dim eeCode, eeRate, erCode, erRate As String
Dim tb As TextBox
tb = CType(e.Item.Cells(1).Controls(0), TextBox)
eeCode = tb.Text
tb = CType(e.Item.Cells(2).Controls(0), TextBox)
eeRate = tb.Text
tb = CType(e.Item.Cells(3).Controls(0), TextBox)
erCode = tb.Text
tb = CType(e.Item.Cells(4).Controls(0), TextBox)
erRate = tb.Text
Not much, because you're using separate variables for the
different strings. (eeCode, ccRate ...) Had you made them
an array of strings, you could fill it within a loop. (if, for
example, you were filling up to 15 or 20 such strings, a loop
would add a significant reduction)
Even if you want to keep individual variables, you can remove
some of that code because VB will let you initialize variables
as you declare them, such as:
Dim eeCode As String = CType(e.Item.Cells(1).Controls(0), TextBox).Text
Dim eeRate As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
.... etc ...
Using a With block you could remove even more:
With e.Item
Dim eeCode As String = CType(.Cells(1).Controls(0), TextBox).Text
Dim eeRate As String = CType(.Cells(2).Controls(0), TextBox).Text
.... etc ...
End With
But (with separate variables) that is about as far as you can go.
HTH
LFS