Create and use TextField dynamically

I am stumped here… again. I can create text fields dynamically but I for the life of me cannot figure out how to actually use them to do anything useful. I have a personal application that I am experimenting with some coding styles / ideas. And one of them is to simplify how many forms ( windows ) and fields I need to create. So I have several methods that contain code for different actions. That code works in an earlier version of my app.

Currently I have a whole slew of TextFields and Labels created with generic names. And I use a ComboBox to select what I want to do, this in turn will show the appropriate Labels and TextFields and populate them as needed. But this to me is not very clean and so I want to instead create the TextFields and Labels on the fly instead of .Show = True or False.

Like I said I can create the objects but I can’t use them. Meaning I can’t reference them after creation. I have been searching and nothing I have found so far seems to address what I am looking for. Maybe it can’t be done, either way I am here asking hat in hand again!

This is the reset code I use to put all the items to a clean state.

// Set Label Values...
lbl01.Text = ""
lbl02.Text = ""
lbl03.Text = ""
lbl04.Text = ""
lbl05.Text = ""
lbl06.Text = ""
lbl07.Text = ""
lbl08.Text = ""
lbl09.Text = ""
lbl10.Text = ""
lbl11.Text = ""
lbl12.Text = ""
lbl13.Text = ""
lbl14.Text = ""

// Set Text Box Values...
txt01.Text = ""
txt02.Text = ""
txt03.Text = ""
txt04.Text = ""
txt05.Text = ""
txt06.Text = ""
txt07.Text = ""
txt08.Text = ""
txt09.Text = ""
txt10.Text = ""
txt11.Text = ""
txt12.Text = ""
txt13.Text = ""
txt14.Text = ""
TextArea1.Text = ""

// Hide it all...
lbl01.Visible = False
lbl02.Visible = False
lbl03.Visible = False
lbl04.Visible = False
lbl05.Visible = False
lbl06.Visible = False
lbl07.Visible = False
lbl08.Visible = False
lbl09.Visible = False
lbl10.Visible = False
lbl11.Visible = False
lbl12.Visible = False
lbl13.Visible = False
lbl14.Visible = False
lblMonth.Visible = False
lblYear.Visible = False

txt01.Visible = False
txt02.Visible = False
txt03.Visible = False
txt04.Visible = False
txt05.Visible = False
txt06.Visible = False
txt07.Visible = False
txt08.Visible = False
txt09.Visible = False
txt10.Visible = False
txt11.Visible = False
txt12.Visible = False
txt13.Visible = False
txt14.Visible = False
TextArea1.Visible = False
cboSelMonth.Visible = False
cboSelYear.Visible = False

lstBx01.Visible = False
lstBx02.Visible = False

lstBx01.RemoveAllRows
lstBx02.RemoveAllRows

btn01.Caption = ""
btn02.Caption = ""
btn03.Caption = ""
btn04.Caption = ""
btn05.Caption = ""
btn06.Caption = ""

btn01.Visible = False
btn02.Visible = False
btn03.Visible = False
btn04.Visible = False
btn05.Visible = False
btn06.Visible = False

And this is one of the methods that then will set the above to a new state for use.

// Set up both the list boxes for use
lstBx01.Visible = True
lstBx02.Visible = False
lstBx01.RemoveAllRows

// Listbox one settings...
lstBx01.ColumnCount = 5
lstBx01.ColumnWidths = "20%,20%,20%,20%,20%"
lstBx01.Heading( 0 ) = "Rec Num"
lstBx01.Heading( 1 ) = "Date"
lstBx01.Heading( 2 ) = "Shift Time"
lstBx01.Heading( 3 ) = "Over Time"
lstBx01.Heading( 4 ) = "Dbl Time"

lstBx01.ColumnAlignmentAt( 0 ) = Listbox.Alignments.Center
lstBx01.ColumnAlignmentAt( 1 ) = Listbox.Alignments.Center
lstBx01.ColumnAlignmentAt( 2 ) = Listbox.Alignments.Center
lstBx01.ColumnAlignmentAt( 3 ) = Listbox.Alignments.Center
lstBx01.ColumnAlignmentAt( 4 ) = Listbox.Alignments.Center

// Set up remaining elements...
cboSelMonth.Visible = False
cboSelYear.Visible = False
lblMonth.Visible = False
lblYear.Visible = False

// Visibility state...
lbl01.Visible = True
lbl02.Visible = True
lbl03.Visible = True
lbl04.Visible = True
lbl05.Visible = True
lbl06.Visible = False
lbl07.Visible = False
lbl08.Visible = False
lbl09.Visible = False
lbl10.Visible = False
lbl11.Visible = False
lbl12.Visible = False
lbl13.Visible = False
lbl14.Visible = False

txt01.Visible = True
txt02.Visible = True
txt03.Visible = True
txt04.Visible = True
txt05.Visible = True
txt06.Visible = False
txt07.Visible = False
txt08.Visible = False
txt09.Visible = False
txt10.Visible = False
txt11.Visible = False
txt12.Visible = False
txt13.Visible = False
txt14.Visible = False

' Set visible element values
lbl01.Text = "Shift Date"
lbl02.Text = "Shift Hours"
lbl03.Text = "Over Time"
lbl04.Text = "Double Time"
lbl05.Text = "Est Wage"

// Set initial field values...
txt01.Text = modAppFunct.mthDate( )
txt02.Text = "8.0"
txt03.Text = "4.0"
txt04.Text = "0.0" 
txt05.Text = "" '<-- write query for this...

// Set edit state...
txt01.ReadOnly = False
txt02.ReadOnly = False
txt03.ReadOnly = False
txt04.ReadOnly = False
txt05.ReadOnly = True

// Set button states and captions...
btn01.Visible = True
btn02.Visible = True
btn03.Visible = True
btn04.Visible = False
btn05.Visible = False
btn06.Visible = False

btn01.Caption = "Shift Hrs"
btn02.Caption = "New Pay Per"
btn03.Caption = "Wage Est"

frmNavigator.mthSetUp_HoursLstBox

So I want to do this dynamically… but how?

Check the documentation for “AddHandler” which beams the event to a method.