|
-
Jun 15th, 2004, 08:25 PM
#1
Thread Starter
Junior Member
Why won't this work?
OK - why won't this code enter a "T", an "F", or anything else in the listbox "lstViewScore"?
Private Sub lstViewScore_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs)
If e.KeyCode.Left Then
lstViewScore.Items.Add("T")
ElseIf e.KeyCode.Right Then
lstViewScore.Items.Add("F")
ElseIf e.KeyCode.Down Then
lstViewScore.Items.Add("Missing Item")
End If
End Sub
Ian
-
Jun 15th, 2004, 08:32 PM
#2
yay gay
Notice how you aren't doing what you want. You are saying "If KeyT" but you aren't refering what you really want to do with KeyT. You have to compare it. "If key pressed key is KeyT".
Private Sub lstViewScore_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs)
Use the e.KeyData or KeyCode
\m/  \m/
-
Jun 16th, 2004, 03:23 PM
#3
Thread Starter
Junior Member
Is this what you meant?
I tried it this way with KeyCode, Keydata, and KeyValue, but it still doesn't work. Is this what you meant?
Public Sub lstViewScore_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs)
If e.KeyValue = Keys.Left Then
lstViewScore.Items.Add("T")
ElseIf e.KeyValue = Keys.Right Then
lstViewScore.Items.Add("F")
ElseIf e.KeyValue = Keys.Space Then
lstViewScore.Items.Add("Missing Item")
End If
End Sub
Ian
-
Jun 16th, 2004, 04:03 PM
#4
PowerPoster
Re: Is this what you meant?
Originally posted by Ian McKenzie
I tried it this way with KeyCode, Keydata, and KeyValue, but it still doesn't work. Is this what you meant?
Public Sub lstViewScore_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs)
If e.KeyValue = Keys.Left Then
lstViewScore.Items.Add("T")
ElseIf e.KeyValue = Keys.Right Then
lstViewScore.Items.Add("F")
ElseIf e.KeyValue = Keys.Space Then
lstViewScore.Items.Add("Missing Item")
End If
End Sub
Ian
I tried the above code and it DOES add "T" or "F" or "Missing Item" on each appropriate key press, provided the LstViewScore has focus. Can't see the point of it though
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jun 16th, 2004, 04:11 PM
#5
Frenzied Member
Doesn't it need a Handles statement....e.g.
Private Sub lstViewScore_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lstViewScore.KeyDown
If e.KeyCode.Left Then
lstViewScore.Items.Add("T")
ElseIf e.KeyCode.Right Then
lstViewScore.Items.Add("F")
ElseIf e.KeyCode.Down Then
lstViewScore.Items.Add("Missing Item")
End If
End Sub
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
Jun 16th, 2004, 04:51 PM
#6
Thread Starter
Junior Member
Still a "no-go".
Yup, the control has the focus, but it still isn't working. I tried the "handles" suggestion too. I must have made another mistake somewhere else. Would you mind looking at the code (I hate to sound even more thick by asking how to attach it)?
If I can get the darned thing to work, I'll nest it in a loop with an array. When it's finished, it'll be a utility that will score a T/F test. I'm a psychologist and am often crunching test data. The first form will be for demographic info, and then the scorer will enter data in the lstViewScore form.
Hey - thanks for your help.
Ian
-
Jun 16th, 2004, 06:21 PM
#7
Thread Starter
Junior Member
Thanks guys!!!
You were both right - it needed both the "handles" line (which I don't know a damned thing about), and the e.KeysValue = e.keys.left issue.
It works now. I'll just stumble along to my next errors now.
:^)
Thanks guys!
Ian
-
Jun 16th, 2004, 06:25 PM
#8
PowerPoster
Hi,
Sorry, I forgot to mention adding the handle (which I did in my test). All I can say is the code works as posted. It may be that the additions are just not in view. Have you tried using the scroll bars of the lstViewScore box to see if anything is there?
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jun 16th, 2004, 07:13 PM
#9
Thread Starter
Junior Member
Yup, it works!
Yup, it works - I'm looking forward to the time when I'll understand this language better. Each programming step is a challenge right now.
Ian
-
Jun 17th, 2004, 05:12 AM
#10
PowerPoster
Re: Thanks guys!!!
Originally posted by Ian McKenzie
You were both right - it needed both the "handles" line (which I don't know a damned thing about), and the e.KeysValue = e.keys.left issue.
Hi,
When you add an event handler ( i.e. Button_Click) don't try to type it in from the keyboard. In the code view of the form there are two dropdown panels just above the code. Click the drop down arrow of the left one and select the control then click the drop down arrow of the right one and select the event you require. This way, VB.NET puts in all the correct wording.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jun 17th, 2004, 07:10 AM
#11
Frenzied Member
The "handles" tells the event (lstviewscore_KeyDown, here) what action it responds to. Normally this is the KeyDown event for this example, and using Taxes post above is the usual way.
You can change it to handle a different event, providing that action has the same arguments (ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs). But more commonly, you might want one event handler to handle more than one control.
Say you had three listboxes, but wanted the same behavior for the keydown event on all of them. In that case, rather than coding three separate event handlers with the same code (which is ok), you could add to the handles statement like:
VB Code:
Handles lstViewScore.KeyDown, lstviewTotal.KeyDown, lstviewAvg.KeyDown
There's also delegates, which are related, but I don't think you want to get into that right now
-
Jun 17th, 2004, 06:06 PM
#12
Thread Starter
Junior Member
Wonderful!
That's wonderful - thanks! My program is slowly starting to take shape.
It'll be great once I have a feel for what I'm doing!
Ian
-
Jun 17th, 2004, 08:19 PM
#13
Frenzied Member
One thing I like is the continual learning curve. I can write an adequate program that does the job, and learn new stuff as I do so. Then I learn better, more efficient ways to do it. That's a cool feeling. Always learning.
I use several different languages at work, most but not all VB variants, and a lot of legacy code. It's neat when I can take maybe 20+ lines of existing code and distill them into 3 or 4 lines.
Keep on truckin', Ian. Programming may not be your main work, but it's cool intellectually. Kind of a cross between art and puzzle solving.
-
Jun 18th, 2004, 03:56 PM
#14
Thread Starter
Junior Member
Programming
I know what you mean. I've been working hard at VB for quite some time, but I'm missing that part of the brain that puts it all together. Pretty soon I'll be able to write something useful, and then my learning curve will be more rewarding. I can hardly wait!
Ian
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
|