locked
Increment a number preceding .Rows.Count with a For Next loop RRS feed

  • Question

  • User293269538 posted

    I am trying to increment the value which precedes a .Rows.Count.

    I want to increment the value by 1 using a For Next loop.  In the code below, I need R1200s to become R1201s, R1202S,  R1203S, etc. which each pass of the For Next loop.  FindControl() method, suggested by another member, worked great for the Labels and Hyperlinks in my page but I know that will not work for the code below.

    Any help, or a point in the right direction, would be appreciated.

    	For i = 1 To 10
    	If Slots.Rows(0)(Ri).ToString() = 0 Then
    	Ai.Style.Add("background-color","#CCCCCC")
    	
    	ElseIf R1200s.Rows.Count < Slots.Rows(0)(Ri).ToString() +1 Then
    	
    	Ai.Style.Add("background-color","#000000")
    	Si.ImageUrl = "images/" & i & ".png"
    	End If
    	Next

    Wednesday, May 17, 2017 8:20 PM

Answers

  • User293269538 posted

    I figured it out...

    I used CreateObject("Scripting.Dictionary") and then a ForNext loop to iterate through the "added" items.

    See my code below.

    Dim Dict = CreateObject("Scripting.Dictionary")
        Dict.Add (1200, r1200s.Rows.Count)
        Dict.Add (1250, r1250s.Rows.Count)
        Dict.Add (1300, r1300s.Rows.Count)
        Dict.Add (1350, r1350s.Rows.Count)
        Dict.Add (1400, r1400s.Rows.Count)
        Dict.Add (1450, r1450s.Rows.Count)
    
    For i = 1200 to 1450 Step 50
    
    If Dict.Item(i) > Slots.Rows(0)(Ri).ToString() -1 Then
    Si.Style.Add("background-color","#CCCCCC") Si.ImageUrl = "images/" & ID & ".png" ElseIf Dict.Item(i) < Slots.Rows(0)(Ri).ToString() +1 Then Si.Style.Add("background-color","#000000")
    End If Next



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, May 27, 2017 8:05 PM

All replies

  • User-1838255255 posted

    Hi smdevivo,

    After reading your needs, I think you could set a global variable, then increase 1 after a for loop, then break to execute the other for loop. You could check this logical code:

    Sample Code:

    Private j As Integer = 0
    Protected Sub Button1_Click(sender As Object, e As EventArgs)
    	For i As Integer = 0 To 8
    		j += 1
    		If j = 1 Then
    			Exit For
    		End If
    	Next
    	If j = 1 Then
    		For i As Integer = 0 To 9
    		Next
    	End If
    End Sub

    Best Regards,

    Eric Du

    Thursday, May 18, 2017 8:56 AM
  • User293269538 posted

    The For Next part of the problem is not the issue.

    The issue was in getting the "R1200s" to accept being a variable.  When I tried to make it a variable (i.e. "R" & i & "s") it kept throwing an error.

    How can I set up that portion of the code to accept a variable?

    Thursday, May 18, 2017 3:12 PM
  • User1771544211 posted

    Hi smdevivo,

    The issue was in getting the "R1200s" to accept being a variable.

    What does the "R1200s" mean?  Where does the "R1200s" come from? 

    Best Regards,

    Jean

    Saturday, May 27, 2017 7:40 AM
  • User293269538 posted

    The "R1200s" is the DataTable() I'm referencing.  i.e.: Dim R1200s, R1201s, R1202s... As New DataTable()

    Using pseudo, I want to increment using as:  For i = R1200s To R1208s but, of course using the variable (i).

    Because of that, it won't accept a string reference like ("R" & i & "s")

    Saturday, May 27, 2017 3:58 PM
  • User293269538 posted

    I figured it out...

    I used CreateObject("Scripting.Dictionary") and then a ForNext loop to iterate through the "added" items.

    See my code below.

    Dim Dict = CreateObject("Scripting.Dictionary")
        Dict.Add (1200, r1200s.Rows.Count)
        Dict.Add (1250, r1250s.Rows.Count)
        Dict.Add (1300, r1300s.Rows.Count)
        Dict.Add (1350, r1350s.Rows.Count)
        Dict.Add (1400, r1400s.Rows.Count)
        Dict.Add (1450, r1450s.Rows.Count)
    
    For i = 1200 to 1450 Step 50
    
    If Dict.Item(i) > Slots.Rows(0)(Ri).ToString() -1 Then
    Si.Style.Add("background-color","#CCCCCC") Si.ImageUrl = "images/" & ID & ".png" ElseIf Dict.Item(i) < Slots.Rows(0)(Ri).ToString() +1 Then Si.Style.Add("background-color","#000000")
    End If Next



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, May 27, 2017 8:05 PM