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.

Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular