Can I change MsgBox Constants Graphics in VB5?

Posted on 1998-08-05
Medium Priority
Last Modified: 2012-06-27
I am using the MsgBox function in VB5 Enterprise and I would like to use custom graphics for the icons:

vbCritical        16    Display Critical Message icon.
vbQuestion        32    Display Warning Query icon.
vbExclamation     48    Display Warning Message icon.
vbInformation     64    Display Information Message icon.

Is it posssible to change these graphics?

Ideally I would create my own form but I'm not too sure how to pass parameters to a form.
How do you pass parameters to a form in VB?
If anyone can answer either of these questions, preferably the last as I would like to use
custom fonts and layouts as well, then I'll give top marks.

Question by:imajdn
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3

Expert Comment

ID: 1467953
For your second question:

There is nothing like passing parameters to a form. However, you can have public Properties and/or Mehods in a form. And you can set those Properties and/or call the Methods from some other modules any time you want.  Think about it, it may help you.

Expert Comment

ID: 1467954
You can pass parameters to a subroutine and from there, based on the parameters, load the form.

Author Comment

ID: 1467955
Are you talking about passing parameters to the Form_Load method?

Rather than having me guess can you give me an example of the calling and
called methods? I'd rather get a example working solution than have to work it
out myself using a few tips.


What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Expert Comment

ID: 1467956
Sorry I was not clear, but I did not have time to put an example.  I dont think that you can actually change the msgbox.  This is just a quick example of passing arguments to a subroutine and then loading a form with that subroutine inplace of the msgbox.  All you have to do, is make the form look like a msgbox.

Sub Command1_Click()

  Dim MsgBoxType as Integer


  If ErrorOrSomeReasonForAMsgBox Then
     If ErrorOrSomeReasonForAMsgBox = "Critical Message" Then
        Call DisplayFormLikeAMsgBox(1)
     End If
     If ErrorOrSomeReasonForAMsgBox = "Warning Query" Then
        Call DisplayFormLikeAMsgBox(2)
     End if
     ...Continue for the rest of the msgbox types
End Sub

Private Sub DisplayFormLikeAMsgBox(TypeOfIcon as Integer)
   If TypeOfIcon = 1 Then
      Form2.Picture1.Picture = "CriticalIcon"
      Form2.Load vbModal, Me
   end if
   If TypeOfIcon = 2 then
      Form2.Picture1.Picture = "WarningIcon"
      Form2.Load vbModal, Me
   end if
.And so on for the rest of the possible calls.

End Sub

This might not be what you were looking for in the first place, but it is a work-around the fact that you cant change the icon in the msgbox.  You could make the above code better with Select Case statements and things like that, but it is just an example.

Author Comment

ID: 1467957
I'm sorry to be blunt but what you have given me is a pile of tosh.

You do not load a form using:

         Form2.Load vbModal, Me

you declare the form, set the form, load the form, then show the form: e.g.

    Dim f2 As  Form2

    Set f2 = New  Form2
    Load f2
    f2.Show vbModal

AND what you have given me doesn't show any picture at all.


   Set f2.Picture1.Picture = LoadPicture(CurDir & "test.bmp")

just does not show the picture. I have tried the statement before and
after the Load Statement.
It is just an idea but why don't you try out a solution then give the results of
that solution. I am spending time trying to adapt what you give me into a
working solution and the whole point of Experts Exchange is that YOU
spend the time working out the solution and I give you the points.
Sorry but giving me what appears to be pseudo code isn't good enough.

Expert Comment

ID: 1467958
Sorry, I didnt realize who I was dealing with.  I assumed that you would be able to use the code as an example and figure out what you needed to do.  I will write a sample and post it on the web so that you can just cut and paste my code into your project.  Sorry for the trouble.  Ill post the answer when I get a chance.

Accepted Solution

jf26028 earned 400 total points
ID: 1467959
Here is the answer that I was talking about:

What you need:
Form1 - Just a form that has three command buttons on it, one for each type of msgbox that you want to call.  In this example, there are only three, Critical, Warning, and Information respectively.

Form2 - A form with three pictureboxes on it.  Picture1, Picture2, and Picture3, which represent the Critical, Warning, and Information icons.  The picture boxes 2 and 3 are invisible on the form, but still hold the pictures of the Warning and Information icons.  Picture1 is in the location on the form
where you want the icon to be located.  There must be a picturebox for each of the icons that you want to show.  All are hidden except for #1.

Use this code to make the form that looks like a msgbox appear.  This code is in form1.

'example of a Critical Event
Private Sub Command1_Click()

    Call Msg(1) 'the 1 representes the type of icon in the
                'msgbox.  in this example, it is Critical

End Sub

Private Sub Command2_Click()

    Call Msg(2) 'the 2 representes the type of icon in the
                'msgbox.  in this example, it is Warning
End Sub

Private Sub Command3_Click()

    Call Msg(3) 'the 3 representes the type of icon in the
                'msgbox.  in this example, it is Information
End Sub

'this is the code that changes form2 to look the way
'that you want(critical, warning, or information)

Sub Msg(Kind As Integer)

    If Kind = 1 Then  'the form should look like a critical msgbox
        'use the icon that is already in picture1 (the critical icon)
        'and show the form
        Form2.Show vbModal, Me
    End If
    If Kind = 2 Then  'the form should look like a Warning msgbox
        'the picture is changed from picture1 to picture2(the warning icon)
        Form2.Picture1.Picture = Form2.Picture2.Picture
        Form2.Show vbModal, Me
    End If
    If Kind = 3 Then
'       ...
        Form2.Picture1.Picture = Form2.Picture3.Picture
        Form2.Show vbModal, Me
    End If

End Sub

This project is available at http://www.swt.edu/~jf26028/da.zip.
You may have problems if your paths to your icons in form2 are not the same as mine, but you can just insert your own.  Let me know if you still dont understand.

Author Comment

ID: 1467960
Thank you jf26028.
That is more like what I was expecting. I don't mind giving out full marks
if the answer is good. It's just that I don't have time to second guess someones
pseudo code.

Cheers again.


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question