944,073 Members | Top Members by Rank

Ad:
Mar 21st, 2007
0

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

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hyenakal is offline Offline
2 posts
since Mar 2007
Mar 21st, 2007
0

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

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
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. <code class="inlinecode">public function getSelected()
  2. return selection
  3. end function</code>


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.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. <code class="inlinecode">
  2. form2.show vbModal
  3. option = form2.getSelected()
  4. form2.dispose()
  5. </code>


or for VB2005
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. <code class="inlinecode">
  2. form2.showDialog()
  3. option = form2.getSelected()
  4. form2.dispose()
  5. </code>

will open it in Modal

Hope this helps
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JamesDT is offline Offline
5 posts
since Mar 2007
Mar 21st, 2007
0

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

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

thank you
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hyenakal is offline Offline
2 posts
since Mar 2007
Mar 21st, 2007
0

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

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"
Form2.hide
'Returns us to Form1, beyond: Form2.Show vbModal
'Preserve the string to take it to Form1
End Sub

--or--------------------------------------------------

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

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

(not tested!)
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
PVBert is offline Offline
60 posts
since Mar 2007
May 17th, 2007
0

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

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??

Thanks!!
Reputation Points: 10
Solved Threads: 0
Light Poster
pbrookee is offline Offline
34 posts
since Apr 2007
May 17th, 2007
0

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

try to get the explained methods
not just the solutions
all answers are given before
use global variables
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
PVBert is offline Offline
60 posts
since Mar 2007
May 21st, 2007
0

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

got it!
thanks much!
Kudos!
Reputation Points: 10
Solved Threads: 0
Light Poster
pbrookee is offline Offline
34 posts
since Apr 2007
May 25th, 2007
0

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

I wouldn't use a function for simply a variable that is kind of a bad habit and useless.
Reputation Points: 35
Solved Threads: 0
Light Poster
~Paul~ is offline Offline
31 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: where is wrong?
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Reading from non existant Text file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC