Link to home
Start Free TrialLog in
Avatar of Natavia Finnie
Natavia FinnieFlag for United States of America

asked on

vb.net How upload data from a .txt file into the controls on the UI using control name

Here is am example of my .txt file:

<%:cntrlName="cntrlSavedData"\%>

<%:productionPlan=""\%>
<%:ProteinName="CP4 EPSPS"\%>
<%:historicalLotNum="20-100048"\%>
<%:ExpPlasmid="pMON21104"\%>

please ignore <%:\%>

I want to be able to recursively add the data back to the textboxes and comboboxes using this format.
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi taviaf;

Read each line of the file and parse it to control name and the value. Then on the Form that the control is on you can do the following.

Dim ctl = Me.Controls.Find(name, True)

Open in new window

Where the name is the control you need to update and True is to search ALL child controls. That method returns an array of controls. If the control was found it will be in position 0. Depending on which property you may be updating you may need to cast to the control type. For example

Dim tb As TextBox = DirectCast(ctl(0), TextBox)

Open in new window

In this sample you can update the TextBox, tb, as needed.
Avatar of Natavia Finnie

ASKER

@Fernando Soto, I am new to vb.net so you may have to be just a bit more detailed.  Sorry....
When you say that to, please ignore <%:\%>, does that mean that it is not in the file?
No that is in the file. If I was to use part of the current function it ignores those. Put if I was to write my own then DO NOT ignore.

In this case do not ignore because the .txt file is saved like the example that I gave.  

That's all.....
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial