473,395 Members | 1,846 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,395 software developers and data experts.

how to use validation in visual basic

14
i want to know how to do validation in visual basic.means how to avoid entering numbers in textbox where we need only characters and also opposite means how to avoid characters where we only need numeric

plz reply me soon..
thanks in advance .
i m waiting 4 ur reply
Jul 30 '07 #1
5 1959
bartonc
6,596 Expert 4TB
Sorry, I inadvertently moved one of your posts to the Misc. Q.s Forum from Member Introductions.
My mistake, but could be avoided it you post in the relevant forum.

Hope you are finding your way around the site by now.
Jul 30 '07 #2
Killer42
8,435 Expert 8TB
i want to know how to do validation in visual basic.means how to avoid entering numbers in textbox where we need only characters and also opposite means how to avoid characters where we only need numeric
Three techniques initially come to mind...
  • In the KeyPress, KeyDown or Change event, discard unwanted characters.
  • Use a masked edit control instead of a textbox. The masked edit control lets you specify the format that it will accept form the user.
  • Just check the value when the user leaves the textbox. You can do this in the LostFocus event, but the Validate event is probably more appropriate.
Note, all of this relates to VB6. You didn't say what version you're using, but if it's a later version the details may vary, though the general idea would be the same.
Jul 31 '07 #3
anianu
14
i want to know how to do validation in visual basic.means how to avoid entering numbers in textbox where we need only characters and also opposite means how to avoid characters where we only need numeric

plz reply me soon..
thanks in advance .
i m waiting 4 ur reply








Sorry, I inadvertently moved one of your posts to the Misc. Q.s Forum from Member Introductions.
My mistake, but could be avoided it you post in the relevant forum.

Hope you are finding your way around the site by now.
Aug 2 '07 #4
hariharanmca
1,977 1GB
i want to know how to do validation in visual basic.means how to avoid entering numbers in textbox where we need only characters and also opposite means how to avoid characters where we only need numeric

plz reply me soon..
thanks in advance .
i m waiting 4 ur reply
Expand|Select|Wrap|Line Numbers
  1. Public Function NumberOnly(KeyAscii As Integer, TxtInput As String) As Integer
  2.     Dim loopx As Integer
  3.     If KeyAscii = 8 Or (KeyAscii >= 48 And KeyAscii <= 57) Then
  4.         NumberOnly = KeyAscii
  5.         Exit Function
  6.     End If
  7.     If KeyAscii = 46 Then
  8.         For loopx = 1 To Len(TxtInput)
  9.             If Asc(Mid(TxtInput, loopx, 1)) = 46 Then
  10.                 NumberOnly = 0
  11.                 Exit Function
  12.             End If
  13.         Next
  14.         NumberOnly = KeyAscii
  15.         Exit Function
  16.     End If
  17.     NumberOnly = 0
  18. End Function
  19.  

the above method will return keysscii value
1. if txtString is contain only number
2. if txtString is contain only one '.'(Dot-Decimal place)


(Killer indicate you to try some thing but you never).
Aug 2 '07 #5
hariharanmca
1,977 1GB
Expand|Select|Wrap|Line Numbers
  1. Public Function NumberOnly(KeyAscii As Integer, TxtInput As String) As Integer
  2.     Dim loopx As Integer
  3.     If KeyAscii = 8 Or (KeyAscii >= 48 And KeyAscii <= 57) Then
  4.         NumberOnly = KeyAscii
  5.         Exit Function
  6.     End If
  7.     If KeyAscii = 46 Then
  8.         For loopx = 1 To Len(TxtInput)
  9.             If Asc(Mid(TxtInput, loopx, 1)) = 46 Then
  10.                 NumberOnly = 0
  11.                 Exit Function
  12.             End If
  13.         Next
  14.         NumberOnly = KeyAscii
  15.         Exit Function
  16.     End If
  17.     NumberOnly = 0
  18. End Function
  19.  

the above method will return keysscii value
1. if txtString is contain only number
2. if txtString is contain only one '.'(Dot-Decimal place)


(Killer indicate you to try some thing but you never).
for this
Expand|Select|Wrap|Line Numbers
  1. If Asc(Mid(TxtInput, loopx, 1)) = 46 Then
you can also use
Expand|Select|Wrap|Line Numbers
  1. If InStr(1, Trim(TxtInput), ".") > 0 Then
without any for loop
Aug 2 '07 #6

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

Similar topics

0
by: Matthias Lohrer | last post by:
Hi, I'm playing around with the possibilities of Page.ParseControl. Thanks to Kirk Allen Evans I got my example running (Posting Juli, 17, "Re: Generating ASP.NET-Controls with XSLT...
2
by: Joey P | last post by:
Hi all, I am doing a project for university whereby i have to implement a simple database related to a frozen foods company. I am having some trouble though creating a validation rule for one...
3
by: Rob Meade | last post by:
Hi all, I have a login page which has username and password fields, a login button, and 2 validation controls (one for each field) - currently I have controls to display to the summary if the...
4
by: Scott M. | last post by:
If I put RequiredFiledValidators on a page and set them up with corresponding TextBoxes everything works just fine. If I add a DropDownList and set its AutoPostBack to True, I am able to post data...
3
by: Arun K | last post by:
Hi, I am creating a simple .aspx page to add some fields with validation. I have used different .NET validations like REquiredFieldValidator, RegularExpressionValidator and showed the summary...
4
by: matt | last post by:
Hi, I'm writing a visual basic application which searches a database of e-mail messages, based on certain criteria. I'm using dynamic SQL and an exec sp_executesql statement on the dynamic sql...
27
by: code_wrong | last post by:
Visual Basic (not dot net) what is the best way to check the User has entered an integer into an InputBox? isNumeric() checks for a numeric value .. but does not notify of numbers with decimal...
1
by: Sankalp | last post by:
Hi I am writing a large program where I am using three text boxes. I am performing validation controls on these text boxes however there are some conditions Names of textboxes 1. x 2. y 3. z...
4
by: Chris | last post by:
Hi, i want to validate a textbox like this: <asp:TextBox ID="vrg" runat="server" Width="495px" TextMode=MultiLine/> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.