I need to choice a way to write a piece of code that will repeated very much so I want it to be as fast as possible.
This is my code (at the moment):
For Cel As Short = 0 To Cels - 1
Rw = Int(Cel / 3) + 1
Col = Cel - ((Rw - 1) * 3) + 1
RifTxt = TabW(RifTW("Pi")).Cells(Cel)
If Col = 1 Then
RowArr(Col) = RifTxt
Else
If DateTime.TryParse(RifTxt, culture, Styles, DateResult) Then
RowArr(Col) = DateResult.ToString("yyyy-MM-dd")
Else
RowArr(Col) = "0000-00-00"
End If
If Col = 3 Then
RowArr(3) = Rw
Pi_W.Rows.Add (RowArr)
End If
End If
Next Cel
I'm wondering changing it (using ElseIf Or Select Case) as shown:
Using ElseIf
For Cel As Short = 0 To Cels - 1
Rw = Int(Cel / 3) + 1
Col = Cel - ((Rw - 1) * 3) + 1
RifTxt = TabW(RifTW("Pi")).Cells(Cel)
If Col = 1 Then
RowArr(Col) = RifTxt
ElseIf Col = 2
If DateTime.TryParse(RifTxt, culture, Styles, DateResult) Then
RowArr(Col) = DateResult.ToString("yyyy-MM-dd")
Else
RowArr(Col) = "0000-00-00"
End If
ElseIf Col = 3 Then
If DateTime.TryParse(RifTxt, culture, Styles, DateResult) Then
RowArr(Col) = DateResult.ToString("yyyy-MM-dd")
Else
RowArr(Col) = "0000-00-00"
End If
RowArr(3) = Rw
Pi_W.Rows.Add (RowArr)
End If
Next Cel
Or using Select Case:
For Cel As Short = 0 To Cels - 1
Rw = Int(Cel / 3) + 1
Col = Cel - ((Rw - 1) * 3) + 1
RifTxt = TabW(RifTW("Pi")).Cells(Cel)
Select Case Col
Case is = 1 Then
RowArr(Col) = RifTxt
Case is = 2
If DateTime.TryParse(RifTxt, culture, Styles, DateResult) Then
RowArr(Col) = DateResult.ToString("yyyy-MM-dd")
Else
RowArr(Col) = "0000-00-00"
End If
Case is = 3 Then
If DateTime.TryParse(RifTxt, culture, Styles, DateResult) Then
RowArr(Col) = DateResult.ToString("yyyy-MM-dd")
Else
RowArr(Col) = "0000-00-00"
End If
RowArr(3) = Rw
Pi_W.Rows.Add (RowArr)
End Select
Next Cel
I tryed to compare the three methods on .netFiddle but I'm not sure of results.
Can you please suggest me the right choice?