Get value from textbox in one form and show in textbox iun opther form (1 Viewer)

DaniBoy

Registered User.
Local time
Today, 14:14
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
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:14
Joined
Aug 30, 2003
Messages
36,125
Forms!Form2.file2 = Forms!Form1.file1
 

Michael_OBrien

New member
Local time
Today, 08:14
Joined
Jan 15, 2008
Messages
4
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:

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:14
Joined
Aug 30, 2003
Messages
36,125
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

Top Bottom