|
-
May 16th, 2004, 07:51 PM
#1
Thread Starter
PowerPoster
[Resolved]Object Instance Error
VB Code:
'from the AlphaNumericButton usercontrol
Public Function getChr() As String
If IsAlphabetic = False Then
getChr = strDigitValue
Else
If keyPadTimer.Enabled = True Then
'supposed to be working with this bit
Dim tmpArray() As String
Dim i As Integer
For i = 0 To Len(strAlphaValue)
tmpArray(i) = strAlphaValue.Substring(i, 1)
Next
For i = 0 To tmpArray.Length
MsgBox(tmpArray(i))
Next
getChr = ""
'end this bit
Else
If strAlphaValue.Length > 0 Then
getChr = strAlphaValue.Substring(0, 1)
Else
getChr = " "
End If
End If
End If
End Function
Private Sub btnKey2to9Handler(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKey2.Click, btnKey3.Click
If armed = True Or expectingInput = True Then
Static KeyValue As String
MsgBox(sender.name)
If Not lastKeyPressed Is sender Then
AlphaNumericButton.keyPadTimer.Enabled = False
End If
lastKeyPressed = sender
If AlphaNumericButton.IsAlphabetic = False Then
KeyValue = sender.Getchr
Else
'Working with this part
If Not AlphaNumericButton.keyPadTimer.Enabled Then
KeyValue = sender.Getchr
AlphaNumericButton.keyPadTimer.Enabled = True
Else
'Delete the last alpha character.
If inputBuffer.Length > 0 Then
inputBuffer = inputBuffer.Substring(0, inputBuffer.Length - 1)
End If
'Determine the next alpha character.
'Errors here if I click within one second
MsgBox(sender.Getchr)
End If
End If
End If
End Sub
Howdy folks.
My little usercontrol has a problem (), it completely crashes when I try to use sender.GetChr.(the Getchr function will recieve and return values when its finished) Basically I have a sub which handles the click events for 10 AlphaNumericButton controls (top code is from that), and they have to retrieve a value using the Getchr function. Theres a timer which is shared across all of the usercontrols called keypadtimer (which is inside the control) which is set for 1 second. So the first time I click, the timer not enabled part fires and works properly. If I wait longer than 1 second, it'll work fine again... but if I click before 1 second has elapsed, I get the following error on the Msgbox part,
An unhandled exception of type 'System.NullReferenceException' occurred in microsoft.visualbasic.dll
Additional information: Object reference not set to an instance of an object.
Anyone?
Last edited by Pc_Madness; May 17th, 2004 at 05:12 AM.
Don't Rate my posts.
-
May 17th, 2004, 12:07 AM
#2
It sounds like sender or something else is not set to anything. You should test if sender is Nothing before trying to use it. It's also a good idea to cast it to a strong type instead of using the generic object type especially since object doesn't have a name property. Depending on what it is it may not have a GetChr method either.
-
May 17th, 2004, 04:22 AM
#3
Retired VBF Adm1nistrator
Use the Debug "Solution Configuration" and then run it from the IDE. What line do you get the error on?
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
May 17th, 2004, 04:37 AM
#4
Thread Starter
PowerPoster
Originally posted by Edneeis
It sounds like sender or something else is not set to anything. You should test if sender is Nothing before trying to use it. It's also a good idea to cast it to a strong type instead of using the generic object type especially since object doesn't have a name property. Depending on what it is it may not have a GetChr method either.
Well, I tried to do If sender <> Nothing Then and it had a spaz about that, but after it highlighted the error, sender wasn't empty, and since that part of the code will only occur when the error posted above would occur, I think we can assume that it isn't empty.
And Jamie, the error is on the Msgbox (the second one) line in the btnKey2to9Handler sub.
-
May 17th, 2004, 04:42 AM
#5
Retired VBF Adm1nistrator
Try this :
VB Code:
Private Sub btnKey2to9Handler(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKey2.Click, btnKey3.Click
[b] MsgBox(sender Is Nothing)[/b]
If armed = True Or expectingInput = True Then
Static KeyValue As String
If Not lastKeyPressed Is sender Then
AlphaNumericButton.keyPadTimer.Enabled = False
End If
lastKeyPressed = sender
If AlphaNumericButton.IsAlphabetic = False Then
KeyValue = sender.Getchr
Else
'Working with this part
If Not AlphaNumericButton.keyPadTimer.Enabled Then
KeyValue = sender.Getchr
AlphaNumericButton.keyPadTimer.Enabled = True
Else
'Delete the last alpha character.
If inputBuffer.Length > 0 Then
inputBuffer = inputBuffer.Substring(0, inputBuffer.Length - 1)
End If
'Determine the next alpha character.
'Errors here if I click within one second
[b] MsgBox(sender Is Nothing)[/b]
MsgBox(sender.Getchr)
End If
End If
End If
End Sub
If it says false, then the problem might lie in an unhandled exception in the Getchr() method.
I have never used UserControls, but there is the possibility that unhandled exceptions in UserControls are passed up through the call stack - instead of VB catching and showing you the error there.
Try using MsgBox() statements in the Getchr() method to track its progress...
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
May 17th, 2004, 04:48 AM
#6
Thread Starter
PowerPoster
The Msgbox's return false, and it seems it hates the two loops inside the GetChr() function.
-
May 17th, 2004, 05:13 AM
#7
Thread Starter
PowerPoster
-
May 17th, 2004, 05:16 AM
#8
Retired VBF Adm1nistrator
Let me guess - you never ReDimmed your tmpArray array ?
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
May 17th, 2004, 05:19 AM
#9
Thread Starter
PowerPoster
Well, that and you can't use substring(0, 1), but I've cheated and just set it to array to 4 items and use mid instead due to substring's oddity (even when I did i + 1 )
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|