 1. ## [RESOLVED] division

i have one textbox and one label i want to see the result
if the number on the textbox is over 150 to be divided by 5.5
if it is lower to be divided by 4.5
thank you  Reply With Quote

2. ## Re: division

Code:
```If Convert.ToInteger(Textbox1.Text) > 150 then
Label1.Text = (Convert.ToInteger(Textbox1.Text)/5.5).ToString
Else
Label1.Text = (Convert.ToInteger(Textbox1.Text)/4.5).ToString
End If```  Reply With Quote

3. ## Re: division Originally Posted by The Fire Snake Code:
```If Convert.ToInteger(Textbox1.Text) > 150 then
Label1.Text = (Convert.ToInteger(Textbox1.Text)/5.5).ToString
Else
Label1.Text = (Convert.ToInteger(Textbox1.Text)/4.5).ToString
End If```
Unless I'm missing something there is no Convert.ToInteger function, just Convert.ToInt16, ToInt32 etc, and it will cause an exception if the textbox can't be converted to an integer.... I'd do

Code:
```Dim nValue as Integer
If Integer.TryParse(Textbox1.Text, nValue) Then
If nValue  > 150 then
Label1.Text = (nValue/5.5).ToString
Else
Label1.Text = (nValue/4.5).ToString
End If
End If```  Reply With Quote

4. ## Re: division

thank you both of you
memas  Reply With Quote

5. ## Re: division Originally Posted by keystone_paul Unless I'm missing something there is no Convert.ToInteger function, just Convert.ToInt16, ToInt32 etc, and it will cause an exception if the textbox can't be converted to an integer.... I'd do

Code:
```Dim nValue as Integer
If Integer.TryParse(Textbox1.Text, nValue) Then
If nValue  > 150 then
Label1.Text = (nValue/5.5).ToString
Else
Label1.Text = (nValue/4.5).ToString
End If
End If```
Duh, I had Convert.ToInt32 and typed the wrong thing. Sorry typo on my part. And yes paul did a good thing by checking the textbox with TryParse. I was going to do something like that and became lazy Good and robust.  Reply With Quote

6. ## Re: division

if i want to say that if the number is between 140 and 150 how i have to fix the code?  Reply With Quote

7. ## Re: division

You would change the If statement:
Code:
` If 140 < nValue < 150 Then`  Reply With Quote

8. ## Re: division

i have error
Error 1 Option Strict On disallows implicit conversions from 'Boolean' to 'Integer'.  Reply With Quote

9. ## Re: division

Aw crap, I misdid the If Statement..sorry.

Code:
`If 140 < nValue AndAlso nValue < 150 Then`  Reply With Quote

10. ## Re: division

thank you formlesstree4 it is ok  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Featured