loop with field names

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Filip De Backer

    #1

    loop with field names

    Hi everybody,

    I want something like I used in MS Access:

    for i = 1 to 20
    me("FieldName" & i).Text = "Text bla bla bla"
    next i

    I want something like that because I have a series of fields like
    FieldName1; FieldName2, FieldName3, ... which I want to fill in
    programmaticaly .

    thanks in advance

    Filip
  • Cor Ligthert

    #2
    Re: loop with field names

    Filip,

    What is the problem with that[color=blue]
    >
    > I want something like I used in MS Access:
    >
    > for i = 1 to 20
    > me("FieldName" & i).Text = "Text bla bla bla"
    > next i
    >[/color]
    \\\by instance roughly typed
    for ctr in me.controls
    dim number as integer = Cint(ctr.text.s ubstring(9,0))
    if number. > 0 AndAlso number < 21 then
    ctr.text = "Text bla bla bla"
    end if
    Next
    ///
    Did you know that there is a newsgroup
    Microsoft.publi c.dotnet.langua ges.vb

    There you can get a lot of methods for this (I took the most simple one)

    Keep in mind that in dotNet windowforms every control can have his own
    controlcollecti on, so when this is on a frame you have not to say "me",
    however "frame1" or whatever.

    I hope this helps?

    Cor



    Comment

    • Filip De Backer

      #3
      Re: loop with field names

      thanks and sorry for posting in the wrong forum



      Comment

      • Cor Ligthert

        #4
        Re: loop with field names

        Filip,

        Was no message to tell you that this is the wrong forum, only to tell you
        that there is in my opinon a better one than this for the question you had
        and you want to know more of it.

        Maybe I had answered that as well in that newsgroup, however there are more
        who can answer the question than here

        (Although before someone understand it wrong I am not the only one here who
        can answer your question).

        Cor
        [color=blue]
        > thanks and sorry for posting in the wrong forum
        >[/color]



        Comment

        • Nick Malik

          #5
          Re: loop with field names

          If these fields are really columns in a database, then you can effectively
          still use the same technique, since the indexer on a dataset column is the
          name of the field.

          However, if these fields are actually variable names, you cannot do this
          easily, and you may want to look at other schemes to index your values (like
          an array).

          Can you tell us if the "fields" are database columns or variables?

          --- Nick


          "Filip De Backer" <filip_de_backe r@hotmail.com.( donotspam)> wrote in message
          news:526547AD-E057-4A8B-A908-BFF883518DA3@mi crosoft.com...[color=blue]
          > Hi everybody,
          >
          > I want something like I used in MS Access:
          >
          > for i = 1 to 20
          > me("FieldName" & i).Text = "Text bla bla bla"
          > next i
          >
          > I want something like that because I have a series of fields like
          > FieldName1; FieldName2, FieldName3, ... which I want to fill in
          > programmaticaly .
          >
          > thanks in advance
          >
          > Filip[/color]


          Comment

          • Nick Malik

            #6
            Re: loop with field names

            why do you think that this is the wrong forum? Is this not a .net question?

            "Filip De Backer" <filip_de_backe r@hotmail.com.( donotspam)> wrote in message
            news:CFA6DB0D-ECCA-4803-816E-25EA9CD03EB1@mi crosoft.com...[color=blue]
            > thanks and sorry for posting in the wrong forum
            >
            >
            >[/color]


            Comment

            • Filip De Backer

              #7
              Re: loop with field names

              These fields are labels on the webform.
              Sometimes i have 3 records of data, somtimes1, so I want to fill in the
              labels by numbering them....

              Comment

              • Jon Skeet [C# MVP]

                #8
                Re: loop with field names

                Filip De Backer <filip_de_backe r@hotmail.com.> wrote:[color=blue]
                > These fields are labels on the webform.
                > Sometimes i have 3 records of data, somtimes1, so I want to fill in the
                > labels by numbering them....[/color]

                The easiest way is to have an array (or a map) of controls, rather than
                have different actual fields.

                --
                Jon Skeet - <skeet@pobox.co m>
                Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                If replying to the group, please do not mail me too

                Comment

                • Cor Ligthert

                  #9
                  Re: loop with field names

                  Filip,

                  A webform needs a little different approach than a windowform, keep my
                  sample I showed you in the earlier message. However use as well an old
                  sample of my, to set the textboxes on a form to space. (When it is not
                  directly on a form however on a panel, it needs the approach which is the
                  same as in a windowsform)

                  I hope this helps?

                  Cor

                  \\\
                  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
                  System.EventArg s) Handles MyBase.Load
                  Dim frm As Control = Me.FindControl( "Form1")
                  Dim ctl As Control
                  For Each ctl In frm.Controls
                  Dim tb As TextBox
                  If TypeOf ctl Is TextBox Then
                  tb = DirectCast(ctl, TextBox)
                  tb.Text = String.Empty
                  End If
                  Next
                  ///

                  [color=blue]
                  > These fields are labels on the webform.
                  > Sometimes i have 3 records of data, somtimes1, so I want to fill in the
                  > labels by numbering them....[/color]


                  Comment

                  Working...