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:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a