|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
What is wrong with this code??
I made this program that will make sure that only number are put into the txt box. If a letter is put inside of it the program should stop and display me a message. I am using Visual Studio.Net 2003. Here is the code if anyone sees something wrong with it can you let me know? The part in red is what I feel is what is making it go wrong. Right now if you run the application it will add the numbers fine but if you put in a "L" it does not do anything..like display the error message. It has a text box = Purchases and 1 label = tax and 1 label = total. It should do 5.00X.06 that amount should be in the lbltax and then that total should be in the lbltotal. If anyone needs further explanation just ask
Thanks PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncalc.Click Dim strpurchase, strpur, strchar AsStringDim intlength, intcount AsIntegerDim blnnonnumberfound AsBooleanDim decpur, decsales, dectotal AsDecimal strpurchase = txtpur.Text intlength = strpurchase.Length blnnonnumberfound = False If strpurchase = "" Then MessageBox.Show("Enter an amount as shown above", "5.00") Else DoUntil intcount = intlength OrElseNot blnnonnumberfound strchar = strpurchase.Substring(intcount, 1) If strchar <> "0" Or "1" Or "2" Or "3" Or "4" Or "5" Or "6" Or "7" Or "8" Or "9" Then blnnonnumberfound = True Else intcount = intcount + 1 EndIf Loop If blnnonnumberfound = TrueThen MessageBox.Show("Invalid purchase amount") Else decpur = Val(strpurchase) decsales = decpur * 0.06 dectotal = decsales + decpur lbltax.Text = decsales lbltotal.Text = dectotal EndIf EndIf EndSub EndClass |
|
#2
|
|||
|
|||
|
Do you like to use another method...?
Use CASE in Keypress event .....!
In text box keypress event call keyascii = OnlyNumbers (keyascii) Fucntion : Public Function OnlyNumbers(KeyAscii As Integer) As Integer If (KeyAscii >= 48 And KeyAscii <= 57) Or KeyAscii = 8 Then FintOnlyNumbers = KeyAscii Else FintOnlyNumbers = 0 End If End Function Try this its EASY....! Where ever you want to validate pass the KEYASCII |
|
#3
|
|||
|
|||
|
Ooops.. u said that VB.NET....
in the text box keypress pass the keyascci like this onlynumbers (Asc(e.KeyChar) ' passes the asciivalue |
|
#4
|
|||
|
|||
|
That code would work but I was really trying to keep it like the way i coded it. I am in a call and I can not add things that we have never learned before. I just didn't know if anyone saw this and thought of an explanation on why it may not be working completely for me. Thanks for the contrib though
|
|
#5
|
||||
|
||||
|
.NET related questions should be posted in the .NET area.
|
|
#6
|
|||
|
|||
|
ok
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > What is wrong with this code?? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|