473,398 Members | 2,427 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.

TextBox Digit & Decimal Limit

23
Hi, Does anyone know how to limit a textbox to digit and decimal entry?
I really need it.
Please help!
Jun 27 '06 #1
3 4339
Banfa
9,065 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1.     ' Set the numeric style for the TextBox
  2.     ' Get the current style
  3.     Dim style As Integer = _
  4.         GetWindowLong(TextBox.Handle, GWL_STYLE)
  5.  
  6.     ' Add ES_NUMBER to the style.
  7.     SetWindowLong(TextBox.Handle, GWL_STYLE, _
  8.         style Or ES_NUMBER)
  9.  
Does that make sence, means nothing to me I'm a C programmer (actually that's not true because GetWindowLong and SetWindowLong are part of the sdk so I do use them but I have to trust that the syntax is correct.
Jun 27 '06 #2
sashi
1,754 Expert 1GB
hi guys,

the most simplest method i ever used to;

accept numeric value..
Expand|Select|Wrap|Line Numbers
  1. Private Sub Text1_KeyPress(KeyAscii As Integer)
  2.     If Not IsNumeric(Chr(KeyAscii)) Then KeyAscii = 0
  3. End Sub
  4.  
accept decimal value in textbox
Expand|Select|Wrap|Line Numbers
  1. Function validateNumber(txtChk As TextBox, KeyAscii As Integer) As Boolean
  2.     validateNumber = False
  3.  
  4.  
  5.     If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 46 And KeyAscii <> 8 Then
  6.         KeyAscii = 0
  7.     ElseIf KeyAscii = 46 And InStr(1, txtChk.Text, ".") <> 0 Then
  8.         KeyAscii = 0
  9.     ElseIf KeyAscii >= 48 And KeyAscii <= 57 Then
  10.         lngDotPos = InStr(1, txtChk.Text, ".")
  11.  
  12.  
  13.         If lngDotPos <> 0 Then
  14.  
  15.  
  16.             If txtChk.SelStart >= lngDotPos Then
  17.                 txtChk.MaxLength = lngDotPos + 2
  18.             Else
  19.                 txtChk.MaxLength = 20
  20.             End If
  21.         End If
  22.         validateNumber = True
  23.     End If
  24. End Function
  25.  
Jun 28 '06 #3
str1ker
23
Thanks, I'll try these!
Jun 28 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Rookie | last post by:
I need to display several columns of numbers in a textbox. I wish to display the columns with the decimal point position aligned vertically. I have found that the # digit placeholders do not...
2
by: anonieko | last post by:
This applies to javascript dynamic textbox onkey > > > Newsgroups: comp.lang.javascript From: Lasse Reichstein Nielsen <l...@hotpop.com> - Find messages by this author Date: Fri, 15 Jul 2005...
1
by: KartTalk.com | last post by:
Hi there, I am very new to C# and the idea of OOP, however I do have some non-OOP PHP background. Anyway, here is the scenario -- I am writing a simple app to get my C# feet wet and it does...
2
by: RobRich | last post by:
I'm trying to figure out the best way to accomplish a task. I need to calculate the numerical values from about 300+ textboxes. Basiclly I have an application that users input checks and credit...
1
by: David Smith | last post by:
What I want to be able to do: A textbox is available that the user can enter information into. Specifically (for the purposes of this post), the user is asked to enter a number, and that number...
3
by: Ivan | last post by:
Hi, how to filter out non-digit chars when user writes text to System.Windows.Forms.TextBox? Thanks, Iavmn
7
by: Stefantastisk | last post by:
Hey there, Anyone knows a clever method for knowing the length of the digit after a decimal point in a standard C# decimal value, WITHOUT use of any string formatting. Example: 5231,12231 <-...
14
by: thehobbit | last post by:
Hi, Could anyone give ideas on how to add 4 20 digit numbers in ANSI C and pass the result back to a calling program in COBOL? We were able to add up to 15 digit numbers without any problems,...
2
by: Jcan | last post by:
HI I have a 10 digit ASCII array: char Arr = {'1','2','3','4','5','6','7','8','9','1'} I have to convert the the array to decimal. I do this by subtracting 0x30 and multiplying with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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...
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
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...
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,...

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.