Solved

Can I change MsgBox Constants Graphics in VB5?

Posted on 1998-08-05
8
251 Views
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.

Cheers.
0
Comment
Question by:imajdn
  • 4
  • 3
8 Comments
 
LVL 1

Expert Comment

by:Anita030598
Comment Utility
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.
0
 
LVL 1

Expert Comment

by:jf26028
Comment Utility
You can pass parameters to a subroutine and from there, based on the parameters, load the form.
0
 

Author Comment

by:imajdn
Comment Utility
Are you talking about passing parameters to the Form_Load method?
How?

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.

Cheers.

0
 
LVL 1

Expert Comment

by:jf26028
Comment Utility
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

  statements...
  statements...

  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.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:imajdn
Comment Utility
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.

Using:

   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.
0
 
LVL 1

Expert Comment

by:jf26028
Comment Utility
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.
0
 
LVL 1

Accepted Solution

by:
jf26028 earned 100 total points
Comment Utility
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.
0
 

Author Comment

by:imajdn
Comment Utility
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.

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now