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

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
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
Close
Got it figured out sds! Thanks
 
0
Close
Appraise.net

We're social

Escrow.com
Spaceship
CryptoExchange.com
Domain Recover

NamePros updates

Quick replies: search, your most used replies, and more on every post
Quick replies are easier to find and use now. The quick reply menu has a search box. Type a few letters to find the reply you want. A...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back