A new way to handle ForLoop variables



  • This was a nice piece of code I stumbled across on my last week at this shop.

    Private Sub SomeSub()
    Dim icounter As Integer = 0
    SomeOtherSub(e, sd, ed icounter, dn)
    End Sub


    Private Sub SomeOtherSub(ByRef e As System.Web.UI.WebControls.DayRenderEventArgs,
    ByRef sd As Integer,
    ByRef ed As Integer,
    ByRef icounter As Integer,
    ByRef dn As XmlNode)
    For icounter = sd To ed
        For Each dn In xldoc.SelectNodes("//root/day[@dnum=" &  icounter.ToString & "]/v/vo/p/f")
             totalc += CInt(dn.Attributes("numc").Value)
       Next
    Next
    end sub

     

     

     



  • Wow... Why didn't I think of that?!

    *Hurries off to change his for loops* 



  • I must be blind or too tired or something... what's special about that for loop?

     



  • @Khim said:

    I must be blind or too tired or something... what's special about that for loop?

     

    You can't see that someone wrote a seperate function to pass in the initial value?

    How about the fact they used ByRef?

     



  • @MasterPlanSoftware said:

    @Khim said:

    I must be blind or too tired or something... what's special about that for loop?

     

    You can't see that someone wrote a seperate function to pass in the initial value?

    How about the fact they used ByRef?

     

    Ah, yes. I did miss that. I must have been too tired, then. Interesting construct, though... or something. Must be the result of a bunch of hurried and misjudged rewrites, I suppose.
     



  • I couldn't see any of that myself--but I'm used to using real languages, not whatever that gibberish is.



  • VB.NET I presume.

     

    Don't know about .NET, but VB6 allowed you to pass numbers as arguments to a ByRef parameter without problems...

    (And the real WTF is me, I know) 


Log in to reply