Practical Web Programming

Wednesday, November 21, 2007

How To Make Custom Messages in VB6

If you are a Visual Basic (VB6) programmer who finds displaying messages using the MsgBox function so tedious. The functions below will make your life easier.

I wrote this functions to answer my demands in displaying messages to the users of my programs. This function is very handy. In fact, almost all of my Visual Basic projects uses this functions.

This functions re-uses the Visual Basic's MsgBox function to create custom message functions that are more flexible and easy to use.

'-->enum for the return of the confirmation from the user
Public Enum enum_prompt_return_value
pr0mpt_yes = vbYes
pr0mpt_no = vbNo
End Enum

'-->system name variable desclaration
'-->ex: gsystem_title = "payroll system"
Public gsystem_title As String

'-->this sub will display the critical error
'-->using the error object passed to it
'-->usage : call criticalerrormsg(err, ["error"])
Public Sub criticalerrormsg(err As ErrObject, _
Optional strtitle As String = "critical error")
MsgBox err.Number & ": " & err.Description, vbCritical, _
gsystem_title & " - [" & strtitle & "]"
End Sub

'-->this sub will display the error using the
'-->error object passed to it
'-->usage : call errormsg(err, ["error"])
Public Sub errormsg(err As ErrObject, _
Optional strtitle As String = "error")
MsgBox err.Number & ": " & err.Description, vbExclamation, _
gsystem_title & " - [" & strtitle & "]"
End Sub

'-->this sub will display an information message
'-->using the text passed to it
'-->usage : call infomsg(err, ["info"])
Public Sub infomsg(strmessage As String, _
Optional strtitle As String = "info")
MsgBox strmessage, vbInformation, _
gsystem_title & " - [" & strtitle & "]"
End Sub

'-->this sub will display an information
'-->message using the text passed to it
'-->usage : call infomsg(err, ["info"])
Public Sub alertmsg(strmessage As String, _
Optional strtitle As String = "alert")
MsgBox strmessage, vbExclamation, _
gsystem_title & " - [" & strtitle & "]"
End Sub

'-->this sub will ask a confirmation from
'-->the user using the text passed to it
'-->usage : retval = confirmmsg("delete record?", ["confirm"])
Public Function confirmmsg(strmessage As String, _
Optional strtitle As String = "confirm") As _
enum_prompt_return_value
confirmmsg = MsgBox(strmessage, vbQuestion + vbYesNo, _
gsystem_title & " - [" & strtitle & "]")
End Function

0 comments:

Recent Post