Get value from textbox in one form and show in textbox iun opther form

DaniBoy

Registered User.
Local time
Today, 06:53
Joined
Nov 18, 2001
Messages
175
Hello,

I need help on this simple procedure:

I have two forms, in form1 I have a textfield name file1 that I input any if info, than on form2 I have another textfield name file2. What i want to do is that when I press my comand botton it gets the value of file1 and puts it in file2?

Can you do this simple code for me?

Thanks

Daniboy
 
Forms!Form2.file2 = Forms!Form1.file1
 
First go into the Form2.vb file and instantiate a global variable to hold the value from the other form and then write a constructor that would look like this:

public sub new(byref value as string)
InitializeComponent() 'This is required to create the controls on the form

GlobalVariable = value
End Sub

Then the value will be available throughout Form2 and if you want to set it to the text of a file2 you would just write

file2.text = GlobalVariable

Inside the onLoad event of Form2

This should work easy enough, and you can pass any kind of variable between any number of forms this way. I'm usually not a fan of using global variables but I haven't found a way around it as of yet.

Hope this helps,
Mike O'Brien
 
Last edited:
I apologize; I didn't notice this was in the VB.Net forum and I gave a VBA answer.
 

Users who are viewing this thread

Back
Top Bottom