Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

  • *Experts*
Posted

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)
'etc

You might also want to add in a Try...Catch error handling

block just in case someone enters a non-number.

  • *Gurus*
Posted (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 by divil

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*
Posted

I believe divil means Option Strict, which prevents direct conversion

from one data type to another where the possibility of data-loss

exists.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...