473,326 Members | 2,061 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,326 software developers and data experts.

trapping the location of a keypress inside the existing string in a custom textbox

I'm building a custom textbox for numbers only (actually two of them - one
for integers and one that allows currency entries, but let's discuss the
integer only control). I'm having a problem knowing where in the current
string the user is trying to enter '-' (ascii 45). I have been able to
ensure it can't be entered twice, but I currenty only allow it at all when
the string length is zero. However, if the user enters '345' and now wants
to change it to '-345' I don't allow it, because I don't know how to
determine if the entry is 34-5 or 3-45 or 345- or -345. In what event and
in what manner can I solve this?

Thanks for any help.

Bernie Yaeger
Nov 20 '05 #1
4 1145
You should be able to use textbox1.selectionstart to figure out where the
cursor is when the user hits a key...

Josh Moody
VSU Team

--

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
--------------------
From: "Bernie Yaeger" <be*****@cherwellinc.com>
Subject: trapping the location of a keypress inside the existing string in a custom textboxDate: Fri, 9 Jan 2004 16:04:43 -0500
Lines: 15
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <u2**************@tk2msftngp13.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: ool-18b80c4e.dyn.optonline.net 24.184.12.78
Path: cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!cpmsftng xa09.phx.gbl!TK2MSFTNGP08.
phx.gbl!tk2msftngp13.phx.gblXref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.languages.vb:171628
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

I'm building a custom textbox for numbers only (actually two of them - one
for integers and one that allows currency entries, but let's discuss the
integer only control). I'm having a problem knowing where in the current
string the user is trying to enter '-' (ascii 45). I have been able to
ensure it can't be entered twice, but I currenty only allow it at all when
the string length is zero. However, if the user enters '345' and now wants
to change it to '-345' I don't allow it, because I don't know how to
determine if the entry is 34-5 or 3-45 or 345- or -345. In what event and
in what manner can I solve this?

Thanks for any help.

Bernie Yaeger


Nov 20 '05 #2
Bernie:

What about a Regex on key down, or simply trapping what's being pressed.
Combine the Ascii representation and append it to the current text. If that
new value will make it not be a number any more, than just eat the keypress.
With a regex (a really simple one would be \d*) you could do some pretty
complex validation.

HTH

Bill
"Bernie Yaeger" <be*****@cherwellinc.com> wrote in message
news:u2**************@tk2msftngp13.phx.gbl...
I'm building a custom textbox for numbers only (actually two of them - one
for integers and one that allows currency entries, but let's discuss the
integer only control). I'm having a problem knowing where in the current
string the user is trying to enter '-' (ascii 45). I have been able to
ensure it can't be entered twice, but I currenty only allow it at all when
the string length is zero. However, if the user enters '345' and now wants to change it to '-345' I don't allow it, because I don't know how to
determine if the entry is 34-5 or 3-45 or 345- or -345. In what event and
in what manner can I solve this?

Thanks for any help.

Bernie Yaeger

Nov 20 '05 #3
Hi BIll,

Both your idea and Josh's worked fine - tx!

Bernie

"William Ryan" <do********@nospam.comcast.net> wrote in message
news:er**************@TK2MSFTNGP12.phx.gbl...
Bernie:

What about a Regex on key down, or simply trapping what's being pressed.
Combine the Ascii representation and append it to the current text. If that new value will make it not be a number any more, than just eat the keypress. With a regex (a really simple one would be \d*) you could do some pretty
complex validation.

HTH

Bill
"Bernie Yaeger" <be*****@cherwellinc.com> wrote in message
news:u2**************@tk2msftngp13.phx.gbl...
I'm building a custom textbox for numbers only (actually two of them - one for integers and one that allows currency entries, but let's discuss the
integer only control). I'm having a problem knowing where in the current string the user is trying to enter '-' (ascii 45). I have been able to
ensure it can't be entered twice, but I currenty only allow it at all when the string length is zero. However, if the user enters '345' and now

wants
to change it to '-345' I don't allow it, because I don't know how to
determine if the entry is 34-5 or 3-45 or 345- or -345. In what event and in what manner can I solve this?

Thanks for any help.

Bernie Yaeger


Nov 20 '05 #4
Hi Josh,

Both your idea and Bill Ryan's worked fine - tx!

Bernie

"Josh Moody [MSFT]" <Jo********@online.microsoft.com> wrote in message
news:bI**************@cpmsftngxa07.phx.gbl...
You should be able to use textbox1.selectionstart to figure out where the
cursor is when the user hits a key...

Josh Moody
VSU Team

--

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
--------------------
From: "Bernie Yaeger" <be*****@cherwellinc.com>
Subject: trapping the location of a keypress inside the existing string in
a custom textbox
Date: Fri, 9 Jan 2004 16:04:43 -0500
Lines: 15
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <u2**************@tk2msftngp13.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: ool-18b80c4e.dyn.optonline.net 24.184.12.78
Path:

cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!cpmsftng xa09.phx.gbl!TK2MSFTNGP08. phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.languages.vb:171628
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

I'm building a custom textbox for numbers only (actually two of them -

onefor integers and one that allows currency entries, but let's discuss the
integer only control). I'm having a problem knowing where in the current
string the user is trying to enter '-' (ascii 45). I have been able to
ensure it can't be entered twice, but I currenty only allow it at all whenthe string length is zero. However, if the user enters '345' and now wantsto change it to '-345' I don't allow it, because I don't know how to
determine if the entry is 34-5 or 3-45 or 345- or -345. In what event andin what manner can I solve this?

Thanks for any help.

Bernie Yaeger

Nov 20 '05 #5

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

Similar topics

13
by: David Gray | last post by:
Greetings all, Quick newbie type question: I would like to be able to trap non-numerical data entered into a textbox via CTRL+C and/or Shift+Insert. I realise that this data can be...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
0
by: Wiktor Zychla | last post by:
in my application I sometimes use KeyPress event. in the event handler I have to check the char the user is trying to type. in NTs everything is correct. however on W98 I've noticed that the...
3
by: Darryn Ross | last post by:
Hi, I am trying to catch the KeyPress event on my datagrid but it isn't working... i have also tried registering the handler with the event like this... dgGLBatch.KeyPress += new...
0
by: Steph. | last post by:
Hi, I have made a new custom TextBox control to enable ENTER and TAB keys to be trapped in the "KeyPress" and "KeyDown" Events. to do that I have overridden the "IsInputKey" property in my...
9
by: Bernie Yaeger | last post by:
I'm trying to control the textbox keypress event to deal with a "." such that it disallows a second "." and no characters after 2 numbers beyond the "." (thus a currency value). I have no problem...
2
by: Peter Osawa | last post by:
Hi, I'm making a form with a statusbar. I added a custom control to statusbar (That control has only a textbox). I set KeyPreview to True on the form. Now I can monitor all keys pressed, but...
7
by: Andy B | last post by:
I have a class I am creating for data access. I need to access controls from inside the class that are on a particular page. How do I do this? or is creating an instance of the page class and using...
2
by: Jason Huang | last post by:
Hi, How do I override a TextBox's KeyPress evnt? And how do we use it? Thanks for help. Jason
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.