how to reference form property?

A

anthony

I tried sth i did b4 in VB, now in VB.NET, but since the form is created
every time, the following code would not work because MsgBox.Visible is
always false, any idea? Thanks!



Public Function MyMsgBox(ByVal strMsg As String, ByVal MsgType As Integer,
ByVal strTitle As String) As Integer

Dim MsgBox As New frmMsgBox

If MsgBox.Visible = False Then

MsgBox.Text = strTitle

MsgBox.MsgType = MsgType

MsgBox.lblMsg.Text = strMsg

MsgBox.ShowDialog()

MyMsgBox = MsgBox.Response

MsgBox.Close()

End If

End Function
 
L

Lucas Tam

I tried sth i did b4 in VB, now in VB.NET, but since the form is
created every time, the following code would not work because
MsgBox.Visible is always false, any idea? Thanks!



Public Function MyMsgBox(ByVal strMsg As String, ByVal MsgType As
Integer, ByVal strTitle As String) As Integer

Dim MsgBox As New frmMsgBox

Set Msgbox as a class variable.
 
C

Chris, Master of all Things Insignificant

MsgBox.visble will be false until .showdialog or .show is called.

On top of that the .showdialog is a blocking call, so nothing else can
happen in this function until it returns from .showdialog.
You don't need to do the .Close either since .ShowDialog won't return until
the box is closed. Also instead of doing MyMsgBox = MsgBox.Response, you
can now use the "Return MsgBox.Response" Which is the newer way of doing
it, and I, personally think the correct way <grin>

What are you trying to accomplish here? Since you just created the MsgBox
object, there is reason to check MsgBox.Visible, you know for sure that it
isn't showing because you just created it. It looks like you are just
trying to replace the messagebox class. If that is the case then just take
out the Msgbox.Visible = False and then .Close and you will be good.

Chris
 
A

anthony

Thanks,

I am trying to have my custom error/warning message box, I used it in some
timer control, so I dont want to have too many message box opened if the
user hasnt acknowledged, in other words, just one message box on top, it
will not be replaced neither, new warning message only appears if the old
one is clicked OK.

But the NEW keyword creates a new form every time.
 
C

Chris, Master of all Things Insignificant

I don't clam to understand your setup completely, but why have a timer fire
off warning messages? By using that showdialog the whole system will stop
until the user acknowledges the messagebox. If I was going to do what you
are talking about do something like this.

Public Class Foo

Dim MyMsgBox as frmMsgBox

Function ShowMessageBoxFunction() as Integer
If MyMsgBox is nothing then
'Hey there already is a live messagebox, leave
return -1
else
MyMsgbox = new frmMsgBox
'Do bunch of stuff
end if

End Function

End Class

This way you have a variable to check all the time if there is a messagebox
showing or not. But llike I said, you have other logic problems going on as
to when the user will see the box. Do you need processing to be done while
the error message is on the screen?

Chris
 
C

Chris, Master of all Things Insignificant

Sorry, slight correction. I had my if statement backward, throw in a not it
works like it says it does.
Chris
 
A

anthony

thx, ur method works, just need to set MyMsgbox = Nothing at the end of the
else statement.

the warning message only fired if there is a run time error, like a file not
found error, i just dont want to have the same message box opened multiple
times.
 
C

Chris, Master of all Things Insignificant

But I have to ask again. Why have a "timer" show the message? Isn't your
system suppose to stop everything if there is a runtime error?

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top