Array of textbox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Angel López

    Array of textbox

    How to do this with Vb.net 2008???

    myNumber=1+ Int(Rnd()*90)
    text(myNumber). backcolor=vbRed

    Tanks

    Angel



  • zacks@construction-imaging.com

    #2
    Re: Array of textbox

    On Oct 16, 9:34 am, "Angel López" <angel.lopezgo. ..@salesianos.e du>
    wrote:
    How to do this with Vb.net 2008???
    >
    myNumber=1+ Int(Rnd()*90)
    text(myNumber). backcolor=vbRed
    >
    You can't make a control array in design mode, but you can emulate it
    by creating the controls at run time.

    I have created an array of picturebox controls to display a variable
    number of images on a form. I did this in C#.NET but I don't see why
    it can't be done with VB.NET.

    Comment

    • Patrice

      #3
      Re: Array of textbox

      You can use an array of textboxes as you would do with any other array...
      For example in Form_Load :

      Const Max As Integer = 10
      Dim TextBoxes(Max) As TextBox
      For i = 0 To Max
      TextBoxes(i) = New TextBox
      TextBoxes(i).To p = i * TextBoxes(i).He ight
      Controls.Add(Te xtBoxes(i))
      Next

      You just won't have design time support (you could also use a textbox as a
      "model"). See http://msdn.microsoft.com/en-us/libr...8a(VS.80).aspx
      for details...

      Or do you need details such as Rnd being Math.Rand or vbRed being
      System.Drawing. Color.Red ?

      --
      Patrice

      "Angel López" <angel.lopezgom ez@salesianos.e dua écrit dans le message de
      groupe de discussion : e4TzYP5LJHA.466 8@TK2MSFTNGP03. phx.gbl...
      How to do this with Vb.net 2008???
      >
      myNumber=1+ Int(Rnd()*90)
      text(myNumber). backcolor=vbRed
      >
      Tanks
      >
      Angel
      >
      >
      >

      Comment

      • Armin Zingler

        #4
        Re: Array of textbox

        "Angel López" <angel.lopezgom ez@salesianos.e duschrieb
        How to do this with Vb.net 2008???
        >
        myNumber=1+ Int(Rnd()*90) text(myNumber). backcolor=vbRed
        Put all textboxes in an array before, for example:

        Public Class Form1

        Dim textboxes As TextBox()

        Private Sub Form1_Load( _
        ByVal sender As System.Object, ByVal e As System.EventArg s) _
        Handles MyBase.Load

        textboxes = New TextBox() {TextBox1, TextBox2, TextBox3}
        End Sub

        End Class


        (no, there are no "control arrays" anymore...)


        Armin

        Comment

        • Cor Ligthert[MVP]

          #5
          Re: Array of textbox

          Zack,

          In my idea are you mixing up using the designer to create something and
          runtime.

          You can make something at runtime by using reflection, however mostly and
          more save is to do it at design time by code.

          Both Armin and Patrice give samples for this, where I like the sample from
          Armin the most because he uses the designer to create the labels.
          As long as that the labels are not moving over the screen, then there is in
          my idea not any reason to make them dynamicly.

          jmo

          Cor

          <zacks@construc tion-imaging.comwrot e in message
          news:8c0719ad-9aff-4e4f-b858-126cfb46b652@k1 6g2000hsf.googl egroups.com...
          On Oct 16, 9:34 am, "Angel López" <angel.lopezgo. ..@salesianos.e du>
          wrote:
          How to do this with Vb.net 2008???
          >
          myNumber=1+ Int(Rnd()*90)
          text(myNumber). backcolor=vbRed
          >
          You can't make a control array in design mode, but you can emulate it
          by creating the controls at run time.

          I have created an array of picturebox controls to display a variable
          number of images on a form. I did this in C#.NET but I don't see why
          it can't be done with VB.NET.

          Comment

          • Cor Ligthert[MVP]

            #6
            Re: Array of textbox

            Armin,

            I hope you don't mind, just your opinion, would it not be better to use the
            text

            "There are no VB6 control arrays anymore"

            Probably like you I think the OP is a classic VB6 user, however others who
            never used that can be confused.

            You show a true control arrays in your code.

            Just writing what I was thinking when I saw your text.

            Cor

            "Armin Zingler" <az.nospam@free net.dewrote in message
            news:u2uV2e5LJH A.4376@TK2MSFTN GP04.phx.gbl...
            "Angel López" <angel.lopezgom ez@salesianos.e duschrieb
            >How to do this with Vb.net 2008???
            >>
            >myNumber=1+ Int(Rnd()*90) text(myNumber). backcolor=vbRed
            >
            Put all textboxes in an array before, for example:
            >
            Public Class Form1
            >
            Dim textboxes As TextBox()
            >
            Private Sub Form1_Load( _
            ByVal sender As System.Object, ByVal e As System.EventArg s) _
            Handles MyBase.Load
            >
            textboxes = New TextBox() {TextBox1, TextBox2, TextBox3}
            End Sub
            >
            End Class
            >
            >
            (no, there are no "control arrays" anymore...)
            >
            >
            Armin

            Comment

            • Armin Zingler

              #7
              Re: Array of textbox

              "Cor Ligthert[MVP]" <Notmyfirstname @planet.nlschri eb
              Armin,
              >
              I hope you don't mind, just your opinion, would it not be better to
              use the text
              >
              "There are no VB6 control arrays anymore"
              >
              Probably like you I think the OP is a classic VB6 user, however
              others who never used that can be confused.
              >
              You show a true control arrays in your code.
              >
              Just writing what I was thinking when I saw your text.
              Hi Cor, :-)

              sorry, but this is really not my problem. I answered Angel who obviously
              knows what "control arrays" mean in this context. I really can not care
              about any reader that will read my message in the future without knowing
              what we are talking about. Of course you are right that I meant "VB6 control
              arrays". Thx for the correction on behalf of all future readers.

              BTW, the term was in double quotes, and, if I had meant an array of
              controls I would have named them array of controls. (w/o double qoutes) ;-)

              You should have better mentioned that 'textboxes' should not be declared
              locally but outside the method as a field of the class (which I was too lazy
              to correct). ;-)

              There are worse things as we both know. :)


              Armin

              Comment

              • Angel López

                #8
                THANKS TO EVERYBODY

                TANKS to every body

                Regards from Spain

                "Angel López" <angel.lopezgom ez@salesianos.e duescribió en el mensaje
                news:e4TzYP5LJH A.4668@TK2MSFTN GP03.phx.gbl...
                How to do this with Vb.net 2008???
                >
                myNumber=1+ Int(Rnd()*90)
                text(myNumber). backcolor=vbRed
                >
                Tanks
                >
                Angel
                >
                >
                >

                Comment

                Working...