NameSilo

Passing strings from one Form to another in Visual Basic Express 2008?

Spaceship Spaceship
Watch

FPForum

Top Member
Impact
1,436
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?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
It would be good that you post some code.

Assuming that in the second form you already have a reference set to Form1 you could get the value of the string entered in the textbox like this (in Form2)
Code:
filecnt = Form1.txtDirectory.Text
where txtDirectory is the textbox name

A better way would consist in passing the string as a parameter to Form2 using Overload methods.
Example: How To Pass Data Between Forms in VB.NET
 
1
•••
Got it figured out sds! Thanks
 
0
•••

We're social

Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back