Link to home
Start Free TrialLog in
Avatar of suicehockey44
suicehockey44

asked on

TextBox as Percentage

Hi.  I basically want a text box entry to be a percentage. So, if the user enters 100 its 100 percent of a value. 50 would be 50 percent (.50) and so on.  In the database its simply a decimal.  How would I go about doing this?

Thanks!!!
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

You can do something like this
 

        Dim value As Integer = 50
        Debug.WriteLine(FormatPercent(value / 100))

Open in new window

Avatar of spacerat60
spacerat60

I Think you are asking a Type casting question

also you might want to sanitize the input to make sure it is within range of percentages (less than 1 and greater than 0)
Function getValue(TextBox tb)
    Dim percent As Double
    
    'Cast String to double
    percent = CDBL(tb.value)
    IF( (percent/100) <= 1 and (percent/100) >= 0 )
        getValue = percent
    ELSE
       'invalid percentage value
    ENDIF
ENDF

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial