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 with the numeric characters,
but I am using this to identify how many chars are after the ".", but it's
not working:
Dim pos As Integer
pos = InStr(1, ratevar1.Text, ".")
If pos <> 0 And ratevar1.Text.Length - pos = 2 Then
SendKeys.Send("{BACKSPACE}")
Exit Sub
End If
This hangs up and continually calls the keypress event. How can I simply
identify that the decimal point has 2 chars behind it and exit the sub
gracefully?
Thanks for any help.
Bernie Yaeger 9 1361
Change to > 2 rather than = 2 then it will work
If pos <> 0 And TextBox1.Text.Length - pos > 2 Then
"Bernie Yaeger" <be*****@cherwellinc.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... 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 with the numeric
characters, but I am using this to identify how many chars are after the ".", but it's not working:
Dim pos As Integer
pos = InStr(1, ratevar1.Text, ".")
If pos <> 0 And ratevar1.Text.Length - pos = 2 Then
SendKeys.Send("{BACKSPACE}")
Exit Sub
End If
This hangs up and continually calls the keypress event. How can I simply identify that the decimal point has 2 chars behind it and exit the sub gracefully?
Thanks for any help.
Bernie Yaeger
Hi Bernie,
Very Quick and dirty
if strField.indexof(".") <> -1 then
if strField.lastindexof(".") = strField.indexof(.) then
correct
else
error
end if
end if
Try it, I think it works.
Cor 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 with the numeric
characters, but I am using this to identify how many chars are after the ".", but it's not working:
Dim pos As Integer
pos = InStr(1, ratevar1.Text, ".")
If pos <> 0 And ratevar1.Text.Length - pos = 2 Then
SendKeys.Send("{BACKSPACE}")
Exit Sub
End If
This hangs up and continually calls the keypress event. How can I simply identify that the decimal point has 2 chars behind it and exit the sub gracefully?
Thanks for any help.
Bernie Yaeger
Put this into your keypress event. This is better than printing a char and
then sending a backspace to the textbox to remove it.
Dim pos As Integer
pos = InStr(1, TextBox1.Text, ".")
If pos > 0 And e.KeyChar = "." Then
e.Handled = True
ElseIf pos > 0 And TextBox1.Text.Length - pos = 2 Then
If e.KeyChar <> ControlChars.Back Then e.Handled = True
End If
"Brian" <no****@prairie.lakes.com> wrote in message
news:vu************@corp.supernews.com... Change to > 2 rather than = 2 then it will work
If pos <> 0 And TextBox1.Text.Length - pos > 2 Then "Bernie Yaeger" <be*****@cherwellinc.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl... 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 with the numeric characters, but I am using this to identify how many chars are after the ".", but
it's not working:
Dim pos As Integer
pos = InStr(1, ratevar1.Text, ".")
If pos <> 0 And ratevar1.Text.Length - pos = 2 Then
SendKeys.Send("{BACKSPACE}")
Exit Sub
End If
This hangs up and continually calls the keypress event. How can I
simply identify that the decimal point has 2 chars behind it and exit the sub gracefully?
Thanks for any help.
Bernie Yaeger
Hi Bernie,
Looking it over and then of course in the key event as Brian also said.
That first test is even not necessary because
-1 = -1 is also correct if strField.lastindexof(".") = strField.indexof(.) then correct else error end if
Cor
Hi Brian,
Tx for your response. I actually have been working on this in the interim
and came up with the same realization re backspace and e.handled.
Tx again,
Bernie
"Brian" <no****@prairie.lakes.com> wrote in message
news:vu************@corp.supernews.com... Put this into your keypress event. This is better than printing a char and then sending a backspace to the textbox to remove it.
Dim pos As Integer
pos = InStr(1, TextBox1.Text, ".")
If pos > 0 And e.KeyChar = "." Then e.Handled = True ElseIf pos > 0 And TextBox1.Text.Length - pos = 2 Then If e.KeyChar <> ControlChars.Back Then e.Handled = True End If
"Brian" <no****@prairie.lakes.com> wrote in message news:vu************@corp.supernews.com... Change to > 2 rather than = 2 then it will work
If pos <> 0 And TextBox1.Text.Length - pos > 2 Then "Bernie Yaeger" <be*****@cherwellinc.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl... 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 with the numeric characters, but I am using this to identify how many chars are after the ".", but it's not working:
Dim pos As Integer
pos = InStr(1, ratevar1.Text, ".")
If pos <> 0 And ratevar1.Text.Length - pos = 2 Then
SendKeys.Send("{BACKSPACE}")
Exit Sub
End If
This hangs up and continually calls the keypress event. How can I simply identify that the decimal point has 2 chars behind it and exit the sub gracefully?
Thanks for any help.
Bernie Yaeger
Hi Cor,
Tx for your response. I came up with a way to handle this by placing this
in the textchanged event:
Dim pos, x As Integer
pos = InStr(1, ratevar1.Text, ".")
x = ratevar1.Text.Length - pos
If pos <> 0 And x > 2 Then
ratevar1.Text = Math.Round(CDec(ratevar1.Text) - 0.005, 2)
Exit Sub
End If
Tx again,
Bernie
"Cor" <no*@non.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl... Hi Bernie,
Very Quick and dirty
if strField.indexof(".") <> -1 then if strField.lastindexof(".") = strField.indexof(.) then correct else error end if end if
Try it, I think it works.
Cor
>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 with the numeric characters, but I am using this to identify how many chars are after the ".", but
it's not working:
Dim pos As Integer
pos = InStr(1, ratevar1.Text, ".")
If pos <> 0 And ratevar1.Text.Length - pos = 2 Then
SendKeys.Send("{BACKSPACE}")
Exit Sub
End If
This hangs up and continually calls the keypress event. How can I
simply identify that the decimal point has 2 chars behind it and exit the sub gracefully?
Thanks for any help.
Bernie Yaeger
* "Cor" <no*@non.com> scripsit: if strField.lastindexof(".") = strField.indexof(.) then
^^^
;-)
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
* "Bernie Yaeger" <be*****@cherwellinc.com> scripsit: 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 with the numeric characters, but I am using this to identify how many chars are after the ".", but it's not working:
Very "user friendly": In German, we use "," as a decimal point.
Globalization is important...
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Hi Herfried,
I knew there was an error in the indexof(.}
I said it was very quick and dirty, I saw it in the first and forgot to
correct it even in the second, but what is the other error?
Cor if strField.lastindexof(".") = strField.indexof(.) then ^^^
;-)
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Chris Tilley - HPC:Factor |
last post by:
Hi,
I'm utterly confounded by this one. There must be some sort of rule that
I don't know of. I'd consider myself a Newbie+1, so be gentle.
I have a database connection (working A-Ok) and a...
|
by: Phil Powell |
last post by:
if (document.location.href.indexOf('?') >= 0) document.location.href
= document.location.href.substring(0,
document.location.href.indexOf('?'));
if (document.location.href.indexOf('#') >= 0) {...
|
by: Roland |
last post by:
Hello,
the example code is the following(the number in parentheses at the
beginning are just for reference)(The complete HTML file is at the end
of this article):
(1)window.location =...
|
by: Lyn |
last post by:
I am trying to get my head around the concept of default, special or empty
values that appear in Access VBA, depending on data type. The Access Help
is not much (help), and the manual that I have...
|
by: shearichard |
last post by:
Hi - I have written some python to insert a row into a table using
MySQLDB. I have never before written SQL/Python using embedded
parameters in the SQL and I'm having some difficulties. Could...
|
by: fredo |
last post by:
This question was asked in comp.lang.javascript with no result.
In IE5.x and IE6, I want to display an image when the user rolls over a
text link. The image does indeed display, but only on the...
|
by: =?Utf-8?B?cmFuZHkxMjAw?= |
last post by:
I have the following:
String.Format("{0}", myNumber);
What is {0} called? The reason I ask is that I want to look up how present
myNumber as 2 digits in the string. For example, if myNumber is...
|
by: Dave griffiths |
last post by:
Hi all
Using VB2005 on Vista with a Norwegian locale setup.
The test program has 3 textboxes the sum held in txt3.
Using the code below, txt2 conversion causes an error when it is left
empty....
|
by: tdickerson |
last post by:
Hi,
I'm encountering a strange error after an upgrade has been run on a test site. Attempting to SELECT * FROM table
or even just entering SELECT *
(no table specified) returns the following...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |