How do I pass data in string from a form to another?

i'm trying to pass the option selected on my list box from one from to another to be displayed in a text box. how do i do that?
thank you

There are many ways,
You could have a global variable in your second form to store which option was selected. Then just have a PUBLIC method in your second form called getSelected which returns your option

public function getSelected()
return selection
end function

then as long as you open the second form modally, the first form will wait for the second form to close before executing the rest of the code. vbModal
option = form2.getSelected()

or for VB2005

option = form2.getSelected()

will open it in Modal

Hope this helps

i'm sorry i didnt make it clear that i'm using vb 6.0

thank you

Make a public form variable in the second form.
Load the second form modally.
Pass the value to the form as a propertie.
If you are ready in the form close is
The form properties stay preserved.
Do with them what you want (e.q. in the fist form).
Then, unload the second form.

'In Form1
Form2.Show vbModal
MsgBox "We still have the string: " & form2.my_second_string
Unload Form2
'Here Form2 is destroyed; with it the (public) string

'In Form2
Public My_Second_String as String

Private Sub Test()
My_Second_String = "The_Second_String"
'Returns us to Form1, beyond: Form2.Show vbModal
'Preserve the string to take it to Form1
End Sub


'In Form1
Form2.My_Second_String = "From Form1 to Form2"
'in Form2
Public My_Second_String As String

Private Sub Test()
My_Second_String = "The_Second_String"
'returns us to Form1, beyond: Form2.Show vbModal
End Sub

(not tested!)

You could also do it this way....
In Form 1
Public Function ShowLogIn() As String
ShowLogIn = frmUser.txtUsername.Text
End Function

In Form 2
Private Sub Form_Load()
lblName = frmUser.ShowLogIn()
End Sub

......does anyone know how to get it to display in multiple forms??


try to get the explained methods
not just the solutions
all answers are given before
use global variables

got it!
thanks much!

I wouldn't use a function for simply a variable that is kind of a bad habit and useless.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.