Re: General .NET programming question

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: William Mansfield (anonymous_at_discussions.microsoft.com)
Date: 03/11/04


Date: Thu, 11 Mar 2004 15:06:09 -0800

Ah - wonderful.
I was lookin at some of my old code, and was trying to think of the better way to code some of it,
here is the exact snippet as it was:

----------------------------
        Dim y As Integer = 0
        For x As Integer = 0 To oReport.DataDefinition.ParameterFields.Count - 1
            If Not oReport.DataDefinition.ParameterFields(x).PromptText = String.Empty Then
                ReDim Preserve arParams(y)
                arParams(y) = New Parameter()
                arParams(y).Name = oReport.DataDefinition.ParameterFields(x).ParameterFieldName
                arParams(y).PromptingText = oReport.DataDefinition.ParameterFields(x).PromptText
                arParams(y).Type = oReport.DataDefinition.ParameterFields(x).ParameterValueKind
                y += 1
            End If
        Next
----------------------

And here it is using a modified approach (per your notes)

----------------------

        Dim x As Integer
        Dim y As Integer = 0
        Dim iBounds As Integer = oReport.DataDefinition.ParameterFields.Count - 1

        For x = 0 To iBounds
            If Not oReport.DataDefinition.ParameterFields(x).PromptText = String.Empty Then
                ReDim Preserve arParams(y)
                arParams(y) = New Parameter()
                arParams(y).Name = oReport.DataDefinition.ParameterFields(x).ParameterFieldName
                arParams(y).PromptingText = oReport.DataDefinition.ParameterFields(x).PromptText
                arParams(y).Type = oReport.DataDefinition.ParameterFields(x).ParameterValueKind
                y += 1
            End If
        Next

--------------------

And here it yet again with another guys notes:

--------------------

        Dim y As Integer = 0
        Dim x As Integer
        Dim iBounds As Integer = oReport.DataDefinition.ParameterFields.Count - 1

        For x = 0 To iBounds
            If Not oReport.DataDefinition.ParameterFields(x).PromptText = String.Empty Then
                y += 1
            End If
        Next

        ReDim arParams(y)

        For x = 0 To iBounds
            If Not oReport.DataDefinition.ParameterFields(x).PromptText = String.Empty Then
                arParams(y) = New Parameter
                arParams(y).Name = oReport.DataDefinition.ParameterFields(x).ParameterFieldName
                arParams(y).PromptingText = oReport.DataDefinition.ParameterFields(x).PromptText
                arParams(y).Type = oReport.DataDefinition.ParameterFields(x).ParameterValueKind
            End If
        Next

-------------

Anyone have any feedback for which of the two would wield the best results? And does array size have a large play in it? That is - if the array is *expected* to be around 20 - vs - 20000.

This kind of programming pattern seems to come up alot when dealing with dynamic collections and sub-collections - so I'm trying to develop the "Best" method of doing it.

Oh yea, I'm not a fan of the "With - End With" Control Structure so I rarely use it.

By the way - I think I love these newsgroups!

Any notes will be much appreciated!



Relevant Pages

  • Re: General .NET programming question
    ... I was lookin at some of my old code, and was trying to think of the better way to code some of it, ... I'm not a fan of the "With - End With" Control Structure so I rarely use it. ... By the way - I think I love these newsgroups! ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: My 1982 SQ Stratocaster
    ... Nice lookin' ride! ... I'm a big fan of jumbo frets. ...
    (alt.guitar)
  • Re: free.uk.binaries.canals
    ... Did a re-scan of the newsgroups - and hey-presto! ... Lookin' good. ... According to their website they have been having a few problems with the ...
    (uk.rec.waterways)
  • Re: What The F**K Is Wrong With People??????
    ... How about a little fan? ... lookin' for a standing ovation or even applause but ...
    (rec.music.gdead)