Control Arrays ?

azrael211

Newcomer
Joined
Jul 6, 2006
Messages
2
I am currently writing a program for a ame I play, it works out the profit I will make from manufacturing stuff.

The blueprint requires 1 or more components to build and item and my program wrks out the profitability of the item based on the amount produced and sell prices etc.


Each component line has component name, unit/batch, cost/unit, units/30days I then perform some maths which takes the unit/batch * unit/cost = units/30days

I can create 4 new text boxes under the original ones and give then names and perform the maths etc but I am wondering how I manage these once I get up to say 20 rows, I assume a control array which is now and event handler i beleive.

I have read about event handlers which seems fine for one textbox but how do i address many textboxes when i dont know their names to control them?

Thank you in advance for any help.
 
Take a look at how the designer sets up the event handler for other controls. You need to do the same thing, except in an array.
 
Here is how I do it, The first code is where I set up a textbox array and calls for a handle. The second cose is a sub for the handle

Code:
      With txtFreqs(intL)
                .Size = New Size(56, 25)
                .Location = New Point(intTFX, intY)
                .Enabled = False
                .MaxLength = 6
                .Name = "txtFreq" & intL.ToString
                AddHandler txtFreqs(intL).KeyPress, AddressOf HandlesTextBox
            End With

This handle is so someone can only write numbers and use the backspace
Code:
  Private Sub HandlesTextBox(ByVal sender As Object, ByVal e As KeyPressEventArgs)
        If Not Char.IsNumber(e.KeyChar) And Not Asc(e.KeyChar) = 8 Then
            e.Handled = True
        End If
    End Sub

Hope this helps and steers you in the right direction for what you are looking for
 
Back
Top