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

TextBox Error

Hello,
I've define a TextBox As Byte. Only numeric can be the input. I have made a
ErrorCheck().
The problem next:

If Val(Form1.txtText1.Text) "This is the problem" is not a byte Then
etc.

What do i have to fill in by: This is the problem is not a byte

I have try <> Byte, but this doesn't work.
I can the input define As String or something but I want only numeric that
can input.

Can someone help me, Thanks

Jul 17 '05 #1
4 5071
Try this for allowing only numeric input into a text box:

Private Sub Text1_KeyPress(KeyAscii As Integer)
Const iNumber = "1234567890"
If InStr(iNumber, Chr(KeyAscii)) <> 0 Then
Exit Sub
Else
KeyAscii = 0
End If
End Sub

The Keypress method of the textbox is called when you type in anything.
Setting the value of KeyAscii to 0 kills the enter.
"hennie" <ja******@hetnet.nl> wrote in message
news:cs**********@reader08.wxs.nl...
Hello,
I've define a TextBox As Byte. Only numeric can be the input. I have made a ErrorCheck().
The problem next:

If Val(Form1.txtText1.Text) "This is the problem" is not a byte Then
etc.

What do i have to fill in by: This is the problem is not a byte

I have try <> Byte, but this doesn't work.
I can the input define As String or something but I want only numeric that
can input.

Can someone help me, Thanks

Jul 17 '05 #2
This will allow you to useboth positive and negative numbers and decimal
points.

Private Sub Text1_Change()
If Not ValidateNumeric(Text1.Text) Then
Text1.Text = ""
End If
End Sub

Private Function ValidateNumeric(strText As String) _
As Boolean
ValidateNumeric = CBool(strText = "" _
Or strText = "-" _
Or strText = "-." _
Or strText = "." _
Or IsNumeric(strText))
End Function

Hope this helps.
"hennie" <ja******@hetnet.nl> wrote in message
news:cs**********@reader08.wxs.nl...
Hello,
I've define a TextBox As Byte. Only numeric can be the input. I have made
a
ErrorCheck().
The problem next:

If Val(Form1.txtText1.Text) "This is the problem" is not a byte Then
etc.

What do i have to fill in by: This is the problem is not a byte

I have try <> Byte, but this doesn't work.
I can the input define As String or something but I want only numeric that
can input.

Can someone help me, Thanks

Jul 17 '05 #3
http://vbnet.mvps.org/code/textapi/txstyles.htm

--
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
"hennie" <ja******@hetnet.nl> wrote in message
news:cs**********@reader08.wxs.nl...
: Hello,
: I've define a TextBox As Byte. Only numeric can be the input. I have made
a
: ErrorCheck().
: The problem next:
:
: If Val(Form1.txtText1.Text) "This is the problem" is not a byte Then
: etc.
:
: What do i have to fill in by: This is the problem is not a byte
:
: I have try <> Byte, but this doesn't work.
: I can the input define As String or something but I want only numeric that
: can input.
:
: Can someone help me, Thanks
:
:
:

Jul 17 '05 #4
> http://vbnet.mvps.org/code/textapi/txstyles.htm

Of course, the API function you cite for restricting input to
digits-only suffers from the flaw that allows a user to Paste non-digits
into the TextBox. For those reading this thread, here is a non-API
solution that protects against Pasting too. Paste the following code
into the code window for the form housing the TextBox (assumed to be
named Text1 for this example).

Rick - MVP

Dim LastPosition As Long

Private Sub Text1_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With Text1
If .Text Like "*[!0-9]*" Then
Beep
SecondTime = True
.Text = LastText
.SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
End Sub

Private Sub Text1_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
With Text1
LastPosition = .SelStart
'Place any other MouseDown event code here
End With
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
With Text1
LastPosition = .SelStart
'Place any other KeyPress checking code here
End With
End Sub

Jul 17 '05 #5

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

Similar topics

3
by: Lisa Calla | last post by:
Hi, I'm trying to control the foreground and background colors of a textbox. I hate that light gray foreground when the textbox.enabled=false. I've tried to derive a control from the textbox,...
2
by: donnet | last post by:
Inside my .aspx file, I have a textbox populated with data from a dataset like this: <asp:TextBox text='<%# DataBinder.Eval(Container.DataItem, "Comment")%>' id="CommentText" runat="server"...
7
by: I am Sam | last post by:
I have a DataGrid that is passing information to a stored procedure properly but the parameters aren't being casted properly. I was woundering if anyone can tell me how I should properly cast the...
1
by: jason | last post by:
I've seen a few posts on this issue, but no clear solutions. I have a mulitiline textbox inside a datagrid. I use TemplateColumn to define as multiline with 3 rows. I have other field types...
7
by: david | last post by:
I try to use "for" loop to assign textbox control ID to a textbox variable in server side codebehind for a web form. But I met some problem. What I want to do is solving the following-like code by...
1
by: OceanBreeze | last post by:
I am using ASP 2.0 and C# I have a TextBox control in .aspx file. <asp:TextBox ID="CityTxt" runat="server"></asp:TextBox> When I click on that text box, I want to trigger onClick event. ...
0
by: mutlyp | last post by:
I have a PreRender event to set the width of my textbox when the Edit button is pressed on my grid here is the code: Private Sub grdPBC_PreRender(ByVal sender As Object, ByVal e As...
0
by: sjickells | last post by:
Hi I am having a problem using asp:TextBox's in a transparent table. I have a background image on the page and a table in the middle of the page. I have set the background colour of the table...
5
by: Nick | last post by:
Hey there, I'm trying to get a textbox (using ASP.NET / VB.NET) to display XML without freaking out the browser afterwards. Currently I have the textbox displaying the XML fine, but that's...
4
by: HenrikL | last post by:
Hi. I have a textbox that have a binding on it with converter and validationrules. When a validation error ouccur the foreground of the textbox will change to red cause it has a style.triggers...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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 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.