-
October 6th, 2005, 02:26 PM
#1
Error trapping
Major NEWBBIE.....
I am trying to error trap for non-numeric values ("r", "?") in the following text boxes:
-Degrees_TextBox.Text
-Minutes_TextBox.Text
-Seconds_TextBox.Text
Also, I need to be sure...
values greater than 90 aren't entered in Degrees_TextBox.Text
values greater than 60 aren't entered in Minutes_TextBox.Text and Seconds_TextBox.Text
I considered making the three text boxes a control array, but can't manage to figure that out.
This is what I have done so far...it only addresses the non-numeric problem:
Private Sub Degrees_TextBox_Change()
If IsNumeric(Me.Degrees_TextBox.Text) Then
DisplayDegree = Me.Degrees_TextBox.Text
Else
MsgBox Me.Degrees_TextBox.Text & " Numeric Values Only", vbExclamation, "Warning"
Me.Degrees_TextBox.Text = ""
End If
End Sub
This code would be duplicated for each textbox.
It just seems to me I could possibly error trap all three boxes at once.
Also, when I hit OK on the msgbox I get another msgbox that says "Numeric Values Only"...it ignores the value in MsgBox Me.Degrees_TextBox.Text ...regardless why am I getting two message boxes.
Suggestions
-
October 6th, 2005, 03:39 PM
#2
Re: Error trapping
For each text box use this code in the keypress event:
Code:
'Only Allow Numbers
If KeyAscii = 13 Then
SendKeys "{Tab}"
Exit Sub
End If
If (KeyAscii < 48 And KeyAscii <> 8) Or KeyAscii > 57 Then
'We are not good
KeyAscii = 0
End If
It will only allow numbers and backspace, 'Enter' acts as Tab.
On Change Event or LostFocus event use something like this
Code:
If val(text1.text) > 90 then
msgbox "Can't have more than 90 degrees"
End If
You can change the 90 to 60 for each other textbox.
-
October 6th, 2005, 03:59 PM
#3
Re: Error trapping
Sabin,
Can you briefly explain what this means. How does this code look into the, for example, Degrees_TextBox text box and make sure it's a numeric value only? Is keypress event the same as click evenT?
I plugged in the second part of your suggestion and it worked perfectly.
Thanks.
For each text box use this code in the keypress event:
Code:
'Only Allow Numbers
If KeyAscii = 13 Then
SendKeys "{Tab}"
Exit Sub
End If
If (KeyAscii < 48 And KeyAscii <> 8) Or KeyAscii > 57 Then
'We are not good
KeyAscii = 0
End If
It will only allow numbers and backspace, 'Enter' acts as Tab.
-
October 6th, 2005, 04:07 PM
#4
Re: Error trapping
Well if your Degrees_Textbox is named Degrees then
Code:
Private Sub Degress_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys "{Tab}"
Exit Sub
End If
If (KeyAscii < 48 And KeyAscii <> 8) Or KeyAscii > 57 Then
'We are not good
KeyAscii = 0
End If
End Sub
All KeyAscii is a code that the computer interputs as each character hit. It is the Ascii value of each key. So by :
Code:
If KeyAscii = 13 Then
SendKeys "{Tab}"
Exit Sub
End If
Your saying if the key = 13 (which is the Enter Key) then do your next part of code.
And this :
Code:
If (KeyAscii < 48 And KeyAscii <> 8) Or KeyAscii > 57 Then
Is just trapping for numbers. The 'KeyAscii = 0' sends 0 instead of what the user hit if it is not a number.
-
October 6th, 2005, 04:36 PM
#5
Re: Error trapping
Originally Posted by Sabin_33
...
Code:
If KeyAscii = 13 Then
SendKeys "{Tab}"
Exit Sub
End If
Your saying if the key = 13 (which is the Enter Key) then do your next part of code.
This is a really good one Sabin I ever did it much more complicate!
To explain it a bit more You are sending 'Tab' after 'Enter' was done. So that will cause the Focus to leave the control and going to the next one which is following in the TabIndex order. Rhenny, You can choose the order in which Focus is given to different controls by setting 'TabIndex' in the properties of each control. Got it ?
Sabin_33. whats to send if you want to get Shift +Tab for moving backwards true the TabIndexList ?
Jonny Poet
Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
-
October 6th, 2005, 04:47 PM
#6
Re: Error trapping
Sabin,
Thanks for the code and explanation.
RH
-
October 6th, 2005, 04:47 PM
#7
Re: Error trapping
Going backwards and hit enter and go
' SendKeys "+{Tab}"'
Last edited by Sabin_33; October 7th, 2005 at 06:07 PM.
-
October 7th, 2005, 07:42 AM
#8
Re: Error trapping
Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
-
October 7th, 2005, 06:08 PM
#9
Re: Error trapping
I think you've helped me plenty on this forum so far johnny! Thanks
-
October 8th, 2005, 05:08 AM
#10
Re: Error trapping
Originally Posted by Sabin_33
I think you've helped me plenty on this forum so far johnny! Thanks
You are everytime welcome
Jonny Poet
Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
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
|