dcsimg
Results 1 to 10 of 10

Thread: [RESOLVED] division

  1. #1

    Thread Starter
    Fanatic Member memas's Avatar
    Join Date
    Jan 2010
    Location
    athens,greece
    Posts
    531

    Resolved [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

  2. #2
    Hyperactive Member The Fire Snake's Avatar
    Join Date
    Sep 2009
    Location
    USA
    Posts
    401

    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

  3. #3
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: division

    Quote Originally Posted by The Fire Snake View Post
    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

  4. #4

    Thread Starter
    Fanatic Member memas's Avatar
    Join Date
    Jan 2010
    Location
    athens,greece
    Posts
    531

    Re: division

    thank you both of you
    memas

  5. #5
    Hyperactive Member The Fire Snake's Avatar
    Join Date
    Sep 2009
    Location
    USA
    Posts
    401

    Re: division

    Quote Originally Posted by keystone_paul View Post
    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.

  6. #6

    Thread Starter
    Fanatic Member memas's Avatar
    Join Date
    Jan 2010
    Location
    athens,greece
    Posts
    531

    Re: division

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

  7. #7

    Re: division

    You would change the If statement:
    Code:
     If 140 < nValue < 150 Then

  8. #8

    Thread Starter
    Fanatic Member memas's Avatar
    Join Date
    Jan 2010
    Location
    athens,greece
    Posts
    531

    Re: division

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

  9. #9

    Re: division

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

    Code:
    If 140 < nValue AndAlso nValue < 150 Then

  10. #10

    Thread Starter
    Fanatic Member memas's Avatar
    Join Date
    Jan 2010
    Location
    athens,greece
    Posts
    531

    Re: division

    thank you formlesstree4 it is ok

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


Click Here to Expand Forum to Full Width