Pass Parameters to User Dialogs

Pass Parameters to User Dialogs

It’s fairly common practice to add buttons to your date and numeric fields to allow users to select and display a popup calendar or calculator. However, to display a calculator or calendar without allowing it to communicate with the calling application defeats the purpose of giving the user these capabilities. The called dialog is only an appendage that cannot pass the user’s calculation back to the field from which the resource was called.

To solve this problem, add a button to a form next to a numeric input field (txtAmount). In the Click event of this button, place a Load statement for the form you want to show the user:

 Sub cmd_Click()	Load Calculator_Dialog	Calculator_Dialog.Show 1	' modalEnd Sub

Pass parameters to a form by writing a wrapper utility that handles the passing of these parameters to and from the called dialog:

 Sub cmd_Click()	CalculatorDialog_Show txtAmountEnd SubSub CalculatorDialog_Show (C As Control)'' Display the Calculator_Dialog and return '' the calculated value as a stringLoad Calculator_DialogCalculator_Dialog.lblReadout = _	Format(Val(C.Text), "#.###############") ' Pass the number to dialogCalculator_Dialog.Op1 = Format(Val(C.Text), _	"#.###############")' simulate user inputCalculator_Dialog.LastInput = "NUMS"Calculator_Dialog.Show 1	' modalIf Calculator_Dialog.Action = True Then	C.Text = Format(Calculator_Dialog._		lblReadout, "General Number")End IfUnload Calculator_DialogSet Calculator_Dialog = NothingEnd Sub

The parameters are passed to hidden label controls on the Calculator_Dialog form between the time the form is loaded and the time it’s displayed. A hidden label control on the Calculator_Dialog (Action) indicates whether the user chose the OK or Cancel button to exit the dialog. Rather than unload the Calculator_Dialog when the user presses the OK or Cancel button, the form hides until the calling sub (CalculatorDialog_Show) processes the value of Calculator_Dialog.lblReadout. The form is then unloaded, and the Set-to-Nothing statement is executed to purge memory of the form’s controls and procedures.

This technique works with any version of VB. Starting with VB4, you can add properties and methods to forms, which is a preferable method to relying on hidden labels for interobject communication.

Share the Post:
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

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of