I am using a TextBox control on one form to accept a directory name and trying to use it on a second form to find the number of files in that directory (filecnt = My.Computer.FileSystem.GetFiles(Form1.txtLocallyArchivedJpg). I receive the following error whenever I try and use the directory entered in the TextBox “Value of type 'System.Windows.Forms.TextBox' cannot be converted to 'String'†How can I get rid of this error?
There are several methods. The easiest is to write a public property on Form1 to pass the string of the test box as in following example. public string MyTestBox { get {return textbox1.Text;} set {textbox1.Text = value;} } Code (markup):
Thanks Neo. I tried to leave some rep for you but says I need to leave rep for others first before I can give you more, lol. Anyways, I tried what you had said but I am getting an error saying the keyword string is not a valid identifier. Basically I can get the two forms to talk to one another...but I can't seam to pass the text in textbox1 (Form1) into a textbox I have on Form2. Thanks again for your help!
Did you load the form with text box as below from the main form? (Note that codes are in C#, I think it will be easy to convert them to VB.Net) Form2 form2; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { form2 = new Form2(); form2.Show(); } private void button1_Click(object sender, EventArgs e) { MessageBox.Show(form2.MyTestBox); } Code (markup):