Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Wanting to use a For Next variable in “xxxx.Rows.Count”

Wanting to use a For Next variable in “xxxx.Rows.Count”

Scheduled Pinned Locked Moved Visual Basic
helptutorialquestionlearning
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    smdevivo
    wrote on last edited by
    #1

    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

    M Z M 3 Replies Last reply
    0
    • S smdevivo

      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

      M Offline
      M Offline
      Maciej Los
      wrote on last edited by
      #2

      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)

      1 Reply Last reply
      0
      • S smdevivo

        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

        Z Offline
        Z Offline
        ZurdoDev
        wrote on last edited by
        #3

        What is R1200s? What type of object is it?

        There are two kinds of people in the world: those who can extrapolate from incomplete data. There are only 10 types of people in the world, those who understand binary and those who don't.

        1 Reply Last reply
        0
        • S smdevivo

          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

          M Offline
          M Offline
          Member 8345599
          wrote on last edited by
          #4

          Have you tried For i as integer = 0 to R1200s.Rows.Count-1 Next i

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups