Wanting to use a For Next variable in “xxxx.Rows.Count”
-
In the code block below I am wishing to use a variable in a xxxx.Rows.Count line. Specifically, I'm wanting to take the "R1200s" portion and increment it to R1201s, R1202s, R1203s and so on as the For-Next loop executes. I, of course, already have the DataTable()'s portion defined... no problem there. The code works fine if I write out every single instance but I'd like to shorten it up into a simpler block of code. I've been able to use "i" in every other control with success but getting hung up on only this portion. I've tried something like ("R120" & i & "s"), along with many variations of this but, can find no solution that works with the limited experience I have with VbScript. Any help, a code example or a point in the right direction, is greatly appreciated.
For i = 1 To 8
Dim Ai As Label = DirectCast(Page.FindControl("A" & i.ToString()), Label)
Dim Si As Hyperlink = DirectCast(Page.FindControl("S" & i.ToString()), Hyperlink)If R1200s.Rows.Count < Slots.Rows(0)(Ri).ToString() +1 Then Ai.Style.Add("background-color","#000000") Si.ImageUrl = "images/" & i & ".png" Si.NavigateUrl = "step3.aspx?Time=" & i & "&Date=" & Request.QueryString("Date") & "&Day=" & Request.QueryString("Day") & "&Entry=" & Request.QueryString("Entry") End If
Next
-
In the code block below I am wishing to use a variable in a xxxx.Rows.Count line. Specifically, I'm wanting to take the "R1200s" portion and increment it to R1201s, R1202s, R1203s and so on as the For-Next loop executes. I, of course, already have the DataTable()'s portion defined... no problem there. The code works fine if I write out every single instance but I'd like to shorten it up into a simpler block of code. I've been able to use "i" in every other control with success but getting hung up on only this portion. I've tried something like ("R120" & i & "s"), along with many variations of this but, can find no solution that works with the limited experience I have with VbScript. Any help, a code example or a point in the right direction, is greatly appreciated.
For i = 1 To 8
Dim Ai As Label = DirectCast(Page.FindControl("A" & i.ToString()), Label)
Dim Si As Hyperlink = DirectCast(Page.FindControl("S" & i.ToString()), Hyperlink)If R1200s.Rows.Count < Slots.Rows(0)(Ri).ToString() +1 Then Ai.Style.Add("background-color","#000000") Si.ImageUrl = "images/" & i & ".png" Si.NavigateUrl = "step3.aspx?Time=" & i & "&Date=" & Request.QueryString("Date") & "&Day=" & Request.QueryString("Day") & "&Entry=" & Request.QueryString("Entry") End If
Next
Check this: [Wanting to use a for next variable in “xxxx.rows.count”](https://www.codeproject.com/Questions/1188811/Wanting-to-use-a-for-next-variable-in-xxxx-rows-co3#answer1)
-
In the code block below I am wishing to use a variable in a xxxx.Rows.Count line. Specifically, I'm wanting to take the "R1200s" portion and increment it to R1201s, R1202s, R1203s and so on as the For-Next loop executes. I, of course, already have the DataTable()'s portion defined... no problem there. The code works fine if I write out every single instance but I'd like to shorten it up into a simpler block of code. I've been able to use "i" in every other control with success but getting hung up on only this portion. I've tried something like ("R120" & i & "s"), along with many variations of this but, can find no solution that works with the limited experience I have with VbScript. Any help, a code example or a point in the right direction, is greatly appreciated.
For i = 1 To 8
Dim Ai As Label = DirectCast(Page.FindControl("A" & i.ToString()), Label)
Dim Si As Hyperlink = DirectCast(Page.FindControl("S" & i.ToString()), Hyperlink)If R1200s.Rows.Count < Slots.Rows(0)(Ri).ToString() +1 Then Ai.Style.Add("background-color","#000000") Si.ImageUrl = "images/" & i & ".png" Si.NavigateUrl = "step3.aspx?Time=" & i & "&Date=" & Request.QueryString("Date") & "&Day=" & Request.QueryString("Day") & "&Entry=" & Request.QueryString("Entry") End If
Next
-
In the code block below I am wishing to use a variable in a xxxx.Rows.Count line. Specifically, I'm wanting to take the "R1200s" portion and increment it to R1201s, R1202s, R1203s and so on as the For-Next loop executes. I, of course, already have the DataTable()'s portion defined... no problem there. The code works fine if I write out every single instance but I'd like to shorten it up into a simpler block of code. I've been able to use "i" in every other control with success but getting hung up on only this portion. I've tried something like ("R120" & i & "s"), along with many variations of this but, can find no solution that works with the limited experience I have with VbScript. Any help, a code example or a point in the right direction, is greatly appreciated.
For i = 1 To 8
Dim Ai As Label = DirectCast(Page.FindControl("A" & i.ToString()), Label)
Dim Si As Hyperlink = DirectCast(Page.FindControl("S" & i.ToString()), Hyperlink)If R1200s.Rows.Count < Slots.Rows(0)(Ri).ToString() +1 Then Ai.Style.Add("background-color","#000000") Si.ImageUrl = "images/" & i & ".png" Si.NavigateUrl = "step3.aspx?Time=" & i & "&Date=" & Request.QueryString("Date") & "&Day=" & Request.QueryString("Day") & "&Entry=" & Request.QueryString("Entry") End If
Next
Have you tried For i as integer = 0 to R1200s.Rows.Count-1 Next i