Results 1 to 3 of 3

Thread: Initializing a lot of variables without repetition

  1. #1

    Thread Starter
    Addicted Member Michel Jr's Avatar
    Join Date
    Jan 2000
    Location
    Brazil
    Posts
    175

    Question

    Hi,

    How can I initialize a lot of TextBox like below:

    TextBox1.Text = "0"
    TextBox2.Text = "0"
    TextBox3.Text = "0"
    TextBox4.Text = "0"
    TextBox5.Text = "0"
    TextBox6.Text = "0"
    TextBox7.Text = "0"
    TextBox8.Text = "0"
    ...
    ...
    TextBox99.Text = "0"
    TextBox100.Text = "0"

    Is there a more intelligent way to do this, instead of repeating the same code a lot of times?

    Thanks for any idea...

    Michel Jr.

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You could make an array of textboxes, just name them the same and set a individual index to each:
    Code:
    Dim a As TextBox
    For Each a In Text1
        a = 0
    Next a
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Addicted Member
    Join Date
    May 1999
    Posts
    161
    If your problem is solely on Text Boxes, you should use a control array. When creating your textboxes, you create one, copy and paste it... VB will create the array for you.

    Then, you can scroll through it just as Text1(i).Text = "0"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width