SunQuest
 
           Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
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  
Old October 22nd, 2004, 05:52 AM
02evad 02evad is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 9 02evad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

End
Class




Reply With Quote
  #2  
Old October 22nd, 2004, 06:51 AM
Arjun Arjun is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 43 Arjun User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 18 sec
Reputation Power: 4
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

Reply With Quote
  #3  
Old October 22nd, 2004, 07:02 AM
Arjun Arjun is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 43 Arjun User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 18 sec
Reputation Power: 4
Ooops.. u said that VB.NET....
in the text box keypress pass the keyascci like this


onlynumbers (Asc(e.KeyChar) ' passes the asciivalue

Reply With Quote
  #4  
Old October 22nd, 2004, 03:06 PM
02evad 02evad is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 9 02evad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #5  
Old October 22nd, 2004, 03:33 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,737 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 1 h 19 m 52 sec
Reputation Power: 443
.NET related questions should be posted in the .NET area.

Reply With Quote
  #6  
Old October 22nd, 2004, 03:48 PM
02evad 02evad is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 9 02evad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ok

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > What is wrong with this code??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway