473,698 Members | 2,271 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.KeyEventA rgs) _
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.Item s(i).Text.Chars (0) = strString) Then
index = i
Exit For
End If
Next

WcboMonth.Selec tedIndex = 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.Item s(i).Text.Chars (0) = _
strString) Then
index = i
Exit For
End If
Next

WcboMonth.Selec tedIndex = index
End If
End Sub

Any help will be appreciated

thank you
_dino_

Nov 21 '05 #1
1 8263
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**@noplaceli kehome.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.KeyEventA rgs) _
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.Item s(i).Text.Chars (0) = strString) Then
index = i
Exit For
End If
Next

WcboMonth.Selec tedIndex = 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.Item s(i).Text.Chars (0) = _
strString) Then
index = i
Exit For
End If
Next

WcboMonth.Selec tedIndex = 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
5520
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 etc), all was well until I got 2 keys with the same value, I seem to loose one of the hash entries. Is there a way around this problem .. cheers, Mark ..
3
3215
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 table to enable users to select a pre-defined list of values. I have developed a practice myself of avoiding AutoNumber type data fields for primary keys where the primary key will be related to a child table. Nevertheless, what do most users do...
5
37703
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: x4,x2,x1,x3 Can anyone please help me write the function? Thank you
5
4083
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 made easy =--------- -= Get GrabIt for free from http://www.shemes.com/ =-
2
1363
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 an item has an explicit key specified instead of its automatically assigned position key?
11
11405
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 keys are numeric, the keys themselves are ordered in the dictionary. part of my code is like this: radix={} for i in range(256):
0
1252
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 pass entry? public class myDateTextBox : AMS.TextBox.DateTextBox { protected override bool ProcessDialogKey(Keys keyData) {if (keyData >= Keys.NumPad0 && keyData <= Keys.NumPad9) {base.ProcessDialogKey(keyData); return true;
2
1895
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 pass entry? public class myDateTextBox : AMS.TextBox.DateTextBox { protected override bool ProcessDialogKey(Keys keyData) {if (keyData >= Keys.NumPad0 && keyData <= Keys.NumPad9) { return true;
2
1685
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 NULL, SecurityAnswer varchar(50) NOT NULL, Primary key (Id));
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9028
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8895
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7728
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.