User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 402,003 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,414 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Views: 2605 | Replies: 7
Reply
Join Date: Mar 2007
Posts: 2
Reputation: hyenakal is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
hyenakal hyenakal is offline Offline
Newbie Poster

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

  #1  
Mar 21st, 2007
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2007
Posts: 5
Reputation: JamesDT is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
JamesDT JamesDT is offline Offline
Newbie Poster

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

  #2  
Mar 21st, 2007
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.

form2.show vbModal
option = form2.getSelected()
form2.dispose()


or for VB2005

form2.showDialog()
option = form2.getSelected()
form2.dispose()

will open it in Modal

Hope this helps
Reply With Quote  
Join Date: Mar 2007
Posts: 2
Reputation: hyenakal is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
hyenakal hyenakal is offline Offline
Newbie Poster

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

  #3  
Mar 21st, 2007
i'm sorry i didnt make it clear that i'm using vb 6.0

thank you
Reply With Quote  
Join Date: Mar 2007
Posts: 59
Reputation: PVBert is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 5
PVBert PVBert is offline Offline
Junior Poster in Training

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

  #4  
Mar 21st, 2007
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!)
Reply With Quote  
Join Date: Apr 2007
Posts: 34
Reputation: pbrookee is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
pbrookee pbrookee is offline Offline
Light Poster

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

  #5  
May 17th, 2007
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!!
Reply With Quote  
Join Date: Mar 2007
Posts: 59
Reputation: PVBert is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 5
PVBert PVBert is offline Offline
Junior Poster in Training

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

  #6  
May 17th, 2007
try to get the explained methods
not just the solutions
all answers are given before
use global variables
Reply With Quote  
Join Date: Apr 2007
Posts: 34
Reputation: pbrookee is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
pbrookee pbrookee is offline Offline
Light Poster

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

  #7  
May 21st, 2007
got it!
thanks much!
Kudos!
Reply With Quote  
Join Date: May 2007
Posts: 31
Reputation: ~Paul~ is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
~Paul~ ~Paul~ is offline Offline
Light Poster

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

  #8  
May 25th, 2007
I wouldn't use a function for simply a variable that is kind of a bad habit and useless.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Visual Basic 4 / 5 / 6 Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum

All times are GMT -4. The time now is 9:13 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC