devxlogo

Use the MsgBox Wrapper to Replace OK

Use the MsgBox Wrapper to Replace OK

Replace all MsgBox calls that display only an OK message with the following OkMsg sub. It automatically defaults the icon to vbInformation, and the title to a global constant defined at startup. None to all of the parameters can be passed to override the defaults. Another advantage is that the OkMsg sub saves and restores the state of the mousepointer, so you don’t get an hourglass outside the MsgBox:

 Sub OkMsg(Optional sMsg As String = _	"Press OK to Continue", Optional vIcon = _	vbInformation, Optional sTitle As String = APPNAME)	Dim iMouse As Integer	iMouse = Screen.MousePointer	Screen.MousePointer = vbDefault	MsgBox sMsg, vIcon, sTitle	Screen.MousePointer = iMouseEnd Sub

To call this sub, use this syntax:

 	OkMsg  "The Record is Saved"	OkMsg "The date entered is out of range!", _		vbExclamation, "INPUT ERROR"

Always declare the global constant:

 	Global Const APPNAME = "Management System"

Note: VB3 users must change the optional parameters to required, and VB4 users must insert IsMissing checks to assign defaults to missing optional parameters.

See also  How College Students Can Shape the Future of Tech Responsibility
devxblackblue

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