Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language:
Expertise: Beginner
Aug 8, 1997

Retrieving Data from A Dialog Form Without Using Globals

From the days of VB3, you no doubt recall the pain of retrieving answers from a dialog form that you displayed from another form. The use of Globals was about the only way provided. In VB4, forms are objects and you can call methods in them from another form just as if they were in a code module. This new feature allows you to call a function in a dialog form, which will display itself, and when the form is unloaded, return your answers. Add this code to your main code that needs user input:

 
        Dim sAnswer As String

        sAnswer = frmDialog.Display()

        'when control returns sAnswer 
        'will have the user reply.




To your frmDialog (.frm) file, add this code:

 
        Dim sRetValue As String

        Public Function Display() As String
                Me.Show vbModal 
                Display = sRetValue
        End Function

        Private Sub cmdOK_Click()
                ' This function must set up the 
                ' return value because the
                ' Text box will be unloaded when 	
                ' "Display" regains control
	           sRetValue = Text1.Text
		Unload Me
	End Sub

Obviously, you can retrieve data from more than one control. In that instance you would pass an object ot array to the Display function for it to retun multiple values. Userdefined types (UDTs) don't appear to work.

Les Smith
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date