PC Review


Reply
Thread Tools Rate Thread

cType error?

 
 
Dave
Guest
Posts: n/a
 
      18th Nov 2006
I'm using several routines in my program that work on properties in a
textbox. The KeyPress is one of them. They all work fine for all of the
textboxes listed in the Handles ... part of the sub shown below. Except for
one. I have one text box, txtAdd2, that ends up being passed to the subs as
'Nothing'. So when I try to reference the object in my subroutines I get the
following error:

"An unhandled exception of type 'System.NullReferenceException' occurred in
system.windows.forms.dll
Additional information: Object reference not set to an instance of an
object."

Here is the KeyPress event code. Stepping through the program the error
triggers on the Me.SelectNextControl line because the sender is 'Nothing'. I
get similar errors when sending a reference to txtAdd2 to other routines;

Private Sub Enter_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtAdd1.KeyPress,
txtAdd2.KeyPress, txtAdded.KeyPress, txtBDay.KeyPress, txtCity.KeyPress,
txtEMail.KeyPress, txtFName.KeyPress, txtHPhone.KeyPress,
txtJoined.KeyPress, txtLName.KeyPress, txtMPhone.KeyPress,
txtState.KeyPress, txtStatus.KeyPress, txtWeb.KeyPress, txtWPhone.KeyPress,
txtZip.KeyPress

If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
Me.SelectNextControl(cType(sender, TextBox), True, True, False,
True)
End If

End Sub

Any help would be appreciated.

Thanks,
Dave



 
Reply With Quote
 
 
 
 
Linda Liu [MSFT]
Guest
Posts: n/a
 
      20th Nov 2006
Hi Dave,

Based on my understanding, you are trying to navigate through the textbox
controls on your form by hitting Enter continuously. It works fine on all
textbox except one textbox, i.e. txtAdd2. When the txtAdd2 gets focused and
you press Enter, an exception of type 'System.NullReferenceException'
occurs. The txtAdd2 passes Nothing to the KeyPress event handler.

If I have any misunderstanding, please feel free to correct me.

I have performed a test based on your description, but I couldn't reproduce
the problem. I have a try setting the TabStop property one textbox on my
form to False. When the program is run and I hit Enter continuously, all
the TextBox except the one whose TabStop property is set to False get
focused in order. There's no any problem.

Is the 'txtAdd2' of type TextBox? Do you have any special process on
txtAdd2? If possible, could you please send me your sample project that
could just reproduce the problem? To get my actual email address, remove
'online' from my displayed email address.

I look forward to your reply.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ctype error in Load control AlecL Microsoft ASP .NET 4 1st Feb 2007 04:37 PM
CType? Arpan Microsoft ASP .NET 3 11th Aug 2006 03:09 PM
Help- LoadControl and Ctype error Justin Dutoit Microsoft ASP .NET 1 23rd Feb 2006 02:58 PM
CType Todd Plambeck Microsoft VB .NET 4 10th Jul 2005 04:15 AM
CType if I *know* that its the same? Fredrik Melin Microsoft VB .NET 4 29th Jan 2004 02:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:56 AM.