473,398 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Processing numeric keys (D0 - D9 and NumPad0 - NumPad9)

Hi,

Can somebody help me with this problem please.

I need to get the value, not just to check for it, of a number
pressed but it has to work for both, numbers above QUERTY and numbers
entered from numeric pad.

I know how to check for the keys (which I am doing in the code below).
What I need is the value (e.g if D2 or NumPad2 then ' 2') so I can
then select the number 2 in my combo box (represents months).

I have several combo boxes on the form, some of which are dealing with
Strings (e.g. names of countries) which I am processing just fine, and
the others dealing with numbers (e.g. months). I process these fine
as well but only for numbers above QUERTY. What I need is the way to
do it for numeric keypad, too.

Here is the code I am using so far:

Private Sub WcboMonth_KeyUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles WcboMonth.KeyUp

If ((e.KeyCode >= Keys.D1) And (e.KeyCode <= Keys.D9)) Then

// ^^^^^ THIS WORKS FINE ^^^^^^^

Dim strString As String = ChrW(e.KeyData)
Dim index As Integer = 0

Dim i As Integer = 0
For i = 0 To WcboMonth.Items.Count - 1
If (WcboMonth.Items(i).Text.Chars(0) = strString) Then
index = i
Exit For
End If
Next

WcboMonth.SelectedIndex = index
End If
If ((e.KeyCode >= Keys.NumPad1) And _
(e.KeyCode <= Keys.NumPad9)) Then

// ^^^^^THIS DOES NOT WORK ^^^^^^

// (it returns 'e' if NumPad5 clicked
Dim strString As String = ChrW(e.KeyData)
Dim index As Integer = 0

Dim i As Integer = 0
For i = 0 To WcboMonth.Items.Count - 1
If (WcboMonth.Items(i).Text.Chars(0) = _
strString) Then
index = i
Exit For
End If
Next

WcboMonth.SelectedIndex = index
End If
End Sub

Any help will be appreciated

thank you
_dino_

Nov 21 '05 #1
1 8216
I find the way how to do this. For those interested, I used wrong
event handler. I used KeyUp instead of using KeyPress (... I know,
one of these things ...)

Anyways, use KeyPress instead of KeyUp or so and then you have
e.KeyChar available which will return you the character pressed no
matter wehter you are using numeric pad, or numbers above QUERTY.

_dino_

On Thu, 03 Mar 2005 17:09:33 GMT, Dino Buljubasic
<di**@noplacelikehome.com> wrote:
Hi,

Can somebody help me with this problem please.

I need to get the value, not just to check for it, of a number
pressed but it has to work for both, numbers above QUERTY and numbers
entered from numeric pad.

I know how to check for the keys (which I am doing in the code below).
What I need is the value (e.g if D2 or NumPad2 then ' 2') so I can
then select the number 2 in my combo box (represents months).

I have several combo boxes on the form, some of which are dealing with
Strings (e.g. names of countries) which I am processing just fine, and
the others dealing with numbers (e.g. months). I process these fine
as well but only for numbers above QUERTY. What I need is the way to
do it for numeric keypad, too.

Here is the code I am using so far:

Private Sub WcboMonth_KeyUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles WcboMonth.KeyUp

If ((e.KeyCode >= Keys.D1) And (e.KeyCode <= Keys.D9)) Then

// ^^^^^ THIS WORKS FINE ^^^^^^^

Dim strString As String = ChrW(e.KeyData)
Dim index As Integer = 0

Dim i As Integer = 0
For i = 0 To WcboMonth.Items.Count - 1
If (WcboMonth.Items(i).Text.Chars(0) = strString) Then
index = i
Exit For
End If
Next

WcboMonth.SelectedIndex = index
End If
If ((e.KeyCode >= Keys.NumPad1) And _
(e.KeyCode <= Keys.NumPad9)) Then

// ^^^^^THIS DOES NOT WORK ^^^^^^

// (it returns 'e' if NumPad5 clicked
Dim strString As String = ChrW(e.KeyData)
Dim index As Integer = 0

Dim i As Integer = 0
For i = 0 To WcboMonth.Items.Count - 1
If (WcboMonth.Items(i).Text.Chars(0) = _
strString) Then
index = i
Exit For
End If
Next

WcboMonth.SelectedIndex = index
End If
End Sub

Any help will be appreciated

thank you
_dino_


Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tommo | last post by:
Hello All, I have a slight problem that goes like this. I have created a Perl hash where the keys are made up of numeric values, I was then sorting the 'keys' for this hash on their value (a<=>b...
3
by: James | last post by:
Hello group: I've done alot of reading on this subject somewhat and have found that many people have many different opinions on this subject. My question centers mainly around using a lookup...
5
by: soup_or_power | last post by:
Hi I have an associative array like this: arr=30; arr=20;arr=40;arr=10; I want the sort function to sort keys in ascending order of the values on the right hand side with the following result:...
5
by: ScareCrow | last post by:
How do I go about limiting a textbox to accepting numeric key input from the keyboard in vb.net? --------------= Posted using GrabIt =---------------- ------= Binary Usenet downloading...
2
by: nickdevx | last post by:
Hi Say if I have a mixed array: $array = array("item1", "2"=>"item2", "5", "item4key"=>"item4") Is it possible while looping through the array (foreach ($array as $key=>$val)) to check if...
11
by: John | last post by:
I am coding a radix sort in python and I think that Python's dictionary may be a choice for bucket. The only problem is that dictionary is a mapping without order. But I just found that if the...
0
by: EgoSum | last post by:
Can someone help me with custom text box? I want change behavior custom date text box - disallow entry and pass entry from numeric keyboard to a text box. Code below disallow entry, but how I can...
2
by: EgoSum | last post by:
Can someone help me with custom text box? I want change behavior custom date text box - disallow entry and pass entry from numeric keyboard to a text box. Code below disallow entry, but how I can...
2
by: prognoob | last post by:
how do they work? so i saw someone posting like... Create Table login (Id int(4) NOT NULL, UserName varchar(20) NOT NULL, Password varchar(6) NOT NULL, securityQuestion varchar(50) NOT...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.