Setting Value of Specific Field on a Window at Runtime

I have a Database Table which contains two fields, the Field_Name and Field_Value. I want to display the Text Value for the Text Field from the Database at runtime.

MainWindow has 6 Control Items named A, B, C, D, E and F.
Database Table has a Text Field “A” is Value “Bob Smith”
Database Table has a Text Field “C” is Value “Jane Smith”
I don’t store Text Fields with blank values

How do I set Text Field “A” to have value of “Bob Smith” at run time?
I tried, but I get an error.

Dim sField As String
Dim sValue As String
sField = “A”
sValue = “Bob Smith”

MainWindow. + sString + .Text = sValue

Uh, you can’t do that. i.e. refer to a control with a variable name.
MainWindow.TextFieldA.Text = sValue
or make your text areas a control set. That will give each field an index value.
MainWindow.myTextField(0).Text = sValue
MainWindow.myTextField(1).Text = tValue

You can write a utility method to set a textfield by name.

Sub SetFieldByName(extends w as window, name as string, value as string)
   for i as integer = 0 to w.ControlCount-1
      if w.Control(i) ISA TextField then
         if TextField(Control(i)).Name = name then
            TextField(Control(i)).Text = value
End Sub

Call it as

MainWindow.SetFieldByName("A", "Bob Smith")

That was perfect, thank you very much…