|
|||||||
| General Software Discussion Got a problem with an application? This is the place for all your software and tweaking questions. |
![]() |
|
|
Thread Tools |
|
|
#1 |
|
HardwareHeaven Lover
Join Date: Dec 2007
Posts: 227
Rep Power: 47 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() WHY when implementing the following code: Code:
Private Sub event_KeyDown(ByVal sender As Object, ByVal e_
As System.Windows.Forms.KeyEventArgs) Handles txtBox.KeyDown
If e.KeyValue = keys.enter Or keys.right Then
If String.IsNullOrEmpty(ActiveControl.Text) Then
MessageBox.Show("Please Enter Data", "Error",_
MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
'Next Textbox recieves focus
...
End If
End If
End Sub
![]() According to the rules - as I understand them - e.KeyValue is an INTEGER. I've replaced the aforementiond keys. values in the above logical expression with discrete integers and it still doesn't work. ![]() What I mean by doesn't work: if I take out one or the other of the logical expressions in the comparison, i.e. either .Enter or .Right (or the integer equivalent) the statement executes as expected. I'm dumbfounded how ~ input can evalute true in the above code (when its intent is to trap <enter> or <right> keys. This has got to be some sort of havengod (sp?) MS mystery pertaintent to KeyEventArgs and KeyPressEventArgs ![]() This is a real simple app I'm trying to create:
Last edited by WxMan1; Dec 21, 2012 at 02:22 AM. Reason: use spiffy new [code] tag & update thread title |
|
|
|
|
|
#2 |
|
Unus offa, unus iuguolo
|
Re: Vb .net vs2008
Nested IFs... Horrible stuff.
Off the top of my head, shouldn't it be something like this? Code:
if e.keyvalue = keys.enter or e.keyvalue = keys.right then
__________________
![]() I don't get paid to know the answer, therefore I'm far more likely to give you a straight and honest answer. |
|
|
|
|
|
|
|
HardwareHeaven Lover
Join Date: Dec 2007
Posts: 227
Rep Power: 47 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Vb .net vs2008
Good answer Mr. "Guru"
It sounds like the Guru is suggesting that a boolean expression needs to be evaluated with ticks (as per C++); I''d actually run into a serious syntax error with your solution. That notwithstanding, I appreciate your reply. The fact is: I've seen boolean expression evaluation issues akin to this in that past. But that atypically pertained to data-type; hence, my pointing out the data type of the vars being compared. Emprically, the following code works: Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e_
As System.EventArgs) Handles MyBase.Load
End Sub
' Boolean flag used to determine when a character other than a
' number is entered.
Private nonNumberEntered As Boolean = False
' Handle the KeyDown event to determine the type of character
' entered into the control.
Private Sub textBox1_KeyDown(ByVal sender As Object, ByVal e_
As System.Windows.Forms.KeyEventArgs) _
Handles TextBox1.KeyDown
' Initialize the flag to false.
nonNumberEntered = False
' Determine whether the keystroke is a non-keypad input number.
If e.KeyCode < Keys.D0 OrElse e.KeyCode > Keys.D9 Then
' Determine whether the keystroke is a number from the keypad.
If e.KeyCode < Keys.NumPad0 OrElse e.KeyCode > Keys.NumPad9 Then
' Determine whether the keystroke is a backspace.
If e.KeyCode <> Keys.Back Then
' A non-numerical keystroke was pressed.
' Set the flag to true and evaluate in KeyPress event.
nonNumberEntered = True
End If
End If
'If shift key was pressed, it's not a number.
If Control.ModifierKeys = Keys.Shift Then
nonNumberEntered = True
End If
End Sub 'textBox1_KeyDown
' This event occurs after the KeyDown event
'implement to prevent characters from entering the control.
Private Sub textBox1_KeyPress(ByVal sender As Object, ByVal e_
As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
' Check for the flag being set in the KeyDown event.
If nonNumberEntered = True Then
' handle non-numerical exception.
e.Handled = True
End If
End Sub 'textBox1_KeyPress
End Class
My best assessment as junior apprentice OOP IT Wizard - given the heriarchy of event handling w/in .NET - there MUST be a clash between event handlers w/in my code that I implremented (or perhaps overriden from the base class). It would appear that an 'eval' is going on at run-time between two objects as opposed to the comparision of ojbects of similar data-type. It is the latter that I had anticpated. That being said - nonetheless - I have concerns that this is some sort of MS security flaw. I'm going to attend to downloading the big MS patch that I've put off for ages (for VS2008). I'm going to dl 380MB for the patch/upgrade and when I can verify its integriy using the archive integrity checking tools inherent to WinRar & 7-Zip, and make the appropriate image and system back-ups: we'll check back here. Last edited by WxMan1; Dec 21, 2012 at 02:29 AM. Reason: Use spiffy new [code] tag |
|
|
|
|
|
|
|
HardwareHeaven Lover
Join Date: Dec 2007
Posts: 227
Rep Power: 47 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Vb .net vs2008
I must've been drunk when I made my OP, when I replied, or now.
![]() Takaharu's - kudo's to very guru lookin avatar BTW - IR was spot on. Too bad I was too drunk to realize it at the time. ![]() Thing is, weren't I not too drunk then, I'd not come to realize what I know now. ![]() Yesh, the whole issue of trapping input keys and mucking around with tabindex sequence set me onto a trail that led me to the peak of Z-list Mountain! ![]() Indeed, the following code-snipit will work: Code:
Private Sub txtBox_KeyPress(ByVal sender As Object, ByVal e_
As System.Windows.Forms.KeyPressEventArgs) Handles_
txtBox1.KeyPress, txtBox2.KeyPress, txtBox3.KeyPress, et ali...
If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
e.Handled = True
Me.ProcessTabKey(True)
End If
End Sub
The following code may be tastier, though: Code:
Private Sub txtBox_KeyDown(ByVal sender As Object, ByVal e_
As System.Windows.Forms.KeyEventArgs) Handles_
txtBox1.KeyDown, txtBox2.KeyDown, txtBox3.KeyDown, et ali...
If e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Down_
Or e.KeyCode = Keys.Up Then
Select Case e.KeyCode
Case Keys.Enter, Keys.Down
e.Handled = True
Me.ProcessTabKey(True)
Case Keys.Up
Dim i As Integer = 0
Do Until Me.ActiveControl.Name = Me.Controls(i).Name
i += 1
Loop
i -= 1
If i < 0 Then i = 2
Me.Controls(i).Focus()
End Select
End If
End Sub
You can muck around with the tab-index values for windows.form.controls.item(x) all you want, but if so, Vegas odds are in favor of you ending up driving that hot rod-Lincoln. ![]() Tab-index controls navigation through form.controls(x) objects through iterative press of TAB key. What when one desires to navigate backwards through the array of form.controls(x)? The crux of the prollem is that ALL form.objects whether 'focusable' - just invented a new word - or not, i.e., lables and buttons, what not, and et ali that may muck things up. ![]() If a coder wants to implement backwards keypress events-handling functionality, then the order of creation of objects onto a form is imperative; implementation of the code 'Case Keys.Up' in the above snipit will NEVER ever work as hoped for by the coder (or hapless users) ![]() If you have 5,973,462 'objects' on a form and a handfull of textbox inputs (or whatnot), and you want to step backwards through that form using keyboard navigation? Good luck! And good riddence say the structured object oriented programming Nazis.You could spend the next five lifetime heartbeats recreating the form with all of its 5,973,462 objects so that focus() can be applied to the proper form.object(x) at the appropriate time; only to discover that a single extra object needs to be shoehorned onto the form. ![]() Doing so will break the backwards navigation-connectivity. ![]() Never fear, Document Outline is here to the rescue. ![]() Yep, in design view one can arrange all the objects for which input keys should be captured in such order whereby setting focus is possible. You can establish the Z-list by creating a form with all its inherent objects from scratch, or manipulate the order of items on a form. ![]() One of the caveats: after cutting any one of the formName inputObject and pasting back, said object has lost any / all associated event handler-handles in the form code-page. ![]() Here's a Coder's Bible rule to implement: synch autotab index with the z-list. If you're implementing backwards navigation through form.inputobject(x), then one needs to come to terms with which is the most likely: adding extra lables and stuff or whatnot? Last edited by WxMan1; Dec 21, 2012 at 03:22 AM. Reason: forgot to mention what Z-list is |
|
|
|
|
|
#5 |
|
Unus offa, unus iuguolo
|
Re: Vb .net vs2008
The avatar is of Dr. Gerald Robotnik, a character from Sonic Adventure 2.
"... The greatest scientific mind... and my grandfather". Intelligent scientist who went mad when his granddaughter was killed as a result of his work and tried to blow up the planet. So, take that as you like. My post was off the top of my head at the time. I'm curious though, why, in the second snippet of the above post, do you use a case statement that already incorporates the role of the if statement?
__________________
![]() I don't get paid to know the answer, therefore I'm far more likely to give you a straight and honest answer. |
|
|
|
|
|
|
|
HardwareHeaven Lover
Join Date: Dec 2007
Posts: 227
Rep Power: 47 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Vb .net vs2008
Said in extremely thick accent nobody recognizes:
"Very cool veedbak consernink avatar. You tagline says fart. That very vunny. Vunny vunny is that. Is one' of the fart types: computnik? I do not want to be offensive but only serious on this board, so I die levity now." Lolz. "in the second snippet of [my] above post", you'll see that I trap the <Enter>, <down> & <up> arrow keys. Any other key inputs are ignored, i.e., get shoveled off to textbox_changed event handler subs. It has to do with trapping focus changing input, i.e., through utilizatoin of the Z-list, and the input itself (which doesn't change focus - and should be processed by textBox_text changed handler subs). arrow nav, including <Cr>+<Lf>, i.e., <Enter> and <Tab> keys function differently depending on the even_handler subs implemented. The aforementioned posts and stuff are days and days of my own heartbeats distilled for use by those interested. There may be relevancy to web-form design, no guarantee's are made ITR. The aforementioned should be used as 'model' and perverted to ones desire. |
|
|
|
![]() |
| Thread Tools | |
|
|