Retrieving Data from A Dialog Form Without Using Globals

Retrieving Data from A Dialog Form Without Using Globals

From the days of VB3, you no doubt recall the pain of retrievinganswers from a dialog form that you displayed from another form.The use of Globals was about the only way provided. In VB4, formsare objects and you can call methods in them from another formjust as if they were in a code module. This new feature allowsyou to call a function in a dialog form, which will display itself,and when the form is unloaded, return your answers. Add this codeto 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 thatinstance you would pass an object ot array to the Display functionfor it to retun multiple values. Userdefined types (UDTs) don’t appear to work.

See also  Why ChatGPT Is So Important Today

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist