Home All Groups Group Topic Archive Search About
Author
28 Feb 2006 9:33 PM
Galen Somerville
VB6 to VB2005 with numerous forms. Of the two forms that are brought up from
the Main form, one fails.

This is at end of sub called by a Menu item. It works fine

   Dim hFrm As frmLect
   hFrm = New frmLect
   frmLect.Show()
   Me.Hide()

Exit Sub


This is at end of a TextBox. This textbox was made visible by a Menu item

   Dim hFrm As frmSweep
   hFrm = New frmSweep     error on this line
   frmSweep.Show()
   Me.Hide()

EventExitSub:

Pardon the huge error attachment

I've searched the Help till I'm blue in the face

Galen

[attached file: Image1.jpg]

Author
1 Mar 2006 6:48 AM
Wei-Dong XU [MSFT]
Hi Galen,

Thanks for posting at the newsgroup!

I have checked your code, which looks very well. They should work very
smoothly without any exception.

So currently for this NullReferenceException error, I think the exception
should be thrown at the frmSweep  class constructor. This is to say, some
members in the frmsweep may be assigned one value which is null so the
NullReferenceException is thrown. I'd suggest please open the class file of
frmsweep and check its constructor which is named Sub New in VB.net. Then
you can set one breakpoint at that method and debug the application to see
which line reported the exception.

Please feel free to let me know if you have any further question on this
issue.

Have a nice day!

Best Regards,
Wei-Dong XU
Microsoft Support
---------------------------------------------------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
---------------------------------------------------------------------------
It is my pleasure to be of any assistance.
Author
1 Mar 2006 3:54 PM
Galen Somerville
I set a breakpoint at Sub New and it never got to it.

When it fails at    hFrm = New frmSweep   intellisense shows hFrm = Nothing.

At the bottom of the screen it shows message "A first chance exception of
type System.NullReferenceException"

In idle mode the intellisense shows hFrm as Dim as Cardio70.frmSweep
and FrmSweep shows as Class frmSweep

Here is Sub New
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> Partial
Class frmSweep
#Region "Windows Form Designer generated code "
<System.Diagnostics.DebuggerNonUserCode()> Public Sub New()
        MyBase.New()
        IsInitializing = True
  'This call is required by the Windows Form Designer.
        InitializeComponent()
        IsInitializing = False
End Sub

Now what?

GalenS

""Wei-Dong XU [MSFT]"" <v-w***@online.microsoft.com> wrote in message
Show quoteHide quote
news:TOo26wPPGHA.2484@TK2MSFTNGXA03.phx.gbl...
>
>
> Hi Galen,
>
> Thanks for posting at the newsgroup!
>
> I have checked your code, which looks very well. They should work very
> smoothly without any exception.
>
> So currently for this NullReferenceException error, I think the exception
> should be thrown at the frmSweep  class constructor. This is to say, some
> members in the frmsweep may be assigned one value which is null so the
> NullReferenceException is thrown. I'd suggest please open the class file
> of
> frmsweep and check its constructor which is named Sub New in VB.net. Then
> you can set one breakpoint at that method and debug the application to see
> which line reported the exception.
>
> Please feel free to let me know if you have any further question on this
> issue.
>
> Have a nice day!
>
> Best Regards,
> Wei-Dong XU
> Microsoft Support
> ---------------------------------------------------------------------------
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> ---------------------------------------------------------------------------
> It is my pleasure to be of any assistance.
>
>
Author
2 Mar 2006 10:07 AM
Wei-Dong XU [MSFT]
Hi,

Thanks for the replying!

Currently since this error message looks very odd, I'd suggest if it
possible, could you be so kind to send this project to me and we will
research this for you? Thanks! Without one reproduce, that's really tough
for us to locate the root cause. Thanks!

My email address is: v-w***@online.microsoft.com (Please remove online from
the email address, used to avoid the spam )

Expect to your update!

Have a nice day!

Best Regards,
Wei-Dong XU
Microsoft Support
---------------------------------------------------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
---------------------------------------------------------------------------
It is my pleasure to be of any assistance.
Author
3 Mar 2006 8:22 AM
Wei-Dong XU [MSFT]
Hi,

Thanks for your great project!

After the debugging, I found there was the line in your frmSweep class
"19    Public PictMap As Bitmap = New Bitmap(Me.PictDraw.Width,
Me.PictDraw.Height)"
reported the "NullReferenceExcpetion" exception.

This property "Me.PictDraw" is null. So the class Bitmap doesn't have the
instantiated value in the constructor, then threw the exception.

I have one code review at the frmSweep class and found the two lines:
--------------
19    Public PictMap As Bitmap = New Bitmap(Me.PictDraw.Width,
Me.PictDraw.Height)
20    Public PicDraw As Graphics = Graphics.FromImage(PictMap)
--------------

This looks very odd that the two properties will be initialized by each
other which will definitly cause the NullReferenceException. I'd suggest
please change the two lines to make one successful instantiation. Then you
class should work as expected.

Besides, we can temporarily remove the line
"<System.Diagnostics.DebuggerNonUserCode()>" in the frmSweep constructor:
'<System.Diagnostics.DebuggerNonUserCode()>
Public Sub New()

Then if we are debugging the application, we can step into the constructor
of frmSweep.

Please feel free to let me know if you have any further question on this
issue.

Have a nice day!

Best Regards,
Wei-Dong XU
Microsoft Support
---------------------------------------------------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
---------------------------------------------------------------------------
It is my pleasure to be of any assistance.
Author
3 Mar 2006 3:23 PM
Galen Somerville
""Wei-Dong XU [MSFT]"" <v-w***@online.microsoft.com> wrote in message
Show quoteHide quote
news:OI1sXupPGHA.5836@TK2MSFTNGXA03.phx.gbl...
>
>
> Hi,
>
> Thanks for your great project!
>
> After the debugging, I found there was the line in your frmSweep class
> "19    Public PictMap As Bitmap = New Bitmap(Me.PictDraw.Width,
> Me.PictDraw.Height)"
> reported the "NullReferenceExcpetion" exception.
>
> This property "Me.PictDraw" is null. So the class Bitmap doesn't have the
> instantiated value in the constructor, then threw the exception.
>
> I have one code review at the frmSweep class and found the two lines:
> --------------
> 19    Public PictMap As Bitmap = New Bitmap(Me.PictDraw.Width,
> Me.PictDraw.Height)
> 20    Public PicDraw As Graphics = Graphics.FromImage(PictMap)
> --------------
>
> This looks very odd that the two properties will be initialized by each
> other which will definitly cause the NullReferenceException. I'd suggest
> please change the two lines to make one successful instantiation. Then you
> class should work as expected.
>
> Besides, we can temporarily remove the line
> "<System.Diagnostics.DebuggerNonUserCode()>" in the frmSweep constructor:
> '<System.Diagnostics.DebuggerNonUserCode()>
> Public Sub New()
>
> Then if we are debugging the application, we can step into the constructor
> of frmSweep.
>
> Please feel free to let me know if you have any further question on this
> issue.
>
> Have a nice day!
>
> Best Regards,
> Wei-Dong XU
> Microsoft Support
> ---------------------------------------------------------------------------
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> ---------------------------------------------------------------------------
> It is my pleasure to be of any assistance.
>
>
I knew the Graphics situation was going to bite me !
All of the Graphics examples I could find always started off with a
Button_Click and then used a Paint Event to do the work.

My data comes in through a USB connection and gets displayed on the screen
in real time like an oscilloscope. I have no Buttons to click. So I did some
guessing and needed to get to the FrmScreen form to debug it.

And of course it was a graphics error that kept me from loading frmSweep. I
will re-think what I am doing.

Thanks Wei-Dong XU for isolating the problem.

GalenS
Author
6 Mar 2006 6:12 AM
Wei-Dong XU [MSFT]
You are very welcome! :)

Enjoy a nice day!

Best Regards,
Wei-Dong XU
Microsoft Support
---------------------------------------------------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
---------------------------------------------------------------------------
It is my pleasure to be of any assistance.