vellaima Posted February 18, 2003 Posted February 18, 2003 Dim ij as Integer ij = discount.Text If ij > 100 Then MsgBox("Cannot be greater than 100") discount.Text = "" discount.Focus() End If In the above code if ij is 100.01 i am not getting the error message. If ij is 100.60 and above i am getting the error message. Is there any other way out? Quote
*Experts* Volte Posted February 18, 2003 *Experts* Posted February 18, 2003 You need to use the Single or Double datatypes; Integer doesn't like decimals, so 100.60 rounds to 101, 100.01 rounds to 100. Dim ij As Single ij = Single.Parse(discount.Text) 'etcYou might also want to add in a Try...Catch error handling block just in case someone enters a non-number. Quote
*Gurus* divil Posted February 18, 2003 *Gurus* Posted February 18, 2003 (edited) Also, go in to your project properties and turn on Option Strict. You are assigning a string directly to an integer, which is horrible. You should use Integer.Parse or the equivalent instead. [edit]Yeah, that's what I meant[/edit] Edited February 18, 2003 by divil Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Experts* Volte Posted February 18, 2003 *Experts* Posted February 18, 2003 I believe divil means Option Strict, which prevents direct conversion from one data type to another where the possibility of data-loss exists. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.